走路应该留下脚印

人生的代码我来书写

2011年5月13日 #

转.iPhone开发网站、论坛、博客

http://cocoachina.com/ 大量iPhone开发资料,教学,经验,还有自曝。 

http://www.javaeye.com/forums/board/mobile iPhone开发论坛,人气鼎盛,大量自曝,还有Android的讨论 

http://developer.apple.com/iphone/ 苹果iPhone开发官方主页,提供大量实例、文档和教学视频 

http://developer.apple.com/contact/phone.html 苹果的支持 

http://www.stanford.edu/class/cs193p/ 斯坦福大学的iPhone课程

http://bit.ly/RuaKq 飞机游戏iFighter的作者dr_watson写的iPhone游戏开发经典教学系列,有源码 

http://www.iphoneside.com/ iPhone达人的博客,很多有价值的资源下载,新闻和教程 

http://lichen1985.com/blog/ iPhone应用的作者,雨雪霏霏的iPhone博客,很多开发手记和心得 

http://blog.liuhongwei.cn/category/iphone/ iPhone开发博客,提供教学文章,经验分享,还有GAE 

http://www.javaeye.com/topic/422948 iPhone日本市场高手的自曝贴,第1个月就赚了2千刀,大量详细的数字和图片 

http://dev.iphonetw.net/ 台湾iPhone开发者论坛,有些教学文章和讨论 

http://www.otierney.net/objective-c.html.zh-tw.big5 Object-c简单教程 

http://icodeblog.com/ game的教程 

http://www.iphoneside.com/2009/06/abc123%EF%BC%9A%E4%B8%80%E4%B8%AA%E5%BC%80%E6%BA%90%E7%9A%84cocos2d%E6%B8%B8%E6%88%8F/ 游戏 

http://adeem.me/blog 简单教程 

http://www.iphoneexamples.com/ iPhone SDK Examples 

http://cocoadevcentral.com/d/learn_objectivec/ learn objective c 

补充: 
www.weiphone.com 

http://stackoverflow.com/ 

from:http://www.javaeye.com/topic/453221?page=1 

http://howtomakeiphoneapps.com 

http://icocoa.cn/ocsection/ocpractice Objective C 2.0 简明教程 

http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:index cocos2d教程 

http://www.premiumbeat.com/  Sound and Music resources 

http://c.gzl.name/  “我”的开发笔记 

http://www.cnblogs.com/HelloCG/category/172682.html //游戏开发中的数学和物理算法 

http://www.cocoachina.com/blog/blog.php?uid=11 //cocoachina dr_watson 

http://www.khronos.org/opengles/sdk/1.1/docs/man/ //OpenGL ES 1.1 Ref Page 

http://www.khronos.org/opengles/sdk/docs/man/  //OpenGL ES 2 Ref Page 

http://www.lihuasoft.net/article/list.php?frmid=97&page=1 //游戏算法 

http://three20.info/ three20控件 
http://joehewitt.com/post/the-three20-project/

http://www.edumobile.org/iphone/     iphone教程

http://www.ourtuts.com/                    美术教程

http://www.appsamuck.com/        31个small project

posted @ 2011-05-13 14:14 wingfay 阅读(31) 评论(0) 编辑

2011年3月31日 #

NSLog的使用

NSLog的定义

NSLog定义在NSObjCRuntime.h中,如下所示:

void NSLog(NSString *format, …);

基本上,NSLog很像printf,同样会在console中输出显示结果。不同的是,传递进去的格式化字符是NSString的对象,而不是chat *这种字符串指针。

示例

NSLog可以如下面的方法使用:

NSLog (@"this is a test");

NSLog (@"string is :%@", string);

NSLog (@"x=%d, y=%d", 10, 20);

但是下面的写法是不行的:

int i = 12345;

NSLog( @"%@", i );

原因是, %@需要显示对象,而int i明显不是一个对象,要想正确显示,要写成:

 

int i = 12345;

NSLog( @"%d", i );

格式

NSLog的格式如下所示:

 

  • %@     对象
  • %d, %i 整数
  • %u     无符整形
  • %f     浮点/双字
  • %x, %X 二进制整数
  • %o     八进制整数
  • %zu    size_t
  • %p     指针
  • %e     浮点/双字 (科学计算)
  • %g     浮点/双字 
  • %s     C 字符串
  • %.*s   Pascal字符串
  • %c     字符
  • %C     unichar
  • %lld   64位长整数(long long)
  • %llu   无符64位长整数
  • %Lf    64位双字

