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 / 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 / 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 / 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 / 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 / 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
@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 / 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 / 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 / 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 / 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})`;