易栈网-膘叔

浏览模式: 标准 | 列表 | 图文
Yii 官方关于event和behaviors的文章

Yii 官方关于event和behaviors的文章

本文内容来自官方的wiki,一来是做备份,二来自己查询起来也会快一点,毕竟yiiframework官网经常抽风,当然它的抽风不是因为自己,而是因为GFW,说来也可怜,好象很多技术网站都被墙了。
不过想想也正常,如果一个搞技术的,连翻墙也不会,还搞个毛技术啊。
OK,上正菜:http://www.yiiframework.com/wiki/44/behaviors-events/#hh1

These features provide endless possibilities and unbelievable flexibility, but as current documentation does not give more than a few examples, it might be difficult to fully understand their internals and requirements.

It should be noted that they do mostly the same thing. You can attach behaviors and event handlers to components to modify the components' behavior.

Events

It is useful when you want to interrupt the normal application flow without extending base classes.

For example, enabling gzip compression on the output could be done via extending CWebApplication. But because there are entry points for event handlers, one can do this:

Yii::app()->onbeginRequest = create_function('$event', 'return ob_start("ob_gzhandler");'),
Yii::app()->onendRequest = create_function('$event', 'return ob_end_flush();'),

You can create an event handler -- which is simply a method in some class with a specific signature -- and attach it to the event of an object. You can add as many event handlers as you wish, from as many objects as you wish. If the event handler is, effectively static, then you can create the object as you assign it:

$test_comp->onSomethingGoesOn = array(new SomeClass, 'eventHandler1');
$test_comp->onSomethingGoesOn = array(new SomeOtherClass, 'eventHandler2');
$test_comp->onSomethingGoesOn = array(new YetAnotherClass, 'eventHandler3');

As long as you have a handle on the object, then you can add an event handler to it.

At some point, you can then raise the event with something like one of these:

$test_comp->onSomethingGoesOn(new CEvent($this));
$test_comp->onSomethingGoesOn(new CEvent());

So, basically, it allows you to build a list of function calls that can later be executed, in the order they were added. It can save you passing around a lot of object refs and building conditional code, since you can still raise the event, even if it doesn't do anything.

Behaviors

Behaviors are simply a way of adding methods to an object.

Take this scenario: You have 2 classes: MySuperClass1, MySuperClass2. There might be lots of methods from MySuperClass1 & 2 that you want in some new class, say MyBoringClass. Unfortunately, php does not allow for this:

class MyBoringClass extends MySuperClass1, MySuperClass2 {
}

This is where behaviors come in. Instead, you can go:

class MyBoringClass extends MySuperClass1 {
}

$classInstance = new MyBoringClass();
$classInstance->attachbehavior('uniqueName', new MySuperClass2);

Now $classInstance has all the methods from MySuperClass1 and MySuperClass2. Since MySuperClass2 is being used as a behavior, it has to extend CBehavior. The only caveat to this is an attached behavior cannot override any class methods of the component it is being attached to. If a method already exists, if it be from the original class or already added by a previously attached behavior, it will not be overwritten.

In an OO language like Ruby, it's quite possible to start with a completely empty object and simply build its behavior as you go along. Yii provides this behavior with a little magic. The key is that the class you wish to add the behavior from must extend Cbehavior.

class SomeClass extends CBehavior
{
public function add($x, $y) { return $x + $y; }
}

Then use with:

$test_comp = new TestComponent();
$test_comp->attachbehavior('blah', new SomeClass);
$test_comp->add(2, 5);

So, in this case, you are extending the functionality of an object with functionality of another object.

After studying this cookbook page you are encouraged to reread the corresponding guide page as it contains advanced information (for example, if you are familiar with interfaces, you might find it enough to implement IBehavior before extending CBehavior).

-------------

behavior和Event在model里用的会相对较多一点,不过,其他地方也可以一用。如果你真的不明白这一块的逻辑,那还是用其他方式替代吧。

editplus 支持svn了

刚才在看sae的文档时,发现他在介绍如何部署代码时提到了editplus,并说,editplus可以用TSVN来部署文件。
这时候我觉得纳闷,什么时候editplus支持SVN了?
然后找到了editplus的官网,找到了what's new:

