Skip to content

Instantly share code, notes, and snippets.

View kaizhu256's full-sized avatar

kai zhu kaizhu256

View GitHub Profile
@wang-bin
wang-bin / base64_buffer
Created November 6, 2013 07:36
js base64 to ArrayBuffer
decode64: function decodeBase64(en) {
var de = new Uint8Array(en.length); //3/4
var u = 0, q = '', x = '', c;
var map64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
for (var r=0; c=en[x++]; ~c&&(u=q%4?u*64+c:c,q++%4)?de[r++]=(255&u>>(-2*q&6)):0)
c = map64.indexOf(c);
var sub = de.subarray||de.subset||de.slice;
return sub.call(de, 0, r);
},
@tmcw
tmcw / README.md
Last active February 18, 2025 21:13 — forked from anonymous/README.md
Jenks Natural Breaks with simple-statistics and d3
@kaizhu256
kaizhu256 / gist:4511667
Last active December 10, 2015 23:48
nodejs - asynchronously, recursively delete directories and files in under 100 lines of code
/*jslint bitwise: true, indent: 2, nomen: true, regexp: true, stupid: true*/
(function () {
'use strict';
exports.requireFs = require('fs');
function FsRemoveR() {
}
FsRemoveR.prototype.callbackDefault = function (err) {
@kaizhu256
kaizhu256 / gist:4482049
Last active December 10, 2015 19:29
javascript - json stringify circular objects in 50 lines of code this code recursively traverses a json array / object. it will stringify all circular objects it encounters for first time and cache their references. that way it can avoid them again in the future.
/*jslint indent: 2, nomen: true, regexp: true, stupid: true*/
(function () {
'use strict';
var circularObject, exports = {};
exports.jsStringifyCircular = function (oo, arr) {
//// stringify circular objects
var ii, kk, out, vv;
arr = arr || [];