Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
Just coding

Kyle Simpson getify

💭
Just coding
View GitHub Profile
@getify
getify / 1.js
Last active February 27, 2023 03:04
example of closure?
View 1.js
function A() {
var x = 1;
C(B);
function B() { console.log(x); }
function C(callback) {
B === callback; // true
B(); // is this console.log() using a closure or not? depends on perspective.
@getify
getify / 1.js
Last active February 17, 2023 11:55
periodic sync example code
View 1.js
// ..
self.addEventListener("periodicsync",onPeriodicSync);
// ..
await registerPeriodicSync();
// ..
@getify
getify / pizza.md
Created February 15, 2023 01:33
a chatgpt conversation
View pizza.md

if my three friends and I split a pizza evenly, and we all want more than one piece, how many slices should we cut the pizza into?

If you and your three friends want to split a pizza evenly and each person wants more than one piece, you should cut the pizza into at least 8 slices.

If you cut the pizza into 8 slices, each person can have two slices, and there will be two slices left over. You can decide how to split the remaining slices among yourselves, or you could also save them for later.

@getify
getify / 1.ebnf
Last active December 15, 2022 05:33
exploring grammars
View 1.ebnf
(* as checked here: https://mdkrajnak.github.io/ebnftest/ *)
(* ebnf syntax rules defined here: https://github.com/Engelberg/instaparse *)
Program := WhSp* (StmtSemi WhSp*)* StmtSemiOpt? WhSp*;
Stmt := AStmt | BStmt | CStmt | DStmt;
StmtSemi := Stmt? (WhSp* ";")+;
StmtSemiOpt := Stmt? (WhSp* ";")*;
WhSp := "_";
@getify
getify / 1-post.md
Last active February 27, 2023 00:23
Comparing: array method chaining, generator delegations, and transducing
View 1-post.md

Comparing: array method chaining, generator delegations, and transducing

I'm writing this quick post to respond to a recent twitter conversation where claims were made about the merits (or lack thereof) of transducers, as they relate to composing list comprehensions (map, filter).

For comparison sake throughout the rest of my post, below you'll find three (actually four!) implementations of a simple list operation demo:

View bfs.java
// this is an experimental Foi (https://github.com/getify/foi-lang) implementation of
// the BFS solution to https://gist.github.com/getify/59ab7443723564eb40d20ab7c45d5f0a
def < :size, :log >: import "#Std";
def M1: <
< 0, 0, 1, 1, 0 >,
< 1, 0, 1, 1, 0 >,
< 0, 1, 0, 0, 0 >,
< 0, 0, 0, 1, 1 >
@getify
getify / 1-setup.js
Last active October 11, 2022 20:06
find size of largest region in matrix... solutions are breadth-first iterative (2) and depth-first recursive (3)
View 1-setup.js
// Adapted from: https://www.geeksforgeeks.org/find-length-largest-region-boolean-matrix/
"use strict";
var M1 = [
[ 0, 0, 1, 1, 0 ],
[ 1, 0, 1, 1, 0 ],
[ 0, 1, 0, 0, 0 ],
[ 0, 0, 0, 1, 1 ]
];
@getify
getify / 1-utils.js
Last active August 20, 2022 17:14
illustrating some "dynamic composition" usage
View 1-utils.js
function flow(...fns) {
return arg => fns.reduce((res,fn) => fn(res),arg);
}
function partial(fn,initialArgs) {
return (nextArgs = []) => fn(...initialArgs,...nextArgs);
}
function pick(prop) {
return obj => obj[prop];
}
function prepend(prefix) {
@getify
getify / 1-CalendarItem.js
Last active August 4, 2022 00:08
an illustration (non-trivial example) of many newer JS class features
View 1-CalendarItem.js
// abstract class, not intended to be instantiated directly
class CalendarItem {
static #UNSET = Symbol("unset")
static #isUnset(v) {
return v === this.#UNSET;
}
static {
for (let [idx,msg] of [
"ID is already set.",
"ID is unset.",
@getify
getify / 1-works-fine.js
Last active July 16, 2022 18:22
strange inconsistency (between members and statics) with privates+subclassing
View 1-works-fine.js
class Point2d {
#ID = null
constructor(id) {
this.#ID = id;
}
getID() {
return this.#ID;
}
}