Skip to content

Instantly share code, notes, and snippets.

View liluo's full-sized avatar
:octocat:
Hey, there ~

liluo liluo

:octocat:
Hey, there ~
View GitHub Profile
@liluo
liluo / gist:2965927
Created June 21, 2012 14:04
ruby 图表库
http://tioga.rubyforge.org/index.html
@liluo
liluo / gist:2964598
Created June 21, 2012 08:32
labs.douban.com
while [ $? -eq 0 ];do nc -vlp 8888 -c'(r=read;e=echo;$r a b c;z=$r;while [ ${#z} -gt 2 ];do $r z;done;f=`$e $b|sed "s/[^a-z0-9_.-]//gi"`;h="HTTP/1.1";o="$h 200 OK";c="Content";hd="$c-Type: text/html; charset=utf-8";if [ -z $f ];then($e "$o";$e $hd;$e;ls|(while $r n;do if [ -f "$n" ]; then $e "<a href=\"/$n\">`ls -gh $n`</a><br>";fi;done););elif [[ $f =~ eggs ]];then($e "$o";$e $hd;$e;curl http://labs.douban.com/doublo/eggs?k=`$e $f|sed "s/eggs//gi"` 2>/dev/null;);elif [ -f $f ];then $e "$o";$e "$c-Type: `file -ib $f`";$e "$c-Length: `stat -c%s $f`";$e;cat $f;else $e -e "$h 404 Not Found\n\n404\n";fi)';done
@liluo
liluo / rubypython.rb
Created June 11, 2012 01:37
rubypython test
1.9.2p320 :001 > require 'rubypython'
=> true
1.9.2p320 :002 > RubyPython.start
=> true
1.9.2p320 :003 > sys = RubyPython.import('sys')
=> <module 'sys' (built-in)>
1.9.2p320 :004 > sys.path.append('/var/shire')
=> None
1.9.2p320 :005 > user = RubyPython.import('luzong.user')
=> <module 'luzong.user' from '/var/shire/luzong/user/__init__.pyc'>
from collections import Counter
r1 = {'a': {'q': 1, 'w': 2}, 'b': {'q': 3, 'w': 4}}
r2 = {'a': {'q': 5, 'w': 7}, 'b': {'q': 8, 'w': 2}}
r = dict(zip(r1.keys(), map(lambda r: dict(r[0] + r[1]), zip(map(lambda k: Counter(r1[k]), r1), map(lambda k: Counter(r2[k]), r2)))))
print r
r1 = {'a': {'q': 1, 'w': 2}, 'b': {'q': 3, 'w': 4}}
r2 = {'a': {'q': 5, 'w': 7}, 'b': {'q': 8, 'w': 2}}
# ret = {'a': {'q': 6, 'w': 9}, 'b': {'q': 11, 'w': 6}}
a = lambda x, y: list(zip(x.keys(), list(zip(x.values(), y.values()))))
rs = reduce(a, (r1, r2))
print rs
#print reduce(a, map(lambda r: r[1], rs))