Skip to content

Instantly share code, notes, and snippets.

View getify's full-sized avatar
💭
Just coding

Kyle Simpson getify

💭
Just coding
View GitHub Profile
@getify
getify / 1.md
Created March 2, 2019 15:16
problem making eslint plugin work... help!?
$> 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 February 14, 2019 20:55
thenify()... turn an err-first callback into two functions that can suitably be passed to a promise.then(..) and/or .catch(..)
function somethingThatReturnsAPromise(x,y,z) { .. }
function myCallback(err,v) {
if (err) {
console.error(err);
}
else {
console.log(v);
}
}
@getify
getify / fizzbuzz.js
Created December 13, 2018 18:29
my first ever attempt at fizzbuzz
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 February 25, 2020 11:27
exploring readability differences
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 June 30, 2022 16:35
fun little experiment... a point-free definition for "copySession()" (essentially a shallow object copy)
// function copySession(sess) {
// return { ...sess };
// }
var copySession = compose(
reduce(
compose(
flip,
binary,
uncurry,
@getify
getify / 1.js
Last active February 5, 2019 10:15
React's `useCallback(..)` memoization... how does it work?
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 July 20, 2022 19:31
regex matching escaped or non-escaped character
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 June 2, 2020 11:07
multiple-field sorter
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 September 29, 2021 11:58
experiment: mimicking React's new "useState()" hook for stand-alone functions, including "custom hooks"
"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 August 9, 2024 06:02
creating hard-bound methods on classes
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); }
}