Skip to content

Instantly share code, notes, and snippets.

View dexbol's full-sized avatar

Kai Zhang dexbol

View GitHub Profile
@dexbol
dexbol / crude-immer.js
Last active February 14, 2023 05:01
immer.js 实现方式简介
#!/usr/bin/env node
/**
* 此函数只为说明 immer.js 的基本实现方式(基于 ES6 Proxy 非 ES5),因此尽量保持简陋,
* 并且只支持普通对象,而且不能通过返回值的方式生成新对象,
* 也不能增加新属性。
* 同时,也不支持 Array Map Set 等其他数据类型。
*/
// 存储 revoke 函数,用于释放 Proxy 对象资源。
@dexbol
dexbol / jMarquee-example.html
Last active November 3, 2017 09:40
jMarquee - jquery plugin can select polygon marquee in canvas
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script type="text/javascript" src="http://vj0.6rooms.com/csjs/lib/tools/jquery/jquery-1.8.0.js"></script>
<script type="text/javascript" src="jMarquee.js"></script>
<style type="text/css">
canvas {
float: left;
}
var reducerShape = {};
var makeFinalStateByReducerShape = function(shape, path, result, state,
action) {
if (typeof shape === 'function') {
var obj = result;
var value = state;
for (var i = 0; i < path.length - 1; i++) {
var key = path[i];
import os
import subprocess
import logging
import argparse
''' Make a python script as daemon.
Usage:
python daemon.py start|stop|restart
You can use this for some scenes such as subversion hooks or init.d
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>html page</title>
</head>
<body>
<form>
userfile: <input type="file" /> <br />
<progress max="100" value="0"></progress> <br />
@dexbol
dexbol / gist:5324980
Created April 6, 2013 05:28
Cross document message
Boom.add('xstream', function(C) {
var TICKET = 'any random string 1';
var PING = 'any random string 2';
var PING_BACK = 'any random string 3';
var host = location.protocol + '//' + location.host +
(location.port ? ':' + location.port : '');
var $ = jQuery;
var win = window;
@dexbol
dexbol / sync.py
Last active December 14, 2015 14:59
# coding=utf-8
''' svn post-commit hook. checkout the repository and synchronizate to the
working copy. you can add some feature that you demand, e.g. after all, restart
your web server persuades the code changes to take effect.
'''
import os
import logging
import sys
@dexbol
dexbol / gist:3760062
Created September 21, 2012 06:45
add commas to integer
function addComma(num) {
num = String(num);
var len = num.length;
var remainder = len % 3;
var h = num.substring(0, remainder);
var str = num.substring(remainder);
var i = 0;
var flag = str.length / 3;
var result = h ? [h] : [];
for (; i <f lag; i ++) {