Lion上开启非苹果Magic Mouse的自然滚动模式

随着Lion的发布而到来的Natural Scroll滚动模式,改变了已经使用并且适应了多年的方式。但是这种我们使用并且习惯了的滚动方式,和手机上的滚动方式正好相反,而且实际上手机上的滚动模式更加符合我们日常生活中的使用习惯。想要往下滚动,就往上推,反之依然。

无论是Magic Mouse, 还是TrackPad都能很好的支持这种Natural Scroll方式,但是对于其它的鼠标就悲剧了。如果你同时拥有Magic Mouse和Logictech/Microsoft鼠标,这种不同的使用习惯会让你觉得无所适从。当然你可以在Lion上关闭这种Natural Scroll, 而继续使用老式的滚动方式,但是事实上如果你坚持用一两个小时,你就能很快的适应这种方式,因为他更加符合我们实际的使用习惯。

那么对于非苹果鼠标怎么办呢?怎么改变他的滚动方式呢?答案就是ScrollReverser. 这是一个非常小巧的软件,打开之后会在你的状态栏上出现一个新的小图标。

Screen Shot 2012 05 20 at 6 05 35 PM

这个向上向下的箭头就是这个app, 

NewImage

把它设置成“Start at Login”,然后就可以是真正的Natural Scroll了,不管什么鼠标。

Enable Trim of Your SSD on Mac OS X

If you don’t enable your TRIM of your SSD, then you only have a jeopardized SSD. On Mac OSX, it doesn’t turn on TRIM function by default for third party SSD. So you’ll have to do it by yourself. But the process used to be painful, at least not enjoyable, you’re instructed to run commands that you have no idea about it, and hope that it would do the magic. But now, things have changed. I present you TRIM Enabler. Just one Click, isn’t it easy enough? Trim Enabler

After a root, you shall see this information in your System Info

NewImage

用Codeigniter的Form_validation验证Service请求

CodeIgniter中的Form_validation在进行Form的有效性验证时是一把利剑,非常有,而且它返回的出错信息也能非常方便的custom显示。Form_validation的源代码显示,validation置对POST请求起作用,这有两方面的意思。一个是对GET请求无效(废话:), 另一个是只要是POST请求,不管是请求来自Form提交,还是来自Service请求,它都能起作用。因此我就把它用到了我的Service中。

利用Form_validation的Service

function register()
    {
    	$this->load->library('form_validation');
    	$this->form_validation->set_rules('name', 'Name', 'required|is_unique[users.name]');
		$this->form_validation->set_rules('password', 'Password', 'required');
		$this->form_validation->set_rules('email', 'Email', 'required|valid_email|is_unique[users.email]');

		if($this->form_validation->run() == true)
		{
			$model = new User_model;
			$model->name = $this->input->post('name');
			$model->email = $this->input->post('email');
			$model->password = SHA1($this->input->post('password'));
			$model->register_time = date('Y-m-d H:i:s');

			$this->db->insert('users', $model);
		}
		else
		{
			$this->output->set_status_header('400');
			$this->output->set_output(json_encode($this->form_validation->error_array()));
		}

    }

Form_validation能很好的工作,但是问题是在validation失败时,返回的错误信息是包含了Html Tag的,比如默认的P元素。

在Form_validation的源代码中,无论是

public function error($field = '', $prefix = '', $suffix = '')
public function error_string($prefix = '', $suffix = '')

,返回的错误信息都包含的Html元素内。当然你可以把自定义元素为一个“空格”(不能为0个空格),但是这样的做法显然太为了解决问题而解决了。

扩展Form_validation

Form_validation的源码中有一个字段叫做$_error_array,用来存储所有的validation失败的信息。可惜这个字段是protected的,直接是无法访问的。不过protected的字段,继承一下不就能用了吗?那就来扩展一下吧。

class My_Form_validation extends CI_Form_validation{

    function __construct(){
        parent::__construct();
    }

    function error_array(){
        if(count($this->_error_array)===0){
            return null;
        }else{
            return $this->_error_array;
        }
    }
}

新建一个error_array函数,把本来protected的字段给暴露出来,然后就可以象第一段Service代码中那样来调用了。

$this->form_validation->error_array();
Rock Feller

Rock Feller

on top of The Rock

Sublime 2 Tips之Multiple Selections

一个没有Multiple Selection的编辑器是不能为开发者所喜欢的,作为后起之秀,目前最火的编辑器,Sublime当然不会缺少这个功能。

首先是多个光标

Mac上,按住command键的同时,Click会产生一个新的光标。这时你就可以同时编辑了。

Screen Shot 2012 04 26 at 12 18 00 AM

无论是CRUD,还是移动,通通都可以。

Multiple Selection

选中一个word的时候,按下command+d,就会向下选中下一个相同的word,

Screen Shot 2012 04 26 at 12 20 49 AM

此时有三个“messages“是被选中的,如果再次command+d,就会选中右边的messages

两个简单但实用的Tips,下回介绍一个Sublime 2中的插件功能

Page 1 of 712345»...Last »