Skip to content

Instantly share code, notes, and snippets.

View primitiveshaun's full-sized avatar

Shaun Knowles primitiveshaun

View GitHub Profile
@primitiveshaun
primitiveshaun / node-commands.sh
Created March 31, 2020 08:31
Node.js - NPM Commands Reference
# node-commands.sh
# *** HOUSEKEEPING! One for the Node ***
# Master File: Maintained by Primitive Digital's Housekeeping Department
# https://primitivedigital.uk/housekeeping-department/
# STATUS ::: DRAFT: Requires Review
# version of npm
$ npm --version
$ npm -v
@primitiveshaun
primitiveshaun / svn-commands.sh
Last active March 31, 2020 08:16
SVN Commands Reference
# svn-commands.sh
# *** HOUSEKEEPING! We all live in a yellow svn repository, a yellow svn repository... ***
# Master File: Maintained by Primitive Digital's Housekeeping Department
# https://primitivedigital.uk/housekeeping-department/
# STATUS ::: DRAFT: Requires Review
# version of svn
$ svn --version
// Class Inheritance Example
// NOT RECOMMENDED. Use object composition, instead.
// https://gist.github.com/ericelliott/b668ce0ad1ab540df915
// http://codepen.io/ericelliott/pen/pgdPOb?editors=001
class GuitarAmp {
constructor ({ cabinet = 'spruce', distortion = '1', volume = '0' } = {}) {
Object.assign(this, {
cabinet, distortion, volume
@primitiveshaun
primitiveshaun / wait.js
Created October 8, 2019 08:17 — forked from ericelliott/wait.js
Wait -- an ES6 promise example
const wait = time => new Promise((resolve) => setTimeout(resolve, time));
wait(3000).then(() => console.log('Hello!')); // 'Hello!'
@primitiveshaun
primitiveshaun / cancellable-wait.js
Created October 8, 2019 08:06 — forked from ericelliott/cancellable-wait.js
Cancellable wait -- an ES6 promise example
const wait = (
time,
cancel = Promise.reject()
) => new Promise((resolve, reject) => {
const timer = setTimeout(resolve, time);
const noop = () => {};
cancel.then(() => {
clearTimeout(timer);
reject(new Error('Cancelled'));
@primitiveshaun
primitiveshaun / promise-chaining.js
Created October 8, 2019 08:05 — forked from ericelliott/promise-chaining.js
Promise chaining behaviors
const wait = time => new Promise(
res => setTimeout(() => res(), time)
);
wait(200)
// onFulfilled() can return a new promise, `x`
.then(() => new Promise(res => res('foo')))
// the next promise will assume the state of `x`
.then(a => a)
// Above we returned the unwrapped value of `x`
@primitiveshaun
primitiveshaun / speculation.js
Created October 8, 2019 08:05 — forked from ericelliott/speculation.js
Speculation: Cancellable promise implementation. Maintained production version here: https://github.com/ericelliott/speculation
// HOF Wraps the native Promise API
// to add take a shouldCancel promise and add
// an onCancel() callback.
const speculation = (
fn,
cancel = Promise.reject() // Don't cancel by default
) => new Promise((resolve, reject) => {
const noop = () => {};
const onCancel = (
@primitiveshaun
primitiveshaun / wait-speculation.js
Created October 8, 2019 08:04 — forked from ericelliott/wait-speculation.js
Wait with speculation
import speculation from 'speculation';
const wait = (
time,
cancel = Promise.reject() // By default, don't cancel
) => speculation((resolve, reject, onCancel) => {
const timer = setTimeout(resolve, time);
// Use onCancel to clean up any lingering resources
// and then call reject(). You can pass a custom reason.
@primitiveshaun
primitiveshaun / filter.js
Created October 8, 2019 08:02 — forked from ericelliott/filter.js
Filter implemented with reduce
const filter = (fn, arr) => arr.reduce((newArr, item) => {
return fn(item) ? newArr.concat([item]) : newArr;
}, []);
@primitiveshaun
primitiveshaun / js-perf-api-tests
Created October 6, 2019 11:07
Custom JavaScript Performance Testing Script
// Custom JavaScript Performance Testing Script
// *** HOUSEKEEPING! Performance Review ***
// Master File: Maintained by Primitive Digital's Housekeeping Department
// https://primitivedigital.uk/housekeeping-department/
// This utilises the native
// https://developer.mozilla.org/en-US/docs/Web/API/Performance
// This can be saved to an external JS file and placed in the library
// this will allow the performance tests to be toggled on/off based on a fied value