Skip to content

Instantly share code, notes, and snippets.

View colbydauph's full-sized avatar
©️

Colby Dauphinais colbydauph

©️
View GitHub Profile
@colbydauph
colbydauph / hook-write-stream.js
Created February 19, 2018 00:50
Hook Write Stream
const hookStreamWrite = (stream, callback) => {
const oldWrite = stream.write;
stream.write = callback((...args) => oldWrite.apply(stream, args));
return () => {
stream.write = oldWrite;
};
};
/* Example */
@colbydauph
colbydauph / subscribe-online.js
Created February 7, 2018 07:06
Subscribe to Online / Offline Changes
// subscribe to online / offline events
// (bool -> undefined) -> () -> undefined
const subscribeOnline = (cb) => {
const online = () => cb(true);
const offline = () => cb(false);
window.addEventListener('online', online, false);
window.addEventListener('offline', offline, false);
return function unsubscribe() {
window.removeEventListener('online', online);
@colbydauph
colbydauph / file-data-url.js
Last active March 15, 2018 22:34
Get File data url
// @async File -> DataUrl
const fileDataUrl = (file) => {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = () => resolve(reader.result);
reader.onerror = reject;
reader.readAsDataURL(file);
});
}
@colbydauph
colbydauph / promisify-callbackify.js
Last active March 21, 2018 20:45
Promisify + Callbackify
// inverse of callbackify
exports.promisify = (func) => (...args) => {
return new Promise((resolve, reject) => {
func(...args, (err, data) => {
err ? reject(err) : resolve(data);
});
});
};
// inverse of promisify
@colbydauph
colbydauph / circleci-docker-tag-commit.yml
Last active January 9, 2018 03:11
CircleCI + Docker + ECS - Tag Commit
tag_commit:
<<: *job_defaults
environment:
AWS_ACCOUNT_ID: 000000000000
AWS_REGION: us-east-1
steps:
- <<: *setup_remote_docker
@colbydauph
colbydauph / y-combinator.js
Created December 7, 2017 19:42
Y Combinator
// const factorial = Y(f => n => n > 1 ? n * f(n - 1) : 1);
const Y = f => (x => x(x))(y => f(x => y(y)(x)));
@colbydauph
colbydauph / npm version scripts.md
Last active January 3, 2018 05:32
Read package and node versions via npm scripts

package.json

"engines": { "node": "8.9.1" },
"scripts": {
  "version": "echo $npm_package_version",
  "node-version": "node -p 'require(\"./package.json\").engines.node'"
}

usage

Keybase proof

I hereby claim:

To claim this, I am signing this object: