Ruby on Rails: RubyGem version error: rack(1.0.0 not ~> 1.0.1) (RuntimeError)
by Elton on 2010年03月7日, under Rails
当你升级了rails后,有时候会出现rack版本跟rails版本不匹配的情况。 当你执行./script/generate命令的时候,会出现以下错误信息:
-
-
/Library/Ruby/Gems/1.8/gems/rails-2.3.5/lib/initializer.rb:271:in `require_frameworks‘: RubyGem version error: rack(1.0.0 not ~> 1.0.1) (RuntimeError)
-
from /Library/Ruby/Gems/1.8/gems/rails-2.3.5/lib/initializer.rb:134:in `process’
-
from /Library/Ruby/Gems/1.8/gems/rails-2.3.5/lib/initializer.rb:113:in `send‘
-
from /Library/Ruby/Gems/1.8/gems/rails-2.3.5/lib/initializer.rb:113:in `run’
-
from /Volumes/Data/study/ruby/blog/config/environment.rb:9
-
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require‘
-
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require’
-
from /Library/Ruby/Gems/1.8/gems/rails-2.3.5/lib/commands/generate.rb:1
-
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require‘
-
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require’
-
from ./script/generate:3
-
解决方案:
-
-
$ sudo gem uninstall rack
-
-
Select gem to uninstall:
-
1. rack-1.0.0
-
2. rack-1.1.0
-
3. All versions
-
> 1
-
-
You have requested to uninstall the gem:
-
rack-1.0.0
-
actionpack-2.3.5 depends on [rack (~> 1.0.0)]
-
actionpack-2.3.4 depends on [rack (~> 1.0.0)]
-
If you remove this gems, one or more dependencies will not be met.
-
Continue with Uninstall? [Yn] y
-
Successfully uninstalled rack-1.0.0
-
然后再执行
-
-
sudo gem install -v=2.3.5 rails
-
-
Successfully installed rack-1.0.1
-
1 gem installed
-
Installing ri documentation for rack-1.0.1…
-
Installing RDoc documentation for rack-1.0.1…
-
问题解决
如何使用Objective-C解析HTML和XML
by Elton on 2010年02月25日, under Mac
使用Objective-C解析HTML或者XML,系统自带有两种方式一个是通过libxml,一个是通过NSXMLParser。不过这两种方式都需要自己写很多编码来处理抓取下来的内容,而且不是很直观。
有一个比较好的类库hpple,它是一个轻量级的包装框架,可以很好的解决这个问题。它是用XPath来定位和解析HTML或者XML。
安装步骤:
-加入 libxml2 到你的项目中
Menu Project->Edit Project Settings
搜索 “Header Search Paths”
添加新的 search path “${SDKROOT}/usr/include/libxml2″
Enable recursive option
-加入 libxml2 library 到你的项目
Menu Project->Edit Project Settings
搜索 “Other Linker Flags”
添加新的 search flag “-lxml2″
-将下面hpple的源代码加入到你的项目中:
HTFpple.h
HTFpple.m
HTFppleElement.h
HTFppleElement.m
XPathQuery.h
XPathQuery.m
-XPath学习地址http://www.w3schools.com/XPath/default.asp
示例代码:
-
-
#import "TFHpple.h"
-
-
-
// Create parser
-
xpathParser = [[TFHpple alloc] initWithHTMLData:data];
-
-
//Get all the cells of the 2nd row of the 3rd table
-
-
// Access the first cell
-
TFHppleElement *element = [elements objectAtIndex:0];
-
-
// Get the text within the cell tag
-
-
[xpathParser release];
-
[data release];
-
另外,还有一个类似的解决方案可以参考
ElementParser http://github.com/Objective3/ElementParser
如何在iPhone图标上加提示符(badge)
by Elton on 2010年02月21日, under iPhone
如果你使用Apple iPhone自带的Mail程序,你会注意到,当有新邮件的时候,在这个程序的图标(icon)上会显示对应的新邮件的数字。 如果你的应用程序也想有类似的功能,其实很简单:
-
-
- (void)applicationDidFinishLaunching:(UIApplication *)application {
-
//…
-
[application setApplicationIconBadgeNumber:123];
-
}
-
将Array、Dictionary等集合类的序列化和反序列化
by Elton on 2010年02月15日, under iPhone
Objective-C的集合类序列化到文件中或者从文件中反序列化其实很简单,请看下面的示例代码:
-
-
@"Hefeweizen", @"IPA", @"Pilsner", @"Stout", nil];
-
-
array, @"array", @"Stout", @"dark", @"Hefeweizen", @"wheat", @"IPA",
-
@"hoppy", nil];
-
-
// 得到documents directory的路径
-
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
-
NSUserDomainMask, YES);
-
if ([paths count] > 0)
-
{
-
// Array的保存路径
-
stringByAppendingPathComponent:@"array.out"];
-
-
// dictionary的保存路径
-
stringByAppendingPathComponent:@"dict.out"];
-
-
// 保存array
-
[array writeToFile:arrayPath atomically:YES];
-
-
// 保存dictionary
-
[dictionary writeToFile:dictPath atomically:YES];
-
-
// 从文件中读取回来
-
-
NSLog(@"Beer: %@", element);
-
-
NSLog(@"%@ Style: %@", key, [dictionary valueForKey:key]);
-
}
-
输出如下:

创建没有按钮的UIAlertView
by Elton on 2010年02月11日, under iPhone
默认的,UIAlertView都有一个或者多个按钮,如果你想创建没有按钮的UIAlertView,可以使用以下的方法:
-
-
UIAlertView *alert;
-
-
…
-
-
alert = [[[UIAlertView alloc] initWithTitle:@"Configuring Preferences\nPlease Wait…"
-
message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil] autorelease];
-
-
[alert show];
-

上面的标题可能有些靠上,可以用过给标题增加回车的方式,使标题居中:
-
-
UIAlertView *alert;
-
-
…
-
-
alert = [[[UIAlertView alloc] initWithTitle:@"\n\nConfiguring Preferences\nPlease Wait…"
-
message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil] autorelease];
-
-
[alert show];
-

如果你还想给UIAlertView添加一个等待提示符,则可以这么做:
-
-
UIAlertView *alert;
-
-
…
-
-
alert = [[[UIAlertView alloc] initWithTitle:@"Configuring Preferences\nPlease Wait…" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil] autorelease];
-
[alert show];
-
-
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
-
-
// Adjust the indicator so it is up a few pixels from the bottom of the alert
-
indicator.center = CGPointMake(alert.bounds.size.width / 2, alert.bounds.size.height – 50);
-
[indicator startAnimating];
-
[alert addSubview:indicator];
-
[indicator release];
-

解除UIAlertView的显示
因为这个AlertView没有按钮,所以就不能通过点击按钮将这个提示框去掉。可以通过程序的方式,将这个窗口关掉。
[alert dismissWithClickedButtonIndex:0 animated:YES];
Three20中给TTPhotoViewController添加播放按钮
by Elton on 2010年02月6日, under iPhone
Three20是一个很不错的iPhone类库,是facebook共享出来的框架。利用TTThumbsViewController可以很容易的制作出类似flickr的应用,实现缩略图和图片查看功能。
但是默认的TTThumbsViewController,点击一个图片的时候,下面的button只有上一个和下一个,并没有播放按钮。 之前以为Three20没有相应的播放功能。但是经过查看代码,发现在TTPhotoViewController中,其实有相关的方法,只是没有把播放按钮显示出来而已。
-
-
UIBarButtonItem* playButton = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:
-
UIBarButtonSystemItemPlay target:self action:@selector(playAction)] autorelease];
-
playButton.tag = 1;
-
通过修改TTPhotoViewController大致在400行左右,添加playButton这个变量
-
-
_toolbar.items = [NSArray arrayWithObjects:
-
space, _previousButton, space, playButton, space, _nextButton, space, nil];
-
这样重新编译后,就可以看到播放按钮了。
Three20这个库其实还是很实用的,只是文档比较欠缺,没办法,只能直接看源码了。
给TableView加背景
by Elton on 2010年02月2日, under iPhone
iPhone默认的表格背景很单调,你可以通过加背景图片的方式来给你的应用增添点亮点。可以通过以下方法来给表格添加背景。
你可以在你的delegate类里面添加如下代码:
-
-
UIView *backgroundView = [[UIView alloc] initWithFrame: window.frame];
-
backgroundView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"TableViewBackground.png"]];
-
[window addSubview:backgroundView];
-
[backgroundView release];
-
-
yourTableViewController = [[ATableViewController alloc] initWithStyle:UITableViewStyleGrouped];
-
yourTableViewController.view.backgroundColor = [UIColor clearColor];
-
[window addSubview:yourTableViewController.view];
-
-
[window makeKeyAndVisible];
-
ATableViewController是UITableViewController的一个子类

