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
View date.lua
JAN = 31
daysFeb = {28, 29}
MAR = 31
APR = 30
MAY = 31
JUN = 30
JUL = 31
AUG = 31
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 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
或者可以指定行数对指定范围进行替换:
@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
@prafulliu
prafulliu / gist:4411747
Created Dec 30, 2012
Get the last element of a table. table.maxn()
View gist:4411747
GameConfig = {}
GameConfig.CnfCity=
{
[1] = {
name = [[testname]],
value = 1,
list = {
{100, 1, 2000, 100, 0, 3, 1, 0, },
{101, 3, 2001, 101, 4, 3, 1, 1, },
{102, 3, 2002, 100, 0, 3, 1, 0, },
View getTableLength.lua
t = {[2] = 2}
local count = 0
for k,v in pairs(t) do
count = count + 1
end
print(count)
@prafulliu
prafulliu / datejudge.lua
Created Dec 30, 2012
lua判断两天是否连续
View datejudge.lua
local t1 = os.time{year = 2012, month = 12, day = 19, hour = 0, sec = 0}
local t2 = os.time{year = 2012, month = 12, day = 19, hour = 23, sec = 59}
if (t1 - t2) <= 86400 and
(os.date("%d", t1) ~= os.date("%d",t2)) then
-- 判断是否有新手目标
print("called")
end
View trackingTableAccess.lua
t = {}
--keep a private access to the original table
local _t = t
--create proxy
t = {}
--create metatable
@prafulliu
prafulliu / window.lua
Created Dec 18, 2012
A window demo in lua. __index
View window.lua
Window = {} -- create a namespace
-- create the prototype with default values
Window.prototype = {x=0, y=0, width=100, height=100}
Window.mt = {} --create a metatable
--declare the constructor function
function Window.new( o )
setmetatable(o, Window.mt)
return o