原来,从3.30开始就支持了。
不过TSVN必须要先安装小乌龟才OK,HOHO,有兴趣的朋友是可以尝试了。
反正我现在用PHPstorm,什么都带了。
自从用了phpstorm,腰不酸腿不疼了。

OS X Tiger: Enable/Disable Spotlight

OS X Tiger: Enable/Disable Spotlight

很幸运,看完这篇文章后,我根据文中的内容,终于恢复了spotlight,所以我现在对邮件什么的也能够搜索了。
OK,这篇文章在这里:http://www.technipages.com/os-x-leopard-enabledisable-spotlight.html
嗯,其实我当时是认为spotlight没什么用啊。但真没想到,原来spotlight接管了这么多功能。NND,我还仅仅以为spotlight是类似第三方插件似以的。没文化啊,真是太可怕了。。。。
上原文:

You may want to turn off Spotlight to increase system performance or to prevent it from indexing personal data. Here’s how to do it under Mac OS X.

Launch Terminal from the Utilites folder.

To disable Spotlight, type the following and press Return:

% sudo launchctl unload /System/Library/LaunchDaemons/com.apple.metadata.mds.plist

To disable it permanently, type this instead:
% sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.metadata.mds.plist

To enable Spotlight type the following and press Return:
% sudo launchctl load /System/Library/LaunchDaemons/com.apple.metadata.mds.plist

To enable it permanently, type this instead:
% sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.metadata.mds.plist

For instructions on how to do this in Mac OS X Leopard, see How to completely disable Spotlight.

---------
HOHO又能够搜索邮件是一件很开心的事情。开始怀念windows下面的搜索了。
很多朋友说你不会直接用find啊。是,如果我搜索文件,用find当然无所谓,可是邮件没办法啊。。

转:Tiger: Disabling Spotlight

转:Tiger: Disabling Spotlight

嗯,到现在为止,我也没有办法搜索我的电脑、mail、甚至 spotlight,真是纠结。
于是这篇disabing spotlight就成了我搜索中的目标。我想,既然能够disable spotlight,那肯定能够enable吧?
所以,上原文吧:http://www.theconsultant.net/2005/06/tiger-disabling-spotlight/

Spotlight introduces a fairely large performance hit on to the system, especially if the files you are working with are both large and have the Spotlight plugin, and thus can be indexed. Performance hit might be less noticable on the desktop system with fast drives, however on my laptop with 4200 rpm drive, and constantly dealing with megabytes of source code and compilations spotlight introduced less of a benefit and more of a hindrance.

So, without further ado, in order to disable spotlight, one has to edit /private/etc/hostconfig, find the line that reads SPOTLIGHT=-YES-, change it to SPOTLIGHT=-NO-, and rebooot.

This will prevent MetaData Service, / System / Library / Frameworks / CoreServices.framework / Versions / A / Frameworks / Metadata.framework / Versions / A / Support / mds from starting on boot time.

Note that this will not disable file change notifications in the kernel, as can be checked using Amit Singh’s fslogger. On the same page there is some more in depth information on the kernel notification service that Spotlight (and fslogger) subscribe to.

A perty GUI called Spotless was written by someone, but I am not sure I’d trust a GUI to parse and edit a text file.

If you want to get rid of the looking glass icon in the top right hand corner as well, you might want to either remove (perferably just move out of place) or chmod -R 0000 /System/Library/CoreServices/Search.bundle (Key file. Actual parts of Spotlight are: /Library/Spotlight /System/Library/Spotlight /System/Library/CoreServices/Search.bundle /System/Library/PreferencePanes/Spotlight.prefPane /System/Library/Services/Spotlight.service /System/Library/Contextual Menu Items/SpotlightCM.plugin /System/Library/StartupItems/Metadata plus /usr/bin/md*, although I’d argue that metadata tools in /usr/bin/md* are actually useful.)
Changing permissions means that if at some point you want to undo the changes, you can always repair permissions. In any case, little looking glass in the corner doesn’t bother me much.

Technically one can probably selectively start and stop Spotlight by killing or startng mds and mdimport, however a way Apple recommends is using mdutil -i off / to turn off indexing of the boot volume (ie existing databases would be preserved and accessible through spotlight).

