Skip to content

Instantly share code, notes, and snippets.

View kaizhu256's full-sized avatar

kai zhu kaizhu256

View GitHub Profile
@kaizhu256
kaizhu256 / repl_start.js
Created December 3, 2020 08:35
nodejs repl with ability to run shell commands in prompt
function replStart () {
/*
* this function will start repl-debugger
*/
let that;
if (globalThis.utility2_repl1) {
return;
}
// start repl
that = require("repl").start({
@kaizhu256
kaizhu256 / chrome-devtools-client.example.js
Last active January 17, 2024 05:44
this zero-dependency nodejs-script demonstrates how to programmatically script chrome-browser to do tasks using chrome-devtools-protocol commands over websocket
/*
* chrome-devtools-client-example.js
*
* this zero-dependency nodejs-script demonstrates how to programmatically
* script chrome-browser to do tasks using chrome-devtools-protocol commands
* over websocket
*
* tldr - jump down to section "quickstart-example" to see an example task
*
* Chrome DevTools Protocol Documentation:
@kaizhu256
kaizhu256 / rfc7516.js
Last active June 5, 2020 01:34
Example JWE Using AES Key Wrap and AES_128_CBC_HMAC_SHA_256
// https://tools.ietf.org/html/rfc7516#appendix-A.3
(async function () {
"use strict";
let aad;
let aal;
let assertJsonEqual;
let base64urlFromBuffer;
let base64urlToBuffer;
let cek;
let ciphertext;
# ~/.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 / webCrawl.js
Last active May 26, 2020 22:06
nodejs - recursively download github api-documentation
/*
* webCrawl.js
* this program will recursively "wget" api-documentation
* from https://developer.github.com/v3/index.html to 2-level-depth
*
* example usage:
* $ node webCrawl.js eager # eager mkdirSync before writeFile
* $ node webCrawl.js lazy # lazy mkdirSync after writeFile failure
*
* example output:
<script src="a00.js"></script>
<link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro&display=swap" rel="stylesheet">
<style>
div {
font-family: 'Source Sans Pro';
font-size: 80px;
font-weight: 700;
height: 132px;
line-height: 44.3636px;
background: #FFE70B;
width: 200px;
@kaizhu256
kaizhu256 / heap.js
Last active February 20, 2020 14:16
javascript binary-min-heap
/* jslint utility2:true */
(function () {
/*
* this function will provide a binary-min-heap in javascript
*/
"use strict";
let heapCreate;
let heapDecreaseKey;
let heapDelete;
let heapHeapify;
@kaizhu256
kaizhu256 / shScreencastToGif.sh
Created September 8, 2019 06:30
this function will convert quicktime.mov $1 to animated gif $2
shScreencastToGif () {(set -e
# this function will convert quicktime.mov $1 to animated gif $2
# https://gist.github.com/dergachev/4627207
# https://gist.github.com/baumandm/1dba6a055356d183bbf7
ffmpeg -y -i "$1" -vf fps=10,palettegen /tmp/palette.png
ffmpeg -i "$1" -i /tmp/palette.png -filter_complex "fps=10,paletteuse" "$2"
)}
@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