Skip to content

Instantly share code, notes, and snippets.

View Gerhut's full-sized avatar
😷
Working from home

George Cheng Gerhut

😷
Working from home
View GitHub Profile
@Gerhut
Gerhut / concat.mhtml.py
Last active December 21, 2015 06:08
Concaterate Mhtml Files
import sys
fout = open(sys.argv[0] + '.mht', 'w')
files = sorted(sys.argv[1:])
first = True
html_content = ''
attachment_contents = {}
for f in files:
data = open(f, 'r').read()
@Gerhut
Gerhut / methodBind.py
Created August 19, 2013 09:41
Instance method & Class method.
class Cls(object):
def method(self):
return self.__hash__()
obj = Cls()
method = Cls.method
boundMethod = obj.method
print obj.method()
print method(obj)
@Gerhut
Gerhut / aSimpleModulesManagement.js
Last active December 21, 2015 17:08
Simple Modules Management
// (function () {
var moduleNames = ['canvas', 'layout']
, modules = {}
function loadModule() {
var currentModuleName = moduleNames.shift()
, scriptElement = document.createElement('script')
function mod(name) {
@Gerhut
Gerhut / problem.markdown
Last active December 23, 2015 01:28
现有一列随机的正整数,算他有2^n个吧,然后两两结合生成一个二叉树,节点是上一级两个数的和,合成的cost是上一级两个数的乘积。 而整个树的cost由总cost最高的那个branch决定,求用什么方法排列这一列数使生成的树cost最低。

现有一列随机的正整数,算他有2^n个吧,然后两两结合生成一个二叉树,节点是上一级两个数的和,合成的cost是上一级两个数的乘积。 而整个树的cost由总cost最高的那个branch决定,求用什么方法排列这一列数使生成的树cost最低。

例如,1,2,3,4这四个数

二叉树

C=21+12=33

@Gerhut
Gerhut / SimpleList.java
Created September 22, 2013 12:27
Java简单实现MapReduce列表
package net.gerhut.functionaljava;
import java.lang.reflect.Array;
import java.util.Arrays;
public class SimpleList<E> {
public static interface SingleArgFunction<E> {
E apply(E arg);
}
@Gerhut
Gerhut / easing.js
Last active December 26, 2015 02:28
Simple Easing Method.
/**
* Easing Function f(t) where t, f(t) <- [0, 1]
* return an Easing Factory.
*/
function easing(f) {
/**
* x = f(t) where x <- [x0, x1], t <- [0, t1]
* return an Easing Instance.
*/
return function(x0, x1, t1) { // x = f(t), x <-[x0, x1]

CodeStar之《前端特工》糙解

第一章

提交中缺一个timestamp的值,补上即可。

document.getElementsByName('timestamp')[0].value = new Date().getTime();
@Gerhut
Gerhut / connect_middlewares_description_cn
Last active December 26, 2015 20:59
Connect.js中间件大意。
logger 自定义格式、输出文件的日志
csrf 跨站请求保护,需求session
compress gzip压缩
basicAuth 简单http验证
json application/json请求体解析到req.body
urlencoded application/x-www-form-urlencoded请求体解析到req.body
multipart multipart/form-data请求体解析到req.body
bodyParser = json + urlencoded + mutipart
timeout 请求超时
cookieParser cookie解析到req.cookies
{
"shell_cmd": "gcc ${file_name} -o ${file_base_name} && ${file_base_name}",
"working_dir": "${file_path}",
"selector": "source.c",
"encoding": "cp936"
}
  1. Basic Auth,加一行HTTP头:Authorization: Basic base64([accountKey]:[accountKey])
  2. 参数需要是string的必须是用单引号' %27 after encode"括起来,双引号不知道。