Skip to content

Instantly share code, notes, and snippets.

function defineReactive(option) {
var o = {};
var data = option.data;
var funcs = {};
var callstacks = o.callstacks = [];
var obs = o.obs = {};
var notify = function (key) {
@LelouchHe
LelouchHe / mflags.lua
Created October 27, 2014 17:07
own implementation of gflags-like in lua
-- 现在的local function的语法可以支持以下语法了,不用纠结
-- pil3的说法看来是不对的.嗯,明显要出pil4的节奏
local fact = function (n)
if n == 1 then
return 1
end
return n * fact(n - 1)
end
@LelouchHe
LelouchHe / mu.lua
Created October 25, 2014 15:11
own implementation of underscore.lua
function seq(n)
return coroutine.wrap(function()
for i = 1, n do
coroutine.yield(i)
end
end)
end
function add4(a, b, c, d)
@LelouchHe
LelouchHe / Makefile
Last active August 29, 2015 14:00
通用的gmock的Makefile文件
# general Makefile for gmock/gtest
# by LelouchHe@gmail.com
###############################################
###############################################
# configuration
# set up your own config of test environment
###############################################
###############################################
@LelouchHe
LelouchHe / float.cpp
Created March 4, 2014 18:06
float内部表示的实验
#include <stdio.h>
#include <stdint.h>
#define IS_SET(n, pos) ((n) & (1 << pos))
union float_t {
float f;
uint32_t i;
struct {
uint32_t m : 23;
@LelouchHe
LelouchHe / permutation.cpp
Created March 4, 2014 04:09
类似next/prev_permutation的实现
bool next_permutation(int num[], size_t n) {
if (n <= 1) {
return false;
}
size_t top = n - 1;
while (top > 0 && num[top - 1] >= num[top]) {
top--;
}
@LelouchHe
LelouchHe / kmp.cpp
Last active August 29, 2015 13:56
kmp算法
#define MAX_D_LEN 100
static void build_next(const char *str, int len, int next[]) {
assert(str != NULL);
assert(len > 0);
assert(next != NULL);
next[0] = -1;
int i = 0;
@LelouchHe
LelouchHe / m_strtol.c
Created February 23, 2014 04:42
将8/10/16进制转为整数,自行判断数据格式,语法兼容C
/* 下标: c & 0x7F */
static const int char_map[] = {
-1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1,
0, 1, 2, 3, 4, 5, 6, 7,
8, 9, -1, -1, -1, -1, -1, -1,
@LelouchHe
LelouchHe / list.cpp
Last active August 29, 2015 13:56
list相关代码
struct node_t {
node_t *next;
};
// x -> y -> z x -> y -> z -> a
// | |
// mid mid
node_t *find_mid(node_t *head) {
if (head == NULL) {
return NULL;
@LelouchHe
LelouchHe / libjson.patch
Last active August 29, 2015 13:56
libjson 7.6.1 utf8 bug修复的patch
Common subdirectories: libjson_7.6.1/_internal/Source/JSONDefs and libjson_7.6.1.mine/_internal/Source/JSONDefs
diff -uN libjson_7.6.1/_internal/Source/JSONWorker.cpp libjson_7.6.1.mine/_internal/Source/JSONWorker.cpp
--- libjson_7.6.1/_internal/Source/JSONWorker.cpp 2012-05-30 17:14:36.000000000 +0800
+++ libjson_7.6.1.mine/_internal/Source/JSONWorker.cpp 2013-04-19 07:05:06.000000000 +0800
@@ -275,12 +275,12 @@
void JSONWorker::UTF(const json_char * & pos, json_string & result, const json_char * const end) json_nothrow {
JSON_ASSERT_SAFE(((long)end - (long)pos) > 4, JSON_TEXT("UTF will go out of bounds"), return;);
- json_uchar first = UTF8(pos, end);
+ json_uchar first = UTF8(pos, result, end);