Navigation Menu

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
Last active March 23, 2024 16:16
describing a bundling question in detail

I'm the author of an npm package that comes as a single ESM-format module, let's call it "A". This package is only a client-side (browser) library, it will not work in Node -- it interacts with client-only web platform APIs.

The "A" package doesn't use any typical build tools (typescript, webpack/vite, etc). But it does include a simple "publish-build" script that's used at npm publish time to prepare a dist/ directory for the package.

The package relies on three npm package dependencies (call them "B", "C", and "D"), which I do not own/control. These 3 packages only distribute themselves as plain .js window-global style scripts. They cannot be imported, because (unfortunately) they make assumptions about global-scope this (being window), non-strict mode, etc. That also means they can't just be inlined into the "A" distribution module file.

Moreover, these dependencies are big enough (and potentially useful enough) that a user of "A" might also want to access and use "B", "C", or "D" functi

@getify
getify / 1.js
Created January 2, 2024 17:53
minimal POC for Reader monad in JS
var r = Reader();
console.log(
r
.map(env => ({ ...env, y: 2 }))
.chain(env => Reader(() => ({ ...env, z: 3 })))
.evaluate({ x: 1 })
);
// { x: 1, y: 2, z: 3 }
@getify
getify / 1.js
Last active December 4, 2023 20:31
JS vs Foi symbol count comparision: async IO
// note: this requires a JS library for the IO monad, for example Monio: https://github.com/getify/monio/blob/master/MONIO.md#io-monad-one-monad-to-rule-them-all
// CHARACTER STATS...
// letters, numbers, string-literal-chars (a-z A-Z 0-9 / < >): 273
// non-letters-non-whitespace: 78
// simple symbols (. ` " ( ) { } $ , =): 63
// compound symbols (=>): 4 (8 chars)
// optional semicolons: 6
// whitespace: 73
@getify
getify / 1.js
Last active December 8, 2023 17:51
JS vs Foi symbol count comparision: FP (partial application, pipelines, etc)
// note: this uses proposed JS syntax for pipeline operator: https://github.com/tc39/proposal-pipeline-operator
// CHARACTER STATS (code comments and their padded whitespace ignored)...
// letters, numbers (a-z A-Z 0-9): 317
// non-letters-non-whitespace: 138
// simple symbols (+ - * / . " : ( ) [ ] { } , =): 94
// compound symbols (=> ?? ?. |> %%): 15 (30 chars)
// optional semicolons: 14
// whitespace: 90
@getify
getify / 1.js
Last active February 27, 2023 03:04
example of closure?
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
// ..
self.addEventListener("periodicsync",onPeriodicSync);
// ..
await registerPeriodicSync();
// ..
@getify
getify / pizza.md
Created February 15, 2023 01:33
a chatgpt conversation

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
(* 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

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:

// 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 >