This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <sys/mman.h> | |
struct env { | |
int x; | |
}; | |
struct __attribute__((packed)) thunk { | |
unsigned char push; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <assert.h> | |
#define CMP(a, b) (a > b ? 1 : (a == b ? 0 : -1)) | |
int bsearch(const int arr[], int n, int k) | |
{ | |
int l = 0, m, cmp; | |
assert(n > 0); | |
while (l < n) { | |
m = (l + n) / 2; | |
cmp = CMP(k, arr[m]); | |
if (cmp == 0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdint.h> | |
#include <stddef.h> | |
// 0-9999对应的字符串 | |
static const char perfmtstr[] = /* 40000 字节 */ | |
"0000000100020003000400050006000700080009001000110012001300140015001600170018001900200021002200230024" | |
"0025002600270028002900300031003200330034003500360037003800390040004100420043004400450046004700480049" | |
"0050005100520053005400550056005700580059006000610062006300640065006600670068006900700071007200730074" | |
"0075007600770078007900800081008200830084008500860087008800890090009100920093009400950096009700980099" | |
"0100010101020103010401050106010701080109011001110112011301140115011601170118011901200121012201230124" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <stdint.h> | |
/** | |
* Jaro–Winkler distance | |
* http://en.wikipedia.org/wiki/Jaro%E2%80%93Winkler_distance | |
* | |
* 比较两个字符串的相似程度 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* An algorithm for solving the following (classic) hard interview problem: | |
* | |
* "You are given an array of integers of length n, where each element ranges | |
* from 0 to n - 2, inclusive. Prove that at least one duplicate element must | |
* exist, and give an O(n)-time, O(1)-space algorithm for finding some | |
* duplicated element. You must not modify the array elements during this | |
* process." | |
* | |
* This problem (reportedly) took CS legend Don Knuth twenty-four hours to solve |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 异步加载js, 支持依赖关系 | |
* Author: zhiyongLiu <[email protected]> | |
* | |
* 使用方法: LazyLoader().load('a.js').load('b.js').wait().load('c.js') | |
* .next() | |
* .load('d.js').load('e.js').wait().load('f.js'); | |
* c.js 依赖与a.js,b.js, f.js 依赖于d.js,e.js; 这两组js之间没有依赖关系; | |
* c.js将在a.js和b.js之后加载, f.js将在d.js,e.js之后加载; 两组js加载同时进行; | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*! Copyright (c) 2011 Brandon Aaron (http://brandonaaron.net) | |
* Licensed under the MIT License (LICENSE.txt). | |
* | |
* Thanks to: http://adomas.org/javascript-mouse-wheel/ for some pointers. | |
* Thanks to: Mathias Bank(http://www.mathias-bank.de) for a scope bug fix. | |
* Thanks to: Seamus Leahy for adding deltaX and deltaY | |
* | |
* Version: 3.0.6 | |
* | |
* Requires: 1.2.2+ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* zhiyongliu <[email protected]> | |
* | |
* 查找一个字符串的所有的重复字串 | |
* 算法的核心思想是两个相同字符串的前缀一定相同, 在查找过程中先查找短的重复字串, | |
* 然后利用短的字串构建次短的重复字串, 直到字符串本身的长度或前一个结果为空集 | |
* 算法的复杂度为O(n) + O(m), n为字符串长度, m为重复字串的数目 | |
*/ | |
function findRepeatedSubstring(str) | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* zhiyongliu <[email protected]> | |
* | |
* conf.getData(str, callback) 用来获取数据, 获取的数据通过回调传入, callback传入的参数要是一个数组 | |
* conf.createChild(obj, inputvalue) 用来生成补全的节点, obj为回调callback的数组的某一项, | |
* 在数组为空时obj可能为null,生成出错信息, inputval时当前的input的输入值; | |
* 返回一个dom对象,将会作为一个子节点插入到rootid节点中; | |
* 函数根据需要可能要设置mouseover/mouserout/click的事件处理函数 | |
* conf.toSting(obj) 返回obj对应的字符串, obj为回调callback的数组的某一项 | |
* conf.enterAction(inputvaule) input的回车时的动作可选 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* js前端的模版 | |
* zhiyongliu <[email protected]> | |
* | |
* 支持两种指令: <!-- -->, <!--{}--> | |
* 1. <!-- --> js的控制结构的代码;不包含输出 | |
* 2. <!--{}--> 输出的内容, 结果为string或可转换为string的表达式 | |
*/ | |
var MyTemplate = MyTemplate || function(id) { | |
var analyze = function (str) { |
NewerOlder