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 / EventLoop.js
Last active February 19, 2020 19:03 — forked from TooTallNate/cocoa-hello-world2.js
cocoa-hello-world2.js working with TooTallNate/NodObjC pull request #56
/* Cocoa application event loop implementation for NodObjC.
* Code created for https://github.com/TooTallNate/NodObjC/pull/56
* Working as of 2015-Jan-11 on Mac OS 10.10, Node 0.10.35, NodObjC 1.0.0
*
* Copyright (c) 2015, Shane Holloway
*
* Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
@shanewholloway
shanewholloway / json_hashing.js
Created October 25, 2016 23:25
JSON hashing, canonicalization, digests, SHA, MD5
function json_canonical(obj) {
return JSON.stringify(obj, (key, value) => {
if ('object' !== typeof value)
return value // it is a value of some kind
if (value instanceof Array)
return value // Arrays are (already) ordered
// normalize into new object initializing via sorted keys
let result = {}
@shanewholloway
shanewholloway / icos_indexer.js
Created December 13, 2016 05:53
Navigating through Triangle Meshes Implemented as Linear Quadtrees
'use strict'
/*
* Adapted from: https://github.com/rpsirois/icosindexer
* Who aadapted it from: Lee, Michael and Samet, Hanan. (April 2000).
* Navigating through Triangle Meshes Implemented as Linear Quadtrees.
* ACM Transactions on Graphics, Vol. 19, No. 2.
* Retrieved from https://pdfs.semanticscholar.org/a5c8/8b53174405e5ff512ff5ffa8a56df3c8e2df.pdf
*
* Authors:
* - [Robert Sirois](https://github.com/rpsirois)
@shanewholloway
shanewholloway / totp_to_qr_dataurl.js
Last active January 28, 2017 06:07
create image data url from otpauth:// url
const speakeasy = require('speakeasy')
const totp_obj = { label: 'gist-totp-demo', algorithm: 'sha256',
secret: 'some secret string', encoding: 'base64'}
const otp_url = speakeasy.otpauthURL(totp_obj)
const qr_image = require('qr-image')
const png_buffer = qr_image.imageSync(otp_url, {type: 'png'})
const svg = qr_image.imageSync(otp_url, {type: 'svg'})
const svg_buffer = Buffer.from(svg)
@shanewholloway
shanewholloway / 01_rectangle.js
Last active April 4, 2017 13:18
2017-04-04--babel-plugin-offside-js--issues--5
class Rectangle ::
constructor(height, width) ::
this.height = height;
this.width = width;
toString() ::
return `(${this.height} ${this.width})`;
@shanewholloway
shanewholloway / docker-stackfile.yml
Last active August 4, 2022 03:44
Example Docker Stack Deploy with Node/Service/Task values
## docker stack deploy -c docker-stackfile.yml gist_demo
version: "3.8"
services:
playground:
image: node:alpine
hostname: '{{.Task.Name}}'
environment:
SWARM_TASK: '{{.Task.Name}}'
SWARM_PEERS: "tasks.{{.Service.Name}}"
@shanewholloway
shanewholloway / nodeOneLineServer.bash
Created May 2, 2017 14:51
Node one-line demo server
#!/bin/bash
node -e 'require("http").createServer((req,res) => {res.end([[req.method, req.httpVersion, req.url], ["On host:", require("os").hostname()], []].map(l=>l.join(" ")).join("\n"))}).listen(3001, "0.0.0.0", ()=> {})'
@shanewholloway
shanewholloway / promiseSome.js
Last active August 6, 2017 03:16
Promise.some :: A cross between Array.some, Promise.all, and Promise.race
function promiseSome(promises) ::
// a cross between Promise.all and Promise.race
promises = Array.from(promises).filter(e => e)
return new Promise @ resolve => ::
const result = []
result.done = new Promise @ done => ::
let count = promises.length
if 0 === count ::
resolve(result)
done(result)
@shanewholloway
shanewholloway / .dockerignore
Last active September 13, 2017 16:16
Rollup 0.49.3 regression bundling React — works in 0.49.2
node_modules/
*/node_modules/
*/build
*/dist
./yarn.lock
./package-lock.json
@shanewholloway
shanewholloway / bundle.vendor.js
Last active September 13, 2017 02:51
React 16 with Rollup 0.49.2 fails to run in the browser due to unresolved 'object-assign' dependency
(function () {
'use strict';
function createCommonjsModule(fn, module) {
return module = { exports: {} }, fn(module, module.exports), module.exports;
}
/*
object-assign
(c) Sindre Sorhus