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
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))
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
@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'>
@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 / gist:2965927
Created June 21, 2012 14:04
ruby 图表库
http://tioga.rubyforge.org/index.html
1, 获取 access token
get '/auth/douban/callback' do
auth = env['omniauth.auth']
credentials = auth['credentials']
end
在这里可以拿到 credentials, 大致格式:
{"token"=>"xxxxxxxxxxxxxxxxx", "expires_at"=>1345640145, "expires"=>true}
@liluo
liluo / gist:4015981
Created November 5, 2012 08:17
去除豆瓣导航黑条背景
var navBgc = $($('.nav-wrap')[0].parentNode).css('background-color');
$('#db-global-nav').css('background', navBgc);
$('#db-global-nav ul li a').css('color', '#566D5E');
$('#db-global-nav ul li.on a').css({'color': '#219A44', 'font-weight': 800});
$('#db-global-nav .bd').css({'width': 960, 'margin': 'auto'});
@liluo
liluo / gist:4176272
Created November 30, 2012 15:02
Douban API v2 上传图片 length mismatch
class Faraday::Parts::FilePart
def initialize(boundary, name, io)
file_length = io.respond_to?(:length) ? io.length : File.size(io.local_path)
@head = build_head(boundary, name, io.original_filename, io.content_type, file_length,
io.respond_to?(:opts) ? io.opts : {})
@length = @head.length + file_length
@io = CompositeReadIO.new(StringIO.new(@head), io, StringIO.new("\r\n"))
end
end
@liluo
liluo / ghfmd.rb
Created December 18, 2012 07:51 — forked from capnslipp/ghfmd.rb
test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test
#!/usr/bin/env ruby
# ^ 1.8.x or 1.9, folks!
require 'rubygems'
require File.expand_path('./md_izer', File.dirname(__FILE__))
render_options = {
:fenced_code_blocks => true,
:autolink => true,
:space_after_headers => true
@liluo
liluo / readme.md
Last active December 10, 2015 01:48
Git Internals(for gist)

init

mkdir proj
cd proj
git init

config

git config user.name 'username'