Skip to content

Instantly share code, notes, and snippets.

View lhwork's full-sized avatar

李焕 lhwork

  • 热酷
  • http://www.gravatar.com/avatar/14cdd9dd97899e09d30ee7b012a73117.png
View GitHub Profile
这里提供 Lua 中实现 OO 的一种方案:
local _class={}
function class(super)
local class_type={}
class_type.ctor=false
class_type.super=super
class_type.new=function(...)
local obj={}
@lhwork
lhwork / gist:3979039
Created October 30, 2012 08:40
erlang crc32 hash 算法 使用 put get
-module(erichash).
-export([start/2, getTargetInfo/1]).
-define(HOST_LIST_ETS_NAME , hostlist).
-define(PROCESS_LIST_NAME , pl).
start(HostList , Num) when is_list(HostList), is_integer(Num) ->
erase(?PROCESS_LIST_NAME),
targets(HostList, Num),
self().
@lhwork
lhwork / gist:3944817
Created October 24, 2012 08:24
Erlang代码片段
.列表操作
lists:foreach (fun(X) -> io:format("E=~p~n",[X]) end, [1,2,3]).
lists:duplicate (10, 16#f). % [15,15,15,15,15,15,15,15,15,15]
"abc-123" -> "abc"
no_vsn(Name) -> lists:takewhile (fun($-)->false;(_)-> true end,Name).
@lhwork
lhwork / libmis.erl
Created October 24, 2012 06:28
两行代码实现全排列
-module(libmis).
-export([perms/1]).
perms([]) -> [[]];
perms(L) -> [ [H|T] || H <- L, T <- perms(L--[H])].
@lhwork
lhwork / gist:3918279
Created October 19, 2012 13:39
python(PIL)图像处理(等比例压缩、裁剪压缩) 缩略(水印)图
#coding:utf-8
'''
python图片处理
@author:fc_lamp
@blog:http://fc-lamp.blog.163.com/
'''
import Image as image
#等比例压缩图片
def resizeImg(**args):
@lhwork
lhwork / gevent-asyncfile.py
Created June 4, 2012 05:45
gevent-asyncfile
#!/usr/bin/env python
# coding:utf-8
import sys
import os
import fcntl
import gevent.hub
import gevent.socket
class _socketobject: