Skip to content

Instantly share code, notes, and snippets.

const compose = (...args) => initData => args.reduceRight((value,item) => item(value), initData);
const memoize = function(f) {
const cache = {};
return (...arg) => {
const arg_str = JSON.stringify(arg);
cache[arg_str] = cache[arg_str] || f(...arg);
return cache[arg_str];
};
};
@magicapple
magicapple / quicksort
Created May 14, 2018 01:13 — forked from ideawu/quicksort
快速排序QuickSort算法JavaScript实现, 包括 Hoare 和 Lomuto 版本的实现,以及网友实现版本的对比
<html>
<body>
<script>
// @author: ideawu
// @link: http://www.ideawu.net/blog/archives/1021.html
var swap_count = 0;
var cmp_count = 0;
// https://gist.github.com/wintercn/c30464ed3732ee839c3eeed316d73253
function wintercn_qsort(arr, start, end){
@magicapple
magicapple / fn
Created July 15, 2015 06:03
transform a path array to a tree.
var arr=["www.ifeng.com/index","news.ifeng.com/index","news.ifeng.com/mainland/index","ent.ifeng.com","news.ifeng.com/mil/index","news.ifeng.com/mil/","news.ifeng.com/mil/special/fzlfm/index"];
var item;
var result = [];
var current;
var path;
var hasIt;
var index;
current = result;
for (var i = 0, iLen = arr.length; i < iLen; i++) {
// method of getCookie
function getCookie( name ) {
var parts = document.cookie.split(name + "=");
if (parts.length == 2) return parts.pop().split(";").shift();
}
function expireCookie( cName ) {
document.cookie =
encodeURIComponent( cName ) +
"=deleted; expires=" +
@magicapple
magicapple / h5g
Created July 19, 2012 00:35 — forked from wintercn/h5g
HTML5 Canvas Game Template
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8" />
<!--允许全屏-->
<meta content="yes" name="apple-mobile-web-app-capable"/>
<meta content="yes" name="apple-touch-fullscreen"/>
<!--禁止电话号码和邮箱识别-->
@magicapple
magicapple / wawammseg.py
Created June 30, 2012 13:22 — forked from onlytiancai/wawammseg.py
写了一个简单的支持中文的正向最大匹配的机械分词,其它不用解释了,就几十行代码
# -*- coding:utf-8 -*-
'写了一个简单的支持中文的正向最大匹配的机械分词,其它不用解释了,就几十行代码'
'搜狗词库下载地址:http://vdisk.weibo.com/s/7RlE5'
import string
__dict = {}
def load_dict(dict_file='words.dic'):
'加载词库,把词库加载成一个key为首字符,value为相关词的列表的字典'
<!DOCTYPE html>
<html>
<head>
<title>JSON-P Example</title>
<script src="jsonp.js"></script>
</head>
<body>
<h1>A simple JSON-P example</h1>
<p>This is a Google Image Search.</p>
<input id="q" />