Skip to content

Instantly share code, notes, and snippets.

View shanewholloway's full-sized avatar
🗜️
I may be slow to respond.

Shane Holloway shanewholloway

🗜️
I may be slow to respond.
View GitHub Profile
@shanewholloway
shanewholloway / README.md
Last active September 14, 2017 15:40
Repro problem using React next (16-rc.2) with Rollup 0.49.3

Working with React next at 16.0.0-rc.2 using the development/non-production path, the commonjs module 'object-assign' does not result in a usable function.

Versions

  • Mac OS X 10.12.6 using node 8.4 and 8.5

Instructions

  1. $ npm install && npm run build
@shanewholloway
shanewholloway / promiseQueue.js
Created October 31, 2017 16:21
Promise Queue pattern as alternative for setImmediate/nextTick
function promiseQueue(nextPromise=() => Promise.resolve()) {
let tip = null
return function () {
if (null === tip) {
tip = nextPromise()
tip.then(clear_tip) }
return tip
}
function clear_tip() { tip = null }
}
@shanewholloway
shanewholloway / join_jobs.sh
Created December 16, 2017 23:09
POSIX join jobs "reduce"
#!/bin/bash
FAIL=0
for job_pid in `jobs -p`; do
echo "Joining job $job_pid"
wait $job_pid || let "FAIL+=1"
done
if [[ "$FAIL" != "0" ]]; then
echo Failed join processes $FAIL
exit 1
fi
@shanewholloway
shanewholloway / show_memory.js
Created December 28, 2017 16:06
NodeJS snippet for periodically showing memory use over time
function show_memory(interval=1000) {
setTimeout(show_memory, interval).unref()
let out = []
const mem = process.memoryUsage()
out.push('MEM')
for (const [k,v] of Object.entries(mem)) {
out.push(`${k}: ${(v / 1.0e6).toFixed(1)} MB`)
}
@shanewholloway
shanewholloway / arrayBufferBase64.js
Last active February 13, 2018 05:40 — forked from jonleighton/base64ArrayBuffer.js
Encode an ArrayBuffer as a base64 string
const base64_encode_std = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
const base64_encode_url = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_'
const base64_decode = [{}, {}, {}, {}]
{
const add = (k, i) => {
base64_decode[0][k] = i << 0
base64_decode[1][k] = i << 6
base64_decode[2][k] = i << 12
base64_decode[3][k] = i << 18
}
@shanewholloway
shanewholloway / browser_base64.js
Last active June 19, 2018 22:49
ArrayBuffer to Base64 packing and unpacking
const _fromCharCode = String.fromCharCode
export function pack_base64(arr) {
let res=''
const u8 = new Uint8Array(arr.buffer || arr)
const len = u8.byteLength
for (let i=0; i<len; i++)
res += _fromCharCode(u8[i])
return window.btoa(res)
}
@shanewholloway
shanewholloway / example.js
Created February 16, 2018 19:06
ES3 Inspect tool
// to depth-first inspect all attributes of an object
inspect(obj)
// or, to see all attributes on the entire prototype chain
inspect.chain(obj)
@shanewholloway
shanewholloway / README.md
Created March 29, 2018 17:39
Rollup 0.57.1 and "lodash-es" tree-shaking issue

Using rollup 0.57.1 with "lodash-es" package does not treeshake properly.

@shanewholloway
shanewholloway / browser_util.js
Created June 20, 2018 16:18
WebCrypto get compressed ECDH public key that is compatible with Node's ec.getPublicKey(null, 'compressed')
const _fromCharCode = String.fromCharCode
export function pack_base64(arr) {
let res=''
const u8 = new Uint8Array(arr.buffer || arr)
const len = u8.byteLength
for (let i=0; i<len; i++)
res += _fromCharCode(u8[i])
return window.btoa(res)
}
export default asWorkerFunction
export asWorkerFunction
export asBlobURLFunction
function asWorkerFunction(func) {
return new Worker(asBlobURLFunction(func))
}
function asBlobURLFunction(func) {
const rx_src = /(^.*=>|{)\s*([^]*?)(}\s*)?$/