Skip to content

Instantly share code, notes, and snippets.

💭
Just coding

Kyle Simpson getify

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 May 4, 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 May 9, 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
@getify
getify / 1.js
Created Feb 14, 2019
thenify()... turn an err-first callback into two functions that can suitably be passed to a promise.then(..) and/or .catch(..)
View 1.js
function somethingThatReturnsAPromise(x,y,z) { .. }
function myCallback(err,v) {
if (err) {
console.error(err);
}
else {
console.log(v);
}
}
@getify
getify / fizzbuzz.js
Created Dec 13, 2018
my first ever attempt at fizzbuzz
View fizzbuzz.js
function fizzbuzz() {
for (let i = 1; i <= 100; i++) {
let div3 = i % 3 == 0;
let div5 = i % 5 == 0;
if (div3 && div5) {
console.log("FizzBuzz");
}
else if (div3) {
console.log("Fizz");
}
You can’t perform that action at this time.