Skip to content

Instantly share code, notes, and snippets.

View alsotang's full-sized avatar

alsotang alsotang

View GitHub Profile
@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'
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 / bind.js
Created September 18, 2012 19:55
js bind的一个简单示例
var obj1 = {
name: 'alsotang',
method: function() {
console.log(this.name);
}
};
var obj2 = {
name: 'freewind'
};
@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 / 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 / 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 / hello.md
Last active December 17, 2015 10:49
just a markdown gist test

Hello World

add some words.

more words here...

@alsotang
alsotang / gist:7319095
Created November 5, 2013 13:36
男女比例
var _ = require('lodash');
var families = [];
for (var i = 0; i < 100000; i++) {
var family = [];
for (var j = 0; j < 3; j++ ) {
// 0 是女孩 1 是男孩
var gender = Math.random() >= 0.5 ? 1 : 0;
family.push(gender);
@alsotang
alsotang / gist:8452415
Created January 16, 2014 09:55
The run time of the three tests are almost the same.
var should = require('should');
var Benchmark = require('benchmark');
var suite = new Benchmark.Suite();
var lambdaLifting = function () {
var x = 10;
function fn() {
return x + 1;
}
@alsotang
alsotang / 1.js
Last active October 15, 2015 07:25
requestIdleCallback 与前端 cpu 运算
var count = 0;
setInterval(function () {
count++;
var el = document.querySelector('.count-number')
el.innerHTML = count;
}, 100)
// add 10k elements to body
setTimeout(function () {
for (var i = 0; i < 10000; i++) {