易栈网-膘叔

浏览模式: 标准 | 列表 | 图文

DNS又被长宽劫持了

以前写过自己在家里的DNS被长宽劫持的文章,现在又遇到了。
其实,以前我都忍了,什么弹旅游的广告啦,弹这个那个的广告啦。如今,干脆弹的我打不开博客了。MD。
为了防止别人说我诬蔑他们所以我一一截图,首先,我的首页的源码变成:

<html><body style=‘margin:0;padding:0;height:100%’ scroll=no><div id=‘Z’></div><iframe id=‘CC’ name=‘CC’ src=‘http://neatstudio.com/' marginwidth=‘0’ marginheight=‘0’ frameborder=‘0’ width=‘100%’ height=‘50000’></iframe><script language=‘javascript’>var CO=document.getElementById(‘CC’);var M=‘http://neatstudio.com/';try{CO.contentWindow.document.location.href=M}catch(e){};setTimeout(“G()”,1500);function G(){try{var t=CO.contentWindow.document.title;if(t==undefined||t==‘’){setTimeout(“G()”,1500);return}document.title=t}catch(e){}}function H(m){document.getElementById(m).height=document.documentElement.offsetHeight-5}window.setInterval(“H(‘CC’)”,100);function T(){location.href=M}</script><script src=“http://124.14.10.69/js/cdn5.js”></script></body></html>

OK,这段代码还可以通过 firebug看到:

然后,用phoneix打开这个JS,看一下详细内容:

看到没,会跳到这个play.tenoad.com,这是一个什么网站呢?是一个游戏推广页面。那么tenoad.com是什么样的网站呢?是一家广告公司。。。我晶。
我当前的IP地址是:124.14.7.171,这个广告的地址是:124.14.10.69,长宽 ,你还不承认 ??
行,我问IP138去:

然后我再刷新,晶啊,还不止一种广告:

还有第二种。。。。
再到google里搜索了一下,我晶,原来还有老外在抱怨,虽然我不喜欢日本,但这回总算有了共同语言:

如果你还不信?你可以打开:http://ch.livedoor.biz/archives/51882715.html,看看别人是怎么说的。
是啊,这个网站在最后还这么说呢:

たとえ中国といえども
まさかネットに接続するプロバイダーがここまで
酷いとは思わなかった...

果たして苦情の回答はくるのだろうか?

なんて回答がくるか楽しみ

所以,我相对还是蛋定了许多。。

YII中的CComponent,CEvent与Behavior及CActiveRecordBehavior

YII中的CComponent,CEvent与Behavior及CActiveRecordBehavior

上一篇文章我介绍的是官方的event和behavior的文章,这一篇是来自个人博客。
嗯,本来只是放在read it later做备份的,不料今天打开的时候发现,这篇文章已经不见了。该博客重新创建,原来的数据都没有了。所幸,我曾用read it later处理过纯文本模式,因此,我将它备份下来,以防哪天read it later也崩了。
ok,上原文链接。靠,原文打不开了,还是上这家网站的地址吧。。。http://www.trailroom.com/
内容其实这样的:

YII中的CComponent,CEvent与Behavior及CActiveRecordBehavior个人理解
这一块教程少,今天个人理解了下,写了个小例子,有助于理解

完成如下功能,一个JTool类,继承CComponent,当其长度改变时,调用事件,输出”change me”.
JTool.php在protected/components 下:

<?php
class JTool extends CComponent{
private $_width;
public function getWidth(){
return $this->_width ? $this->_width : 1;
}

public function setWidth($width){
if($this->hasEventHandler(‘onChange’)){
$this->onChange(new CEvent());
}
$this->_width = $width;
}

public function onChange($event){
$this->raiseEvent(‘onChange’, $event);
}

OK,功能已经实现了,找个控制器,执行

现在我们想给JTool添加一个功能,返回长度的100倍,我们可以继承JTool.php写一个方法

[。。。TEXT后,这一段内容消失了]
OK,功能实现了,这个执行就简单了new JToolSub调用方法即可

上边的这两种办法,就是仅完成功能,下边演示Behavior及events来实现

如何用Behavior来实现上边的增加一个方法,返回长度的100倍的功能呢?
写类JBe
JBe.php在protected/behavior 下:

class JBe extends CBehavior{

public function get100width(){
return $this->Owner->width*100;
}
}

OK,功能已经实现了,找个控制器,执行

如何用Behavior实现JTool中的长度改变时,调用一个事件的功能呢?
写类JBe:

class JBe extends CBehavior{
public function events(){
return array_merge(parent::events(),array(
‘onChange’=>’change’,
));
}

public function change(){
echo ‘changed’;
}

public function get100width(){
return $this->Owner->width*100;
}
}

OK,功能实现随便找个控制器,执行

这里的要点是events方法
返回的数组array(‘onChange’=>’change’)定义了事件(event)和对应的事件处理方法(event hander)

事件是是Compents(JTool中)定义的,即JTool中的onChange
处理方法同由Behavior(JBe中)类定义的,即JBe中的change

这样子再看CActiveRecordBehavior,其是绑定给CActiveRecord 这个组件的,绑定方法重写behaviors()
CActiveRecordBehavior中的events() 方法返回事件及事处理函数的对应,如:
‘onBeforeSave’=>’beforeSave’

即组件CActiveRecord中的onBeforeSave这个事件对应的处理函数是
CActiveRecordBehavior中的beforeSave方法

这样子CActiveRecord在调用save()时,触发事件onBeforeSave,调用CActiveRecordBehavior对应的处理函数beforeSave
我们只要写一个CActiveRecordBehavior的子类,重写其中的beforeSave,执行一些操作,然后给CActiveRecord绑定即可

我还有个疑问,在继承CBehavior时,是不是一定要让方法events()反回那个对应关系的数组,如果这里为空,没有默认的对应关系?

---------

虽然TEXT保留了大部分内容,但还是有一小部分不见了。真可惜

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 同步还没有试过。。什么时候试用下