posted @ 2011-03-31 16:35 wingfay 阅读(46) 评论(0) 编辑

2010年6月12日 #

Could not load type System.Security.Authentication.....

如果WCF出现这个错误,请把 KB979909 & KB976769v2 两个补丁删除.

 

 

Could not load type 'System.Security.Authentication.ExtendedProtection.ExtendedProtectionPolicy' from assembly 'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.  

posted @ 2010-06-12 10:58 wingfay 阅读(83) 评论(0) 编辑

2009年8月13日 #

[原创]Prism Command 和 IsEnabled 的冲突解决方法

在开发Silverlight项目中,学习使用MVVM ,在Button的click上想使用Prism下的Click Command方法来处理Click事件,发现当用到Click事件绑定的时候,
绑定IsEnabled的属性不起作用了。
XAML代码如下
Code

C#代码如下
    public class MainPageViewModel : INotifyPropertyChanged  
    {
        
public MainPageViewModel()
        {
            BTNEnabledCommand 
= new DelegateCommand<object>(OnEnabledCommand);
            BTNClickCommand 
= new DelegateCommand<object>(OnClickCommand);
        }
        
private void OnEnabledCommand(object arg)
        {
            IsNewEnabled 
= !IsNewEnabled;                        
        }
        
private void OnClickCommand(object arg)
        {
            MessageBox.Show(
"Hello Wingfay");
        }
        
public ICommand BTNClickCommand { getprivate set; }
        
public ICommand BTNEnabledCommand { getprivate set; }
        
private bool _IsNewEnabled;
        
public bool IsNewEnabled
        {
            
get
            {
                
return _IsNewEnabled;
            }
            
set
            {
                _IsNewEnabled 
= value;
                OnPropertyChanged(
"IsNewEnabled");
            }
        }

       ....
    }
郁闷死我了,在网上找资料发现了这个
引用

The Click.Command attached property provided by Composite Application Guidance for WPF & Silverlight requires you to specify an ICommand (generally using DelegateCommand class). In that command you define an Execute and CanExecute method. The CAL relies on this latter method to check if the command can be executed and sets the control's IsEnabled property to the value returned by the CanExecute method.

So, when you use CAL's Click attached property to define commands, the IsEnabled property is set at runtime by the command behavior (more precisely in the UpdateEnabledState method of the CommandBehaviorBase class) which is executed after the isEnabled set in XAML.

 

      protected virtual void UpdateEnabledState()

      {

            ...

            if (this.Command != null)

            {

                TargetObject.IsEnabled = this.Command.CanExecute(this.CommandParameter);

            }
      }

 

You can use the RaiseCanExecuteChanged method from the DelegateCommand class to reevalute the CanExecute method and that will update the isEnabled property of all attached controls.

以上是Prism开发人员的回答
然后看了下Prism关于Command的源代码 终于明白了点
该后的代码如下
XAML
    <UserControl.Resources>
        
<Local:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
        
<Local:MainPageViewModel x:Key="MainPageViewModelDataSource" d:IsDataSource="True"/>
 
    
</UserControl.Resources>  
    
<Grid x:Name="LayoutRoot" DataContext="{Binding Source={StaticResource MainPageViewModelDataSource}}">
      
<Button Height="36" HorizontalAlignment="Left" Margin="128,126,0,0" VerticalAlignment="Top" Width="58" Content="New" 
         Visibility
="{Binding IsNewVisible, Converter={StaticResource BooleanToVisibilityConverter}, Mode=OneWay}"
           commands:Click.Command
="{Binding BTNClickCommand}"
            
/>
      
<Button Height="36" Margin="292,126,273,0" VerticalAlignment="Top" Content="Enabled" commands:Click.Command="{Binding BTNEnabledCommand}"/>


  
</Grid>

C#代码

Code
*转载请注明来自哪里就行。

posted @ 2009-08-13 00:44 wingfay 阅读(247) 评论(0) 编辑

2009年3月17日 #

[ZT]JScript下Array对象的性能问题



原发表于:hax的技术部落格

今天看了微软JScript官方blog上去年的两篇文章:
http://blogs.msdn.com/jscript/archive/2008/03/25/performance-optimization-of-arrays-part-i.aspx
http://blogs.msdn.com/jscript/archive/2008/04/08/performance-optimization-of-arrays-part-ii.aspx
讲的是IE8对Array性能的改进,其中也解释了过去JScript对Array的内部实现及导致的性能问题。

