Skip to content

Instantly share code, notes, and snippets.

View JasonCust's full-sized avatar
🍺
Hold my beer…

Jason Cust JasonCust

🍺
Hold my beer…
View GitHub Profile
<!DOCTYPE html>
<html dir="ltr" lang="en-US">
<head>
<base href="https://raw.githubusercontent.com/rachelandrew/css-for-print/master/">
<style>
/* this stylesheet is used when generating a PDF with PrinceXML or any other tool that understands the CSS used. */
/* define a page */
@page {
size: 5.5in 8.5in;
@JasonCust
JasonCust / concurrent-full-update-example.js
Last active February 21, 2018 03:12
Concurrent Updates: Full vs Partial Objects.
import createDb from './database.js';
import { randomWait, log } from './helper.js';
const db = createDb();
// Current middleware approach
const logger = log('Full');
// Simulated two concurrent fetch and save requests
Promise.all([
// Helper function to generate random delay
function randomWait() {
return new Promise(resolve => {
setTimeout(resolve, Math.ceil(Math.random() * 1000));
});
}
// The "database"
const dataStore = {
// Records Collection
@JasonCust
JasonCust / dogwood-sandwich-arguments-defaults.js
Last active January 22, 2017 05:23
ES2015 Destructuring Assignment Example -- Basic object destructuring assignment for arguments with defaults using a Dagwood Sandwich
function makeCheeseSandwich({bread, cheeses, condiments = ['mustard']}) {
return {bread, cheeses, condiments};
}
console.log(makeCheeseSandwich(dagwoodSandwich));
// output: { bread: 'rye', cheeses: [ 'cheddar' ], condiments: [ 'mustard' ] }
@JasonCust
JasonCust / dogwood-sandwich-arguments.js
Last active January 22, 2017 05:10
ES2015 Destructuring Assignment Example -- Basic object destructuring assignment for arguments using a Dagwood Sandwich
// The argument name syntax is a Destructuring Assignment
function makeCheeseSandwich({bread, cheeses}) {
return {bread, cheeses};
}
console.log(makeCheeseSandwich(dagwoodSandwich));
// output: { bread: 'rye', cheeses: [ 'cheddar' ] }
@JasonCust
JasonCust / dogwood-sandwich-basic-default.js
Last active January 22, 2017 05:24
ES2015 Destructuring Assignment Example -- Basic object destructuring assignment with default value using a Dagwood Sandwich
let {bread, cheeses, condiments = ['mustard']} = dagwoodSandwich;
console.log({bread, cheeses, condiments});
// output: { bread: 'rye', cheeses: ['cheddar'], condiments: ['mustard'] }
@JasonCust
JasonCust / dogwood-sandwich-basic.js
Last active January 22, 2017 05:03
ES2015 Destructuring Assignment Example -- Basic object destructuring assignment using a Dagwood Sandwich
let dagwoodSandwich = {
bread: 'rye',
cheeses: ['cheddar'],
meats: ['salami', 'ham', 'turkey', 'bologna'],
toppings: ['lettuce', 'tomatoes', 'onions', 'fried egg', 'olives']
};
let {bread, cheeses} = dagwoodSandwich; // <-- Destructuring Assignment
console.log({bread, cheeses}); // ouptut: { bread: 'rye', cheeses: ['cheddar'] }
@JasonCust
JasonCust / objects-basic-defaults.js
Last active January 22, 2017 05:26
ES2015 Destructuring Assignment Example -- Basic object destructuring assignment with default value
/* ES5 equivalent (ignoring assignment of intended falsy values)
var obj = {};
var one = obj.one;
var two = obj.two || 2;
*/
let obj = {};
let {one, two = 2} = obj;
console.log({one, two}); // output: { one: undefined, two: 2 }
@JasonCust
JasonCust / arguments-basic-defaults.js
Created January 17, 2017 01:57
ES2015 Destructuring Assignment Example -- Basic function argument destructuring assignment with default value
/* ES5 equivalent (ignoring assignment of intended falsy values)
function foo(one, two) {
one = one || 1;
console.log({one, two});
}
*/
function foo(one = 1, two) {
console.log({one, two});
}
@JasonCust
JasonCust / arrays-defaults-basic.js
Last active January 22, 2017 05:26
ES2015 Destructuring Assignment Example -- Basic array destructuring assignment with default value
/* ES5 equivalent (ignoring assignment of intended falsy values)
var arr = [];
var one = arr[0] || 1;
var two = arr[1];
*/
let arr = [];
let [one = 1, two] = arr;
console.log({one, two}); // output: { one: 1, two: undefined }