If you ever want to blow away your Spotlight database, and force reindexing (assuming mds/mdimport run), you can do mdutil -i off /, mdutil -E / , mdutil -i on /

Note: Apprently killing spotlight interferes with find in Finder and in Mail.app. As I never use either (locate or find . -name “*foo*” -print on the command line is much more powerful, plus gives me an -exec stuff {} \; option), it doesn’t bother me, however ocdinsomniac has some nice additional information and a script that purports reverting Finder’s find to the Panther style behavior.

纠结:mac居然不能使用搜索功能了

纠结:mac居然不能使用搜索功能了

不知道从什么时候起,我的macosx系统居然不能搜索了。
Finder中无法找文件
邮件中无法搜索邮件(只能根据发件人的详细地址来筛选)
Spotlight中也无法搜索了。

真纠结啊,不知道是哪里的设置出了问题。NND,望知情者给条生路啊

SecureCRT for MAC 破解

SecureCRT for MAC 破解

之前说过securecrt的破解,说是一直删除/Users/xxx/Library/......下面的lic文件就可以了。但自从换到了6.7.3之后,该功能就无效了。所以在网上找了一些破解。
嗯,QQ微博里素包子说他破解了。但我没看到,我找到了pcbeta的文章,就是这一篇啦 ,作者如是说:
2011.11.20 再次更新
请下载之前版本补丁的重新下载试试。已经解决注册的问题。

2011.11.19更新
更新解决patch后无法注册的问题。
原版备份下载地址:http://115.com/file/aq5ymxbb
由于ipatch bug,在打补丁前需要手动在终端执行以下命令:
sudo chmod -R 777 /Applications/SecureCRT.app/Contents/MacOS


注:patch后需要使用补丁中的注册信息进行注册。方法为点 enter licenseXXXX,在弹出的界面直接选 continue。到了报错界面,左下角会有一个 “Enter License Manually",点击进去后进行注册。

嗯,在之后,得输入以下的注册码:
使用如下的注册信息手工注册:
Name:suddy
Company:suddy
Serial:03-67-009054
Date:11-19-2011
LicenseKey:ACUYJV Q1V2QU 1YWRCN NBYCYK AAXBZT CMJS8Z KBFYR7 QXJE45
--------
具体页面还是看:http://mac.pcbeta.com/thread-79412-1-1.html
记住,这个patch还是需要和官方的版本是一样的,即,版本号是[Mac OS X 6.7.3(build 292) ]
--------
注意,用了这个patch后,你会发现,居然密码不能保存了,怎么办怎么办?
嗯,微博上看到素包子说:把keychain禁用就OK了。于是乎,就搞定了
如何禁用:
在全局设置(GLobal Options)->Terminal->Advanced-> 看到右侧的Mac Options了没?把Use Keychain前的勾去掉就OK了。good luck

【科普贴】话说回车和换行

有意思的文章,大多数时候,我们都是知道\r,\n,\r\n,但为什么是这样的呢,居然找到了一篇科普贴。
来吧,看看为什么吧。
原文来自:【科普贴】话说回车和换行
看xml的时候发现这样的一段话:

XML 以 LF 存储换行

在 Windows 应用程序中,换行通常以一对字符来存储:回车符 (CR) 和换行符 (LF)。这对字符与打字机设置新行的动作有相似之处。在 Unix 应用程序中,新行以 LF 字符存储。而 Macintosh 应用程序使用 CR 来存储新行。

让我对这三个(win,unix,mac)苦逼的主产生了兴趣,为啥你们不一样呢,难道你们认识“回车”和“换行”的时间有先有后吗?为啥没统一或者说为啥产生了CR和LF这两个玩意?说说历史吧!

为什么会有两个貌似一样功能的东西?

潜台词:很多时候敲击enter就是换行了呀,还回啥个车,回车就是换行吗?

在计算机还没有出现之前,有一种叫做电传打字机(Teletype Model 33)的玩意,每秒钟可以打10个字符。但是它有一个问题,就是打完一行换行的时候,要用去0.2秒,正好可以打两个字符。要是在这0.2秒里面,又有新的字符传过来,那么这个字符将丢失。

于是,研制人员想了个办法解决这个问题,就是在每行后面加两个表示结束的字符。一个叫做"回车",告诉打字机把打印头定位在左边界;另一个叫做"换行",告诉打字机把纸向下移一行。

-http://www.ruanyifeng.com/blog/2006/04/post_213.html

为啥windows,unix,mac不统一呢?

可能是基于成本和效率的考虑,我认为都统一成一个“回车”就够了,可是当年正是这种想法导致了现在的问题,至于这三家互不相同,我也不知道,各有各的考虑吧,反正蛋疼的是用户,比起现在浏览器的兼容性问题,这算不上问题。

以下是他们表示“下一行”的方式:

OS 表示 C语言表示 16进制表示

windows 回车+换行(CR/LF) \r\n 0x0d0a

UNIX 换行符(LF) \n 0x0a

MAC 回车符(CR) \r 0x0d

看一下在一份xml文件里的情况吧,我没钱买苹果,所以下面不包括MAC OS,果粉别砍我!

抱怨之余,我们还能干啥呢?

至少你知道这是怎么回事了,至少在不同平台之间传送文件时别傻傻的骂别人没整理文件格式,至少...,这还不够吗?

-------------
在用PHP写文件的时候,一般我们都是用\n来解决断行。但这时候,如果用windows下的记事本打开这个文件,你会发现一堆黑框,并且处在一行里。
因此,看了上面的文章后,你会知道怎么办了。突然想到以前的str_replace(array("\r\n","\r","\n"),"<br />",$str), 这种烂代码。当然nl2br就解决这样的功能了。然后再转回来?哎。纠结啊。。

PhpStorm 3.0 released!

PhpStorm 3.0 released!

一大早就收到这封邮件,灰常开心。
因为在2.x的时候用的就是它,而且,除了代码格式化外(数组这一块的格式化非常不友好),其它我都非常满意。当然也可能是我没有把netbeans的所有能力都发挥出来吧,先看邮件:
PhpStorm 3.0 is now available and introduces the Smart Duplicated Code Detector to help you quickly find similar blocks through your entire code base and securely get rid of them without losing the intended functionality.
Also a new integrated UML tool allows you to quickly get a bird’s-eye-view of your project structure, or even a semantic view of the changes in the recent VCS commits made by your colleagues.
Furthermore, to ensure that your code works fast and doesn’t cause any performance bottlenecks, the IDE now includes a profiler, a new PHPUnit test runner and JSTestDriver.

The new key functionality in PhpStorm 3.0 includes:
- Smart Duplicated Code Detector
- PHP UML roundtrip diagrams
- Profiling results browser for Xdebug and Zend Debugger engines
- PhpUnit 3.6 integration
- CoffeeScript support
- Significant improvements to FTP/SFTP Sync
- TFS support and revision graph for GIT
- Streamlined UI across all operating systems

HOHO,看到没,居然PHP UML roundtrip diagrams,但其实在EAP版的时候,我试过,其实并没有想象中的那么完善,将就着能用用而且。 ftp/sftp 同步还没有试过。。什么时候试用下

详解谷歌官方教程 Android插件ADT 9.0.0

详解谷歌官方教程 Android插件ADT 9.0.0

本文其实已经过时了,但还是可以值得一看,以当作资料,至少我在下载的时候,已经是15.0了,而不是文中说的9.0
我摘抄的文章来自于:http://kb.cnblogs.com/page/91451/

