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
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");
}
@getify
getify / 1.js
Last active Mar 13, 2019
exploring readability differences
View 1.js
let names = people.map(personToGetNameFrom => personToGetNameFrom.name);
// ******************
let getName = person => person.name;
let names = people.map(getName);
// ******************
function getName(person) { return person.name; }
@getify
getify / 1.js
Last active Apr 4, 2019
fun little experiment... a point-free definition for "copySession()" (essentially a shallow object copy)
View 1.js
// function copySession(sess) {
// return { ...sess };
// }
var copySession = compose(
reduce(
compose(
flip,
binary,
uncurry,
@getify
getify / 1.js
Last active Feb 5, 2019
React's `useCallback(..)` memoization... how does it work?
View 1.js
function Foo() {
var [x,setX] = useState(0);
var [y,setY] = useState(1);
var cb = useCallback(
function printXYIfChanged() { console.log(x,y); },
[x,y]
);
useEffect(
function pollingXY(){
var intv = setInterval(cb,100);
@getify
getify / 1.js
Last active Nov 14, 2018
regex matching escaped or non-escaped character
View 1.js
var a = "j"; // "j"
var b = "\\j"; // "\j"
var c = "\\\\j"; // "\\j"
var d = "\\\\\\j"; // "\\\j"
var e = "\\\\\\\\j"; // "\\\\j"
var f = "\\\\\\\\\\j"; // "\\\\\j"
var just_j = nonescapedRE("j");
just_j.test(a); // true
just_j.test(b); // false
@getify
getify / 1.js
Last active Mar 15, 2019
multiple-field sorter
View 1.js
var data = [
{ a: 4, b: 12, c: "elderberry" },
{ a: 2, b: 10, c: "cherry", d: 4 },
{ a: 4, b: 12, c: "durian" },
{ a: 2, b: 10, c: "cherry", },
{ a: 3, b: 12, c: "durian" },
{ a: 1, b: 10, c: "apple", },
{ a: 1, b: 11, c: "apple", },
{ a: 1, b: 11, c: "banana", },
{ a: 2, b: 10, c: "banana", },
@getify
getify / 1.js
Last active Jan 30, 2019
experiment: mimicking React's new "useState()" hook for stand-alone functions, including "custom hooks"
View 1.js
"use strict";
[foo,bar] = TNG(foo,bar);
// NOTE: intentionally not TNG(..) wrapping useBaz(), so that it's
// basically like a "custom hook" that can be called only from other
// TNG-wrapped functions
function foo(origX,origY) {
var [x,setX] = useState(origX);
var [y,setY] = useState(origY);
@getify
getify / 1.js
Last active Mar 15, 2019
creating hard-bound methods on classes
View 1.js
class Foo {
constructor(x) { this.foo = x; }
hello() { console.log(this.foo); }
}
class Bar extends Foo {
constructor(x) { super(x); this.bar = x * 100; }
world() { console.log(this.bar); }
}
@getify
getify / 1.js
Last active Nov 12, 2018
the "knights-dialer" problem
View 1.js
// https://medium.com/@alexgolec/google-interview-questions-deconstructed-the-knights-dialer-f780d516f029
function nearby(number) {
return (
number === 0 ? [4,6] :
number == 1 ? [6,8] :
number == 2 ? [7,9] :
number == 3 ? [4,8] :
number == 4 ? [3,9,0] :
number == 6 ? [1,7,0] :
You can’t perform that action at this time.