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

Keybase proof

I hereby claim:

  • I am shanewholloway on github.
  • I am shanewholloway (https://keybase.io/shanewholloway) on keybase.
  • I have a public key ASALlQzEk_Vxarp8quh4XDhlOBCO9NXZrifkY9BwvJ8v7wo

To claim this, I am signing this object:

Keybase proof

I hereby claim:

  • I am shanewholloway on github.
  • I am rs_shane (https://keybase.io/rs_shane) on keybase.
  • I have a public key ASBsTru3vXFK9qSaEUSKQf90HtU5s1RHMAePC-xxM79zCwo

To claim this, I am signing this object:

@shanewholloway
shanewholloway / tiny_load.js
Created August 29, 2018 21:48
Tiny dynamic script resource loader
const tiny_load = src =>
new Promise((onload, onerror) =>
document.head.appendChild(
Object.assign(
document.createElement('script'),
{src, onload, onerror},
src.startsWith('http')
? {crossorigin: true}
: null ) ))
export default asWorkerFunction
export asWorkerFunction
export asBlobURLFunction
function asWorkerFunction(func) {
return new Worker(asBlobURLFunction(func))
}
function asBlobURLFunction(func) {
const rx_src = /(^.*=>|{)\s*([^]*?)(}\s*)?$/
@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)
}
@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 / 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 / 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 / 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 / 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`)
}