Skip to content

Instantly share code, notes, and snippets.

View mrosata's full-sized avatar
🐣

Michael Rosata mrosata

🐣
  • Quincy, MA USA
View GitHub Profile
@mrosata
mrosata / call-json-api.js
Created January 21, 2017 23:07
JavaScript; Mock Dating Site JSON Api challenges
const getJSON = require('get-json');
/** api data **/
const API = {
uri: 'http://beta.json-generator.com/api/json',
tables: {
profiles: '4ybyRpIWz',
users: 'NJq8uvBWM'
}
};
@mrosata
mrosata / future-app-model-a.js
Last active December 14, 2016 18:42
FAM - Chrome Dev Summit 2016 snippet
const response = await fetch(url);
const reader = response.body.getReader();
while (true) {
const {done, value} = await reader.read();
if (done)
break;
// Do something with value otherwise
console.log(value);
}
// We now can write this, more human readable form:
placeOrder([
farmhouseLight(10),
farmhouseDark(4),
columbian(3, 3),
columbian(4, 3),
arrrrrggg(letMeThink(), itDepends())
]);
// Now where we once would have written this:
placeOrder([
baristaJoe('farmhouse blend', 10, 10),
baristaJoe('farmhouse blend', 0, 4),
baristaJoe('columbian', 3, 3),
baristaJoe('columbian', 4,3),
baristaJoe('half-caff carmel-mocha pumkin-karaoke', letMeThink(), itDepends())
]);
// Those 5 lines of code we wrote above to create more specific functions,
// is about the same as writing these 35 lines of code down here... power.
/* So to be clear, we don't have to write these implementations */
function farmhouse(creams, sugars) {
const coffee = getCoffee('farmhouse blend');
coffee.add.cream(creams);
coffee.add.suger(sugars);
return coffee;
}
// If baristaJoe was a curried function, we could create more specific functions
// by "partially applying" an argument at a time.
const farmhouse = baristaJoe('farmhouse blend');
const columbian = baristaJoe('columbian');
const arrrrrggg = baristaJoe('half-caff carmel-mocha pumkin-karaoke');
const farmhouseLight = farmhouse(10);
const farmhouseBlack = farmhouse(0);
// Our friendly work-adjacent coffee man!
function baristaJoe(flavor, creams, sugars) {
const coffee = getCoffee(flavor); // Pour the coffee
coffee.add.cream(creams); // How many creams to add
coffee.add.suger(sugars); // How many sugars to add
return coffee;
}
@mrosata
mrosata / getting-curried-away.1a.js
Last active November 19, 2016 16:33
Getting Curried Away - example 1
// Our friendly work-adjacent coffee man!
function baristaJoe(flavor, creams, sugars) {
const coffee = getCoffee(flavor); // Pour the coffee
coffee.add.cream(creams); // How many creams to add
coffee.add.suger(sugars); // How many sugars to add
return coffee;
}
@mrosata
mrosata / notes.txt
Created November 16, 2016 05:17 — forked from AlwaysBCoding/notes.txt
Ethereum Ðapp Development - Video 3 | The Halting Problem And Why We Need Gas
// To learn more about the halting problem check out Gary Bernhardt's series on computation
https://www.destroyallsoftware.com/screencasts
// Ethereum Yellow Paper
http://gavwood.com/paper.pdf
// Ethereum OpCodes List
http://ethereum.stackexchange.com/questions/119/what-opcodes-are-available-for-the-ethereum-evm
// Ethereum OpCodes Gas Costs
@mrosata
mrosata / jsbin-functional-program.js
Created November 16, 2016 04:50
Functional Programming with IO, Maybe, Just, Nothing -- Touch of Reactive
console.clear()
// The Ramda Library functions you need to breathe.
const Maybe = iJustMetYouThisIsCrazyImAMonadSoCallMeMaybe()
const {
map, chain, compose, reduce, filter, prop, curry
} = R
// fromEvent :: Str -> Elem -> Obs
const fromEvent = curry((eventType, elem) => {
return Rx.Observable.fromEvent(elem, eventType)