Skip to content

Instantly share code, notes, and snippets.

View kaizhu256's full-sized avatar

kai zhu kaizhu256

View GitHub Profile
@kaizhu256
kaizhu256 / semverCompare.js
Created September 7, 2019 17:18
this gist will provide standalone funtion `semverCompare` and accompanying test
/*jslint devel*/
function semverCompare(aa, bb) {
/*
* this function will compare semver versions aa ? bb and return
* -1 if aa < bb
* 0 if aa = bb
* 1 if aa > bb
* https://semver.org/#spec-item-11
* example usage:
semverCompare("2.2.2", "10.2.2"); // -1
@kaizhu256
kaizhu256 / rmrf.js
Created August 31, 2019 20:54
one-liner to rm -rf in nodejs
function fsRmrSync (dir) {
/*
* this function will sync "rm -rf" <dir>
*/
require("child_process").spawnSync("rm", [
"-rf", dir
], {
stdio: [
"ignore", 1, 2
]
{
"openapi" : "3.0.1",
"info" : {
"title" : "defaultTitle",
"description" : "defaultDescription",
"version" : "0.1"
},
"servers" : [ {
"url" : "https://api.nasa.gov"
} ],
@kaizhu256
kaizhu256 / post.txt
Created March 9, 2019 11:39
wd mycloudex2ultra fan control
https://community.wd.com/t/question-regarding-the-fan-used-by-wd-my-cloud-ex2/98304/150
martin953
1
Aug '17
Hi everybody!
I’m the owner of WD My Cloud Mirror Gen2 8 TB and my drives (2 WD Red’s) were constantly running at around 52º C, so I was among others who were concerned about high operating temperature of WD My Cloud drives.
I’ve read this thread top to bottom and accumulated suitable solution (at least for me it is). Basically, My Cloud OS already have temperature controlling program (daemon), we only need to make it do it’s job somewhat more passionate. The temperature thresholds are stored in four .xml files in /etc/wd/ folder:
@kaizhu256
kaizhu256 / gameboy.txt
Last active October 25, 2018 08:15
gameboy code
advance wars - co always eagle
0000317D 000A
1006C9E4 0007
3201ABB9 0008
advance wars - max power p1
0000317D 000A
1006C9E4 0007
8201ABBC FFFF
@kaizhu256
kaizhu256 / .bashrc
Created August 22, 2018 14:22
default ubuntu .bashrc
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
@kaizhu256
kaizhu256 / crypto.js
Last active July 17, 2019 09:06
webcrypto example
var local;
local = {};
local.cryptoAesDecrypt = function (key, data, onError) {
/*
* this function will aes-256-cbc decrypt Uint8Array data with the Uint8Array key
* example usage:
key = new Uint8Array(32);
local.cryptoAesEncrypt(key, new Uint8Array([1,2,3]), function (error, data) {
console.assert(!error, error);
local.cryptoAesDecrypt(key, data, console.log);
@kaizhu256
kaizhu256 / .travis.yml
Created May 1, 2018 06:31
travis override $NODE_VERSION
before_install:
# override $NODE_VERSION
- printf "$NODE_VERSION\n" && if (printf "$CI_COMMIT_MESSAGE" | grep -qE "\bNODE_VERSION="); then nvm install "$(printf "$CI_COMMIT_MESSAGE" | sed -e "s/.*\bNODE_VERSION=//" -e "s/ .*//")" && printf "$NODE_VERSION\n" && node --version && npm --version; fi
@kaizhu256
kaizhu256 / example.js
Last active April 29, 2018 15:06
benchmark http-request performance for recursive-callback vs. promise vs. async/await
/*
* example.js
*
* this zero-dependency example will demo a simple (60 sloc), high-performance express-middleware
* that can broadcast a single fs.readFile() operation to multiple server-requests
*
*
*
* example usage:
* $ REQUESTS_PER_TICK=10 node example.js
@kaizhu256
kaizhu256 / example.js
Created April 25, 2018 12:42
this zero-dependency example will demo a simple (60 sloc), high-performance express-middleware that can broadcast a single fs.readFile() operation to multiple server-requests
/*
* example.js
*
* this zero-dependency example will demo a simple (60 sloc), high-performance express-middleware
* that can broadcast a single fs.readFile() operation to multiple server-requests
*
*
*
* example usage:
* $ node example.js