Skip to content

Instantly share code, notes, and snippets.

View alsotang's full-sized avatar

alsotang alsotang

View GitHub Profile
@alsotang
alsotang / euler14.rb
Created October 24, 2012 15:42
euler14
collatz = Hash.new do |h, k|
if k == 1
1
elsif k.even?
h[k] = h[k/2]+1
else
h[k] = h[3*k+1] + 1
end
end
@alsotang
alsotang / cipher.py
Created September 26, 2012 18:44
一个简单的AES加密库
from Crypto.Cipher import AES
import os
BLOCK_SIZE = AES.block_size
key = os.urandom(BLOCK_SIZE)
cipher = AES.new(key)
def pad(data):
@alsotang
alsotang / zlib.py
Created September 26, 2012 18:35
测试zlib的压缩效率
import zlib
import base64
filename = '1.jpg'
with open(filename, 'rb') as f:
data = f.read()
print len(data)
bdata = base64.encodestring(data)
print len(bdata)
zdata = zlib.compress(bdata)
@alsotang
alsotang / bind.js
Created September 18, 2012 19:55
js bind的一个简单示例
var obj1 = {
name: 'alsotang',
method: function() {
console.log(this.name);
}
};
var obj2 = {
name: 'freewind'
};
package main
import "fmt"
func main() {
v := []int{1,2,3,4,5,6,7,8}
mv := new(MeanValue)
/*mvFunc := mv.exec()*/
nmv := new(MeanValue)
nmvFunc := nmv.exec()
@alsotang
alsotang / 1.ruby
Created October 24, 2011 06:37 — forked from ohlol/gist:1308482
#In Ruby:
class Foo
attr_accessor :bar
end
f = Foo.new
f.bar = 'baz'
f.bar # => 'baz'