Skip to content

Instantly share code, notes, and snippets.

Avatar

Pengfei Liu prafulliu

  • teambition
  • shanghai
View GitHub Profile
@prafulliu
prafulliu / readOnlyTables.lua
Created Dec 18, 2012
read-only tables in lua.
View readOnlyTables.lua
function readOnly( t )
local proxy = {}
local mt = {
__index = t,
__newindex = function ( t, k, v )
error("attempt to update a read-only table", 2)
end
}
setmetatable(proxy, mt)
return proxy
@prafulliu
prafulliu / set.lua
Created Dec 18, 2012
A lua metatable demo.
View set.lua
Set = {}
-- create a new set with the values of the
-- given list
local mt = {}
function Set.new(l)
local set = {}
@prafulliu
prafulliu / tree.md
Created Jul 23, 2012 — forked from hrldcpr/tree.md
one-line tree in python
View tree.md

One-line Tree in Python

Using Python's built-in defaultdict we can easily define a tree data structure:

def tree(): return defaultdict(tree)

That's it!

@prafulliu
prafulliu / fatal: remote origin already exists
Created Jan 8, 2012
fatal: remote origin already exists
View fatal: remote origin already exists
出现fatal: remote origin already exists. git,可是我就是没有弄过,不知道怎么解决耗了挺久,在网页上看就是没看出来,把网页上的仓库删了还出这个错误,终于找到方法git remote rm origin
重新git remote add origin git@github.com:young001/personal_config.git
最后git push origin master
View metatable
http://www.cnblogs.com/simonw/archive/2007/01/17/622032.html
http://blog.csdn.net/hong201/article/details/4153182
http://www.cnblogs.com/simonw/archive/2006/12/20/597986.html
View vim config
http://spf13.com/post/ultimate-vim-config
View vim批量替换
http://hi.baidu.com/zhmsong/blog/item/7cb17eeaddca8adad539c977.html
:s/XXX/YYY/g
其中XXX是需要替换的字符串,YYY是替换后的字符串
以上这句只对当前行进行替换,如果需要进行全局替换,则要:
%s/XXX/YYY/g
如果需要对指定部分进行替换,可以用V进入visual模式,再进行
:s/XXX/YYY/g
或者可以指定行数对指定范围进行替换:
View shuffle lua
http://www.gammon.com.au/forum/?id=9908
http://blog.fuqcool.com/2011/04/17/algorithm-shuffle.html
http://en.wikipedia.org/wiki/Fisher-Yates_shuffle
View ubuntu添加证书
http://linux.itwaka.com/administer/69448.html
sudo apt-get install libnss3-tools
最终执行如下命令导入根证书:
certutil -d sql:$HOME/.pki/nssdb -A -t "C,," -n <证书别名> -i <证书文件>
View linux 批量替换查找
sed -i "s/floating-point/fixed-point/g" `find . -name "*.xml"|xargs grep floating-point -rl`
http://www.blogjava.net/hispark/archive/2010/08/14/328851.html