Skip to content

Instantly share code, notes, and snippets.

Avatar

kai zhu kaizhu256

View GitHub Profile
@kaizhu256
kaizhu256 / jsonRowListFromcsv.js
Created Dec 21, 2020
convert json list-of-list or list-of-dict to csv
View jsonRowListFromcsv.js
function jsonRowListFromCsv({
csv
}) {
/*
* this function will convert <csv>-text to json list-of-list
*/
/*
https://tools.ietf.org/html/rfc4180#section-2
Definition of the CSV Format
While there are various specifications and implementations for the
@kaizhu256
kaizhu256 / repl_start.js
Created Dec 3, 2020
nodejs repl with ability to run shell commands in prompt
View repl_start.js
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 Nov 11, 2020
this zero-dependency nodejs-script demonstrates how to programmatically script chrome-browser to do tasks using chrome-devtools-protocol commands over websocket
View chrome-devtools-client.example.js
/*
* 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
*/
@kaizhu256
kaizhu256 / rfc7516.js
Last active Jun 5, 2020
Example JWE Using AES Key Wrap and AES_128_CBC_HMAC_SHA_256
View rfc7516.js
// 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;
View .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 / webCrawl.js
Last active May 26, 2020
nodejs - recursively download github api-documentation
View webCrawl.js
/*
* 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:
View a00.html
<script src="a00.js"></script>
View logo.html
<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 Feb 20, 2020
javascript binary-min-heap
View heap.js
/* 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 Sep 8, 2019
this function will convert quicktime.mov $1 to animated gif $2
View shScreencastToGif.sh
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"
)}