OK,上原文:

  ADT为Android开发工具(Android Development Tools)简称,是在强大的、集成的环境Eclipse IDE中构建Android应用程序插件。

  ADT扩展了Eclipse的功能,让您快速建立新的Android项目,创建一个应用程序的用户界面,加上Android框架的API组件、调试应用程序使用Android SDK工具,以便APK分发给应用程序。

  首先,强烈建议尽快开始使用Eclipse开发插件ADT。随着项目设置我们将提供指导、以及工具的集成和自定义XML编辑器,并在ADT给你的一个令人难以置信的开发Android应用环境。

  本文提供从Eclipse开发环境分步说明到如何安装下载的ADT插件的全过程,请注意只有当你有Android兼容版本的SDK安装在Eclipse IDE时你才能安装或使用ADT。

  如果您已经使用ADT的,本文还提供了有关如何更新ADT的最新版本或如何卸载它的必要的指示。

  ADT最新修订内容

  以下我们提供有关后续版本的ADT插件的版本号

  ADT 9.0.0 (2011年1月)

  ADT 9.0.0与Android R9 SDK工具的关系:

  ADT 9.0.0是专为Android R9 SDK工具提供的插件。

  一般注意事项:

  转至声明”超链接支持:可以直接从代码引用(R.id.main )跳到相应的XML声明或从清单的XML登记的活动和服务。

  改进了的名字重构。

  改进的可视化布局编辑器等。

  ADT 8.0.1 (2010年12月)

  ADT 9.0.0是专为Android R8 SDK工具提供的插件。

  一般注意事项:

  这是一个快速跟进ADT的8.0.0修正了一些错误。

  修复了问题,哪些项目编译失败,理由是敏捷的错误。

  更好ProGuard的错误报告时发布出口申请。

  安装ADT插件

  下面我们将说明如何下载和安装Eclipse ADT。

  准备工作

  ADT是为Eclipse IDE的插件。在安装或使用ADT时,你必须安装一个兼容版本的Eclipse在你的电脑上。

  如果Eclipse已经安装在你的电脑,请确保它是一个兼容AndroidSDK与ADT版本。

  如果您需要安装或更新Eclipse,你可以从这个位置下载它:

http://www.eclipse.org/downloads/

  此外,在你可以配置或使用ADT时,你必须安装Android SDK的启动包,如我们提供下载Android R9 SDK的入门包 。 具体来说,您需要安装一个Android SDK工具兼容版本和至少一个开发平台。 为了简化ADT的设置,我们建议安装的Android SDK之前安装ADT。

  当您的Eclipse和Android SDK的环境都准备好了,请按照下面的步骤来完成ADT安装。

  ADT插件下载

  使用Update Manager里的Eclipse安装功能,把ADT的最新版本安装在你的电脑上。

Eclipse 3.5 (Galileo) and 3.6 (Helios) Eclipse 3.4 (Ganymede)
  1. Start Eclipse, then select Help > Install New Software....
  2. Click Add, in the top-right corner.
  3. In the Add Repository dialog that appears, enter "ADT Plugin" for the Name and the following URL for theLocation:https://dl-ssl.google.com/android/eclipse/

    Note: If you have trouble acquiring the plugin, try using "http" in the Location URL, instead of "https" (https is preferred for security reasons).

    Click OK.

  4. In the Available Software dialog, select the checkbox next to Developer Tools and click Next.
  5. In the next window, you'll see a list of the tools to be downloaded. Click Next.
  6. Read and accept the license agreements, then clickFinish.
  7. When the installation completes, restart Eclipse.
  1. Start Eclipse, then select Help > Software Updates.... In the dialog that appears, click the Available Softwaretab.
  2. Click Add Site.
  3. In the Add Site dialog that appears, enter this URL in the "Location" field:https://dl-ssl.google.com/android/eclipse/

    Note: If you have trouble acquiring the plugin, you can try using "http" in the URL, instead of "https" (https is preferred for security reasons).

    Click OK.

  4. Back in the Available Software view, you should see the plugin listed by the URL, with "Developer Tools" nested within it. Select the checkbox next to Developer Tools, which will automatically select the nested tools. Then click Install
  5. On the subsequent Install window, all of the included tools should be checked. Click Next.
  6. Read and accept the license agreements, then clickFinish.
  7. When the installation completes, restart Eclipse.

  安装兼容版本的Eclipse IDE的,请查看这个地址。完成这些之后请按照下列步骤下载ADT插件并安装在你的Eclipse环境中。

  ADT插件配置

  成功下载ADT的如上所述之后,修改Eclipse的ADT的参数指向了Android SDK目录:

  选择 Window > Preferences... 打开参数面板(在Mac OS X上请选择: Eclipse > Preferences )。

  选择Android从左侧面板。

  对于Android SDK位置在主面板,点击 浏览并找到您下载的SDK目录。

  单击“应用”后 ,点击“确定”。

  如果你没有遇到任何问题,则安装完成。 如果你是第一次安装了Android SDK的,返回到 安装Android SDK来完成您的设定。

  ADT的安装故障排除

  如果你按照以上步骤无法下载的ADT插件,这里有一些建议:

  如果Eclipse无法找到远程更新站点,尝试改变远程站点的URL使用的HTTP而不是HTTPS,包含ADT插件。 也就是说,设置远程站点的位置:

http://dl-ssl.google.com/android/eclipse/

  如果您仍然无法使用Eclipse ADT的下载站点为远程更新插件,你可以下载ADT压缩文件下载到你的电脑上,然后手动安装它:

Name Package Size MD5 Checksum
ADT 9.0.0 ADT_9.0.0.zip 4433536 bytes bc2757f2a5a11d131390ce547bae154b

  浏览并选择下载的zip文件。

  输入本地更新站点的名称(例如,“Android Plugin”)。

  单击“确定”。

-------

来自dbanotes:对 Pinterest 类应用的一点思考

来自dbanotes:对 Pinterest 类应用的一点思考

这是冯大辉的博客中的一篇文章,看看之余我也在剖析自己的内心。我是该继续做开发,还是转行做产品?
虽然我对产品的理解和设计暂时还不如那些专业的产品经理,但是从事互联网这么多年,没见过猪跑总还吃过猪肉的吧?
OK,先上原文,再继续乱弹,原文来自: 对 Pinterest 类应用的一点思考

最近一段时间 Pinterest 类应用相当火爆,引发了不少讨论。我自己最近也一直在使用花瓣 ,也在捉摸为什么这一类应用这么有魔力。知乎上有个问题是: Pinterest 好在哪里?,尝试做了一下回答,也稍作整理,发在这里做个记录,会随着理解再做进一步修改。

本质上,Pinterest 类应用属于社会化书签站点的延续,只是要处理的数据对象变成了「图片」,而不是传统社会化书签的URL。这是社会化信息处理的一次改良。

提到社会化书签,不得不提 Del.icio.us ,不过或许 Del.icio.us 模式已经到头了,即使现在从Yahoo! 手里卖给了陈士骏,也不太可能玩出新花样,因为核心的数据对象没变。

相比 Flickr 来说,Pinterest 主要的生成内容动作是 Pin (花瓣叫采集),而 Flickr 则是 Upload,这个动作上的不同导致 Flickr 向左,Pinterest向右。Flickr 重心是「照片」(Picture),尤其是原创照片,而非图片(Image)。 Flickr的一个弊端是大量的图片没有标题,这意味着元数据的先天不足,不太可能和其他网络内容进一步结合起来。但是也要说一下,Flickr 现在的价值是被低估了。

Pinterest 相对 Flickr 来说,恰恰是一种互补,每张图片基本可以关联到一条URL,进一步可以抽取其他信息。

从用户行为的角度上看,满足了用户天生的「收集癖」,很多人都有看到一张照片想顺手存起来的冲动,没有Pinterest这类产品之前,这个交互操作太费事了... Pinterest 无疑弥补了人的这个原始的需求。

Pinterest 类应用的创新之处我认为是「降低了收集信息的门槛」,或者,至少做到了这一点。其价值是不言而喻的,每一次信息处理的门槛降低都会得到商业价值的变现,你可以不信。

要有足够好的技术团队支撑、足够好的数据处理能力才能走到最后,这也是在国内众多产品中我看好花瓣(huaban.com)的主要理由。

--EOF--

目前现在很多网站都在做Pinterest正在做的事情,而且由于国内广大网民(非设计师、程序员、产品)接触国外网站的机会比较少,因此,这些有创意的复刻版在国内就变得很流行了。

说到美味书签,真要算的话,国内其实也有很多做类似的,只是很多人都不习惯它的使用方法。但要说他死了?也不见得,毕竟书签有很多展示方式,比如:read it later,难道就不能算是一个书签?它也能够通过API的方式来对外分享,而且正因为提供了API,使得在任意平台上都可以支持了read it later,越往后,书签就越来越趋向于移动设备的支持,但移动设备的屏幕小,不适合看书签收藏的网页中提供的内容。所以read it later提供的纯文本阅读,就使得这个缺陷被无限缩小了。

象Pinterest这类网站,还真的不好说能够在移动设备上占优势,流量啊,那可是要钱的东西,you know.