狗狗了一下,似乎没有中文文章介绍过,所以我就写一篇来稍作介绍——不过并非翻译——微软的人总不好意思自己骂自己——而我素来要痛打落水狗的。

首先,目前JScript中数组操作是很慢滴,有多慢呢?我们引用一下JScript团队第一篇blog的数据:

   提示:您可以先修改部分代码再运行

此段代码,IE7用了7秒,而IE8仅仅用时18毫秒。

如果你看了第一篇blog中所解释的原因,请注意

——其实它在忽悠你,真正的原因在第二篇里。


我这里有有个更加简单的测试代码:

   提示:您可以先修改部分代码再运行

你可以改变SIZE和count的值来观察。

基本上,pop()方法或者任何导致length减小的操作,都是非常耗费的——大体上与数组实际包含元素个数成正比。

这才是真正的性能杀手。


而且这一操作所要遍历的元素甚至包括非正整数索引(而只有索引为uint32才会被认为是数组元素):

   提示:您可以先修改部分代码再运行

可以发现结果也是基本与元素个数成正比。但是比前面要快一些。原因后面解释。


之所以有这样的结果,是因为length减小时,引擎不仅仅是改变了length的值,而且要删除所有索引大于等于新的length的元素。

本来这件事情可以这样做(我相信大多数程序员的第一感觉也就是这样做):

Code:

function get_length() { return this._length }
function 
set_length(len) {
  if (
len || len 0xffffffff) throw RangeError()
  if (
len this._length) {
    
this._length len; return
  }
  while (
len this._length) {
    
delete this[--this._length]
  }



如果确实这样做的话,性能绝不会如此糟糕(不信你可以写个自己的MyArray来试验一下——用JS写出来的居然比built-in的C实现还要快)。

但是,JScript团队的程序员,据说认为JS的Array其实是稀疏数组,或者说就是一个hash——理论上也确实如此,所以采用了大概是这样的算法(以JS来示意):

Code:

function get_length() { return this._length }
function 
set_length(len) {
  if (
len || len 0xffffffff) throw RangeError()
  if (
len this._length) {
    for (var 
k in this) {
      var 
toUint32(k)
      if (
>= lendelete(this[k])
    }
  }
  
this._length len



其中toUint32(s)将一个32位无符号整数的十进制字符串表达转为数字,如果转换失败则返回-1。【注意,此toUint32与parseInt不同,传入'0123'、'123.00'、'+123'、'1e4'等都会转换失败。】

这段代码遍历所有的key(因为Array本质上是把数字索引转换为字符串索引来保存的),如果这个key可以被转回无符号整数(也就是数字索引),则看看它是否大于指定的长度,大于的话就删掉。

好了,现在我们就不难理解为什么性能会与元素个数成正比了。假如一个50000个元素的数组,pop()了一下之后,居然也要遍历50000个元素!如果是在一个循环中不断pop()可想而知会有多慢。

那么为什么我们第二个例子会快一些呢?
这是因为我们的字符串索引是字母"i"开头的,而toUint32的实现,应该会一个字符一个字符的解析,当第一个字母是i时已然可知转换失败,直接返回了。以下是也以JS示意:

Code:

function toUint32(s) {

  if (
== '') return -1
  
if (s.charCodeAt(0) == 48 && s.length 1) return -1

  
var 0d
  
for (var 0s.lengthi++) {
    
*= 10
    d 
s.charCodeAt(i) - 48
    
if (|| 9) return -1
    n 
+= d
    
if (>= 0xffffffff) return -1
  
}
  return 
n



你也可以把前面第二段代码中的:
   arr['i' + i] = i;
换为
   arr[i + '00000000x'] = i

结果就会发现耗费时间更长了,因为toUint32必须解析到最后一个字符才知道转换失败。

【注:这里可以优化,因为uint32十进制最长是10个字符,所以可以先判断string的长度,超过10直接失败——问题是从测试结果来看,JScript实际的实现并没有做此优化】


那么JScript的开发者为什么要采用这样一个算法呢?

其实,如果从稀疏数组的角度看,这个算法是可行的,而且在某些条件下性能很好,比如对于以下:

var a = new Array(100000)
a.length = 10

在这次对length的改变中,上述算法飞快的完成,因为这个数组没并有什么实际元素可遍历!

所以JScript的开发者或许是特意做了这样的优化算法!!


然而讽刺的是,这本质上是一个极其愚蠢的优化!!


通常我们在用Array的时候,很少拿它当稀疏数组用!因为如果我们确实要用一个稀疏数组,我们完全可以直接用普通对象(即hash)。

就算我们经常使用稀疏数组——诚然,在一个稀疏数组时,前面所描述的最显白的算法,可能并不高效,但是稍加分析就可以看出,那样的算法要出现性能问题,只能是如下形式的代码:

Code:

for(var i=0;i<arrays.length;i++) {
  
arrays[i].length 0



其中每个arrays[i]都是稀疏数组。
这样的代码我是没有见过。

对于单个稀疏数组来说,要出现性能问题,除非你这样:

Code:

for(var i=0;i<count;i++) {
  array = new Array(
50000)
  ...
  array.
length 0



然而几乎没有人会写这样的代码
——而且 array.length=0 这句造成性能问题的语句根本是多余的。

归根到底,既然是一个稀疏数组,则通常不会进行遍历,更没有理由执行 array.length = 0 之类的语句,如果要抛弃一个数组,直接 array = null 即可。


相反,普通(非稀疏)的数组,就是用来遍历的。因此很容易写出这样的代码:

Code:

while (array.length 0) {
  var 
= array.pop()
  
// do sth for e



或者

Code:

while (array.length 0) {
  var 
= array[array.length 1]
  
// do sth for e
  
array.length--



所以我所能得出的结论是,JScript的Array.length的算法实现实在非常愚蠢。幼稚程度堪比我们诟病的白痴的垃圾回收策略

当然,比起垃圾到极点的垃圾回收算法给我们造成的麻烦,这个length的问题还是可以有workaround的,不必干等IE8那样复杂到狂出bug(见第一篇blog下面的comments)的设计。比如IE8 beta1的platform performance improvements白皮书里就提到,有人自己造轮子:

Code:

//user defined array type called 'prototypeArray' 
var prototypeArray = function() { 
  
this._array = []; 
  
this.length 0
  
this.start 0
  
this.end 0
}
//push method for user defined array type 'prototypeArray' prototypeArray.prototype.push = function() { 
  
var arguments.length
  for (var 
i=0;i<l;i++){ 
    
this.length++; 
    
this._array[this.end++] = arguments[i]; 
  } 

//pop method for user defined array type 'prototypeArray' prototypeArray.prototype.pop = function() { 
  
var obj null
  if (
this.length>0){ 
    
this.length--; 
    
obj this._array[--this.end]; 
    
delete this._array[this.end];
  } 
  return 
obj

//creating an object of user defined array type 'prototypeArray' var myArray = new prototypeArray(); 
//accessing push and pop methods of user defined array type 'prototypeArray' 
myArray.push("Test String"
myArray.pop(); 


一个用js代码自造的轮子,居然比c写的built-in函数跑的还要快,真是让人汗颜。

另外一个更简便的方式,就是记住这个简单的最佳实践:

少去改length!特别不要在循环中做pop()或length--之类的操作。如果要减,等到循环结束,一次性减到底就好了!

BTW,我们也要注意shift()、unshift()、splice()之类的操作,因为这些操作可能会改变大量数组元素的索引——按照稀疏数组的实现,显然会比单单改length更慢上许多!如果你真的需要shift()、unshift(),那还是自制一个类似上面的轮子吧(提示:上面代码的start属性就是为此准备的)。

posted @ 2009-03-17 13:33 wingfay 阅读(27) 评论(0) 编辑

2009年2月5日 #

获取地区的Resolve Weather Location ID

posted @ 2009-02-05 14:34 wingfay 阅读(361) 评论(0) 编辑

Using .NET C# LDAP Library(Novell.Directory.Ldap)

posted @ 2009-02-05 14:22 wingfay 阅读(607) 评论(0) 编辑

WINDOWS下搭建LDAP服务器

posted @ 2009-02-05 14:10 wingfay 阅读(2376) 评论(0) 编辑

[转帖]LDAP Schema的概念和基本要素

posted @ 2009-02-05 13:58 wingfay 阅读(480) 评论(0) 编辑

2008年11月27日 #

KEYPREVIEW 属性

posted @ 2008-11-27 12:11 wingfay 阅读(413) 评论(0) 编辑