如何使用MyFace快速构建基于JSF的应用
by Elton on 2010年02月2日, under Java
如果大家使用Apache MyFace的JSF实现来搭建JSF应用,可以利用Apache提供的便捷maven方法来快速搭建一个初始的应用。
-
-
mvn archetype:generate -DarchetypeCatalog=http://myfaces.apache.org
-
……
-
Choose archetype:
-
1: http://myfaces.apache.org -> myfaces-archetype-helloworld (Simple Web application using Apache Myfaces)
-
2: http://myfaces.apache.org -> myfaces-archetype-helloworld-facelets (Simple Web application using Apache Myfaces and Facelets)
-
3: http://myfaces.apache.org -> myfaces-archetype-helloworld-portlets (Simple Web application using Apache Myfaces and Portlets)
-
4: http://myfaces.apache.org -> myfaces-archetype-jsfcomponents (Simple JSF Component using Apache Myfaces)
-
5: http://myfaces.apache.org -> myfaces-archetype-trinidad (Simple Web application using Apache Myfaces and Trinidad)
-
Choose a number: (1/2/3/4/5):
-
……
-
可以看到它提供了你5个初始项目进行选择,你可以根据你的需要选择响应的选项。之后填写响应的参数后,你的应用程序框架就生成了。
然后再使用以下命令,来下载必要的依赖包,假设你的groupId=myAppId,artifactId=yourapp
-
-
cd yourapp
-
mvn package
-
之后你就搭建了一个初始框架,你可以继续使用maven来操作这个框架。
千万别study English,应学会learn Englis——英语学习方法强烈推荐
by Elton on 2010年01月29日, under 未分类
l 开始第一阶段:“打通”耳朵,完全听清
要领:
第一, 选择1盘(再次强调是1盘而非一套)适合自身英语水平的磁带;(磁带我选用的是李阳的疯狂英语,电驴有很多资源的,也可用新东方的或者BBC)
第二, 每天集中精力把A面和B面连续听两遍
第三, 要坚持天天听,但每隔6天要休息一天
第四, 直到听清磁带中的所有内容
2 完成第二阶段:听读并举,掌握语法
要领:
第一, 把已经能完全听清的磁带中的第1盘磁带再找出来。
第二, 听写这盘磁带的内容。
第三, 做听写练习时,一句一句地听。即:听完一句后,先按暂停,把刚才听到的写下来,反复听,直到完全听清这句为止。不会的单词根据发音大致拼写出来即可。
第四, 听写完整盘磁带的所有内容后,用英英词典确认不会的单词拼写是否正确(知道其意当然好,不知道也不要紧)。
第五, 按这种方法听写完整盘磁带的内容后,尽量模仿磁带的发音和语调,从头到尾大声朗读(不满意的部分要再听一遍磁带重新朗读)
第六, 感觉到所有的句子都已经能朗朗上口以后,便结束这一阶段。
第七, 整个过程中,每个星期要有1天与英语完全隔绝。
3 突破第三阶段:跃跃欲说,出口成章
要领:
第一, 用英英词典查以前做听写练习不懂的单词。(英英词典,我使用的是《朗文当代英语辞典(第4版)(精装)》,因原来听新东方的视频,新东方老师推荐使用朗文的英英字典)
第二, 把单词的解释和例句记下来,若这其中还有不懂的单词话,继续查单词。
第三, 查词典要坚持查到没有不懂的单词为止。
第四, 大约查1个小时后,暂停查词典,并大声朗读通过查词典整理出的内容。
第五, 朗读约1个小时后结束。
第六, 每周要隔1天。
第七, 查在原文和单词解释中出现的所有不懂的单词、并一直朗读到完全吃透解释和例句为止。
4 征服第四阶段:自我领悟,无典自通
要领:
第一, 准备1盘录像带。(我打算使用MIT的《算法导论》视频)
第二, 带上耳机,每天看1遍。
第三, 能够完全听清之后,便开始听写,朗读。
第四, 将不清楚的单词,利用英英词典查找并朗读。
5 攀登第五阶段:文化融通,渐入佳境
要领:
第一, 准备1张最近的英文原版报纸(在美国发行的报纸)。
第二, 从社会版面挑选一篇短文章(1~2分钟就能念完的),然后大声朗读。必须坚持到完全消化为止,就好像自己成了新闻主持人一样。
第三, 当确信自己不看原文也可以记住文章内容时,把它像讲一个故事一样绘声绘色地复述。
第四, 能够流利地朗读,再选第二篇文章,重复上面所讲的方法。
第五, 看完一个版面后,就像第三阶段那样处理不认识的单词。
第六, 把报纸上广告、名人访谈、漫画等所有内容,都按上述方法加以学习。
下面是书上关于这个英语学习的阐述与分析:
1、分析第一阶段:打通耳朵,完全听清
2、分析第二阶段:听读并举,掌握语法
3、分析第三阶段:跃跃欲说,出口成章
4、分析第四阶段:自我领悟,无典自通
5、分析第五阶段:文化融通,渐入佳境
去掉iPhone应用图标上的弧形高光
by Elton on 2010年01月25日, under iPhone
有时候我们的应用程序不需要在图标上加上默认的高光,可以在你的应用的Info.plist中加入:
-
-
UIPrerenderedIcon,让它等于YES即可
-


