Skip to content

Instantly share code, notes, and snippets.

💭
Just coding

Kyle Simpson getify

💭
Just coding
Block or report user

Report or block getify

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@getify
getify / 1.js
Last active Jun 8, 2019
race-promises-pool
View 1.js
async function racePromisesPool([ ...prs ] = []) {
var raceWon = false;
var prListeners = prs.map(function listen(pr,idx){
return pr.then(function t(v){
if (!raceWon) {
raceWon = true;
prs.splice(idx,1); // remove the promise from the pool since it won the race
return v;
}
});
@getify
getify / 1.js
Created Jun 7, 2019
merging defaults/settings objects with destructuring
View 1.js
ajax(
ajaxOptions({
url: "https://my.other.tld/api",
headers: {
"Cache-Control": "no-cache"
},
cb: resp => console.log(resp)
})
);
@getify
getify / 1.js
Last active May 31, 2019
Force Monad #MayThe4thBeWithYou
View 1.js
var Force = { Skywalker, RegularFolk, of: Skywalker };
function Skywalker(v) {
return { map, chain, ap };
function map(fn) {
return Skywalker(fn(v));
}
function chain(fn) {
return fn(v);
}
@getify
getify / 1.js
Last active Jun 3, 2019
is Maybe a "monad?
View 1.js
// is Just(..) a monad? Well, it's a monad constructor.
// Its instances are certainly monads.
function Just(v) {
return { map, chain, ap };
function map(fn) {
return Just(fn(v));
}
function chain(fn) {
return fn(v);
}
@getify
getify / 1.js
Created Apr 9, 2019
if..else if.. else clauses
View 1.js
// note: mathematically, `x` can only ever be 0, 1, 2, or 3
var x = someNumber % 4;
// let's consider some options for an if..else if..else clause series...
@getify
getify / 1.js
Last active Apr 11, 2019
Nested ternary: good vs bad
View 1.js
var data = x ? y ? z ? z : y : x : 0;
// I call this the "if..if" pattern, and it's BAD. It means:
var data;
if (x) {
if (y) {
if (z) {
data = z;
}
@getify
getify / 1.js
Last active Mar 14, 2019
ESLint: test cases for determining if a function parameter is unused
View 1.js
// these `xx` parameters are all used, so no "unused parameter" errors should be reported
var f;
f = (xx) => xx;
f = (xx) => () => xx;
f = (xx) => { xx; };
f = (xx, yy = xx) => { yy; };
f = (xx, yy = xx) => { var xx; xx = yy; };
f = (xx, yy = xx) => { var xx = yy; };
@getify
getify / better-web.md
Created Mar 12, 2019
Building That Better Web
View better-web.md

Building That Better Web

In honor of the 30th anniversary of the web, I wanted to share a few thoughts about what a better web could aspire to be, and challenge us to move toward it.

The Worser Web

It's tempting to frame "better" simply in terms of improvement and progress, as in how far the web has come over the last 20+ years. As a developer, I like many others get all too excited about fancy new features like Service Workers, WebRTC, and yes, even CSS Grids. The pace of change is dizzying, but it feels like a great problem to have too many awesome features to learn and use!

So in one practical respect, a better web is one that empowers developers and users alike to express themselves and connect with others more fluently.

@getify
getify / 1.js
Created Mar 6, 2019
Promise.lazyAll(..)
View 1.js
Promise.lazyAll = async function lazyAll(iter) {
var results = [];
for await (let val of iter) {
results.push(val);
}
return results;
};
(async function(){
console.log( `results(1): ${ await Promise.lazyAll( [1,2,3] )}` );
@getify
getify / 1.md
Created Mar 2, 2019
problem making eslint plugin work... help!?
View 1.md
$> node_modules/eslint/bin/eslint.js --version
v5.15.0

$> cat foo.js
"use strict";
var x = y => foo(y);

$> cat .eslintrc.json
You can’t perform that action at this time.