Skip to content

Instantly share code, notes, and snippets.

View akirayu101's full-sized avatar
🥅
Focusing

Akira Yu akirayu101

🥅
Focusing
  • Bytedance
  • Hangzhou.China
View GitHub Profile
@akirayu101
akirayu101 / hook_tb.lua
Created July 8, 2014 12:56
method missing
hook_tb = {}
local function hook_index(o, key)
print("get", key)
if type(o["data"][key]) ~= "table" then
return o["data"][key]
else
@akirayu101
akirayu101 / class design
Last active August 29, 2015 14:03
lua class design
###lua class设计
* 首先要有super chain, 能够正确无误的调用super方法
* 在create阶段绑定所有的attribute,在create结束后,应该禁用掉一切我外部绑定新attribute的方法,防止别人改掉内省逻辑
* 所有数据成员,应该具有一个初始值设定,对数据对象的生命,应该调用self:define_attribute(key, value, defaultValue)
* 对于回收时刻,应该对每一个attribute,变更成初始状态的值
* 应该支持面向接口集合的delegate,以便进行组合
* 应该对对象内置函数和状态位之间的hook来进行状态位的绑定,不给外部改变状态的机会
* 其他优化点
@akirayu101
akirayu101 / hook_timer
Created August 21, 2014 08:55
hook timer
require "src/third/socket.lua"
local time_table = {}
local function hook_timer(o, key, value)
if type(value) == "function" and value ~= "summary" then
local function inner( ... )
time_table[key] = time_table[key] or 0.0
print("in function ",key)
* Generate classes like WhereNot automatically with class decorator?
* Haskell style deconstruction, perhaps like:
@pmatch
def count(first_arg=Match(x=Head, *xs=Rest)):
print x, xs
Will require some nasty hacks like https://github.com/smcq/python-inject
* Implement boolean operators for stuff like:
@pmatch
@akirayu101
akirayu101 / simple_lua_rpc.lua
Created November 27, 2014 03:31
simple_lua_rpc
rpc_lua = {}
function rpc_lua:call(fn_name, ...)
return self[fn_name](self, ...)
end
function rpc_lua:test1(arg1, arg2, arg3)
print "test1"
end
@akirayu101
akirayu101 / test_gm.lua
Created November 27, 2014 09:41
test gm
rpc_lua = {}
function rpc_lua:call(fn_name, ...)
return self[fn_name](self, ...)
end
function rpc_lua:test1(arg1, arg2, arg3)
print "test1"
end
require "src/modules/traceback.lua"
hook_tb = {}
local function hook_index(o, key)
local function_name, filename, line = traceback.getsource(4)
logger:fatal("access hook_tb in funtion[%s] filename[%s] line[%d]", function_name, filename, line)
a = {}
a["__realdata"] = {}
a["__realdata"]["a"] = 1 -- save const a
a["__realdata"]["b"] = 2 -- save const b
local function const_index(o, key) return o["__realdata"][key] end
local function const_newindex(o, key, value) return end
setmetatable(a, {__index = const_index, __newindex = const_newindex})
print(a["a"])
print(a["b"])
@akirayu101
akirayu101 / simple_spider.py
Last active August 29, 2015 14:11
test gevent simple spider
__author__ = 'hzyuxin'
import requests
from gevent import monkey
monkey.patch_all()
import gevent
main_url = 'http://www.cellmap.cn/cellmap_gsm2gps_api.aspx'
def job(lac, cell):