[ Content | Sidebar ]

Archives for 四月, 2011

乱马~

~/.bashrc

#flex sdk在ubuntu上好好的,到了mac os下就乱码了~~!
mxmlc()
{
    /Users/hualu/opt/flex_sdk_4.1.0.16076/bin/mxmlc $* | iconv -f gb2312 -t utf-8
}
 
#tree,一条基本不用的命令,给同学发目录列表用过一次,中文会被编码
tree()
{
    /opt/local/bin/tree $* | ascii2uni -aK
}
Copy Code 

关于js的字符串编码

The String type is the set of all finite ordered sequences of zero or more 16-bit unsigned integer values (“elements”). The String type is generally used to represent textual data in a running ECMAScript program, in which case each element in the String is treated as a code unit value (see Clause 6). Each element is regarded as occupying a position within the sequence. These positions are indexed with nonnegative integers. The first element (if any) is at position 0, the next element (if any) at position 1, and so on. The length of a String is the number of elements (i.e., 16-bit values) within it. The empty String has length zero and therefore contains no elements.
When a String contains actual textual data, each element is considered to be a single UTF-16 code unit. Whether or not this is the actual storage format of a String, the characters within a String are numbered by their initial code unit element position as though they were represented using UTF-16. All operations on Strings (except as otherwise stated) treat them as sequences of undifferentiated 16-bit unsigned integers; they do not ensure the resulting String is in normalised form, nor do they ensure language-sensitive results.

按照ECMA标准,无论引擎底层如何实现,js的字符串看起来都应该是UTF-16编码的字符串,并且每个字符串单元代表一个UTF-16的双字节
例如:
>”中”.length
1
(不知道这是啥特殊字符,发到wordpress有问题,直接贴图,那我是怎么输进去的呢,后面说转义符)
“中”编码成UTF-16为一个双字节0x4E2D,所以长度为1
长的像口的字符编码成UTF-16占4字节 0xD950 0xDF21,占用两个双字节,长度为2
(下面用”口”代替这个特殊字符)
>”口”[0]
“”
>”口”.charCodeAt(0).toString(16)
“d950″
所以字符串的长度显然是占用双字节的个数,而非我以前想当然认为的实际字符的个数。。。

\udddd形式的转义同样用来表示一个双字节,而非字符本身,”口”用转义符来表示的话:

最后我要的结论是:

对于像objective c里unichar一样的UTF-16编码格式的字符串可以通过@“\\u04x”直接得到json转义串~

VimiTunesList for vim on Mac OS X

2011.4.18更新
增加了一个选项,可以指定一个播放列表
let g:vim_itunes_playlist = “音乐”
——————-
本来用automator为itunes添加了一个全局搜索的快捷键,无奈快捷键不快捷,点击到激活延迟严重,从itunes选完不能自动返回vim,跟我ubuntu上自己写的mpd搜索不能比。so,写了一个vim插件,效果看我用quicktime录的屏幕(唉,ubuntu上完全没有好用的屏幕录像工具)

第一次加载列表慢点,以后有缓存就瞬间了,刷新缓存用 ctrol+r

安装方法:
下载两个文件
vimiTunesList.vim
vimitunes
将vimiTunesList.vim放到 ~/.vim/plugin/目录
将vimitunes放入$PATH里面随便一个目录,比如我的~/bin

使用方法:
开vim或macvim,输入:IT,会加载一次列表,在想要播放的曲目上回车播放,可以vim的搜索方式搜索。

Python简介

给同事做了一个小分享,主要是简单介绍一下python这门语言,ppt贴上,期待python能够成为主流!!!

一个vpn越墙用的路由表修改工具

刚换到mac,昨天搞定翻墙这事,自己有个vpn,但是几乎没用,因为开了vpn所有连接就都走vpn了,与内网测试机无缘。不过直到昨天发现,路由表可以搞定这事。。
原理是:默认网关不选vpn,把需要访问网站的ip添加到路由表,路由到vpn网关即可~
工具:autovpnconf
下载之后用文本编辑器修改一下里面需要使用vpn的网站列表,我只加了几个

前提:连接vpn,并且vpn不是默认网关
mac下只要不选“通过vpn连接发送所有通信”即可
ubuntu下,连接vpn之后就成默认网关了,可以手动改回来

sudo route del default
#xx.xx.xx.xx是网关ip eth0是有线网卡设备名,如果用无线就是 wlan0
sudo route add default gw xx.xx.xx.xx dev eth0
Copy Code 

之后执行:

sudo ./autovpnconf
Copy Code 

OK了,这样以来只有指定的网站才会走vpn。
!!!每次连接vpn都需要执行一下~~!