Skip to content

Instantly share code, notes, and snippets.

Avatar

月影 akira-cn

View GitHub Profile
View multiply8
let multiply8 = (num) => num << 3;
multiply8(7); //We got 56
View Benchmark of string concat in node.js
var Benchmark = require('benchmark');
var suite = new Benchmark.Suite;
var str_long = (new Array(50000)).join('0');
var str_mid = (new Array(500)).join('0');
var str_short = (new Array(5)).join('0');
suite.add('concat#longstr', function() {
str_long + str_long;
@akira-cn
akira-cn / hook.js
Created Oct 15, 2015
wechat hook for think.js 2.0
View hook.js
/**
* this file will be loaded before server started
* you can register app hook
*/
const WEIXIN_APPID = appid;
const WEIXIN_APPSECRET = appsecret;
const WEIXIN_TOKEN = token;
const WEIXIN_AESKEY = aeskey;
think.middleware('parse_wechat', http => {
View jsbin..html
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
</body>
</html>
@akira-cn
akira-cn / gist:7675171
Last active Dec 29, 2015
1006题解法
View gist:7675171
function solve(modules){
function getBranch(node, tree){
var ret = [];
var current = node;
do{
ret.push(current);
}while(current = tree[current])
return ret;
}
View gist:7499361
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
from xmlrpclib import ServerProxy
def main():
url = sys.argv[1].strip()
if not url or not url.startswith('http://'):
print 'please enter a url!'
View gist:7226489
function solve(jA, jB, target){
var cA = [jA, 0],
cB = [jB, 0];
var stateMap = {'0,0': true}, ops = [];
var solved = false;
//the state checked
function checked(){
var st = [cA[1],cB[1]].join();
View gist:7166271
function convert(from, to){
if(from.split('').sort().join('') != to.split('').sort().join('')){
return [];
}
var res = [];
function proceed(stack, pos, prefix, ops){
//找到一个解
if(prefix === to){
View gist:7152589
function m(map){
var max = 0, size = map.length;
return proceed(0); //回溯算法
function proceed(pos){
var max = 0; //放置城堡数
for(var i = pos; i < size * size; i++){
var y = i % size;
@akira-cn
akira-cn / gist:6317012
Last active Dec 21, 2015
ES 6 实现PHP的魔术方法 —— 可以在比较新的Firefox下试试~
View gist:6317012
<meta charset="utf-8">
<script>
function MagicObject() {
return new Proxy(this, {
get: function (target, name) {
if (name in target) {
return target[name];
} else {
You can’t perform that action at this time.