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-overview.md
Last active October 31, 2024 15:49
horribly slow date functions -- need help to optimize!!

Overview

I'm in need of help to profile where the slow part(s) of this relative-date util logic is, and find reasonable tweaks or work-arounds to thse bottlenecks.

I'm actually happy to even pay a bit of a bounty ($USD) for someone who can produce an analysis of the actual problem(s) and clear, workable solutions.

Here's an example estimated threshold for improvement that might be helpful (and earn a bounty): the 500-iteration loop above might be taking 200-300ms (on my system), and I need it to be able to run in less than 10ms (which should be completely doable I think, it's not that complex of logic).

IOW, we're going to need at least an order of magnitude improvement, not just 5-10% improvement.

@getify
getify / 1-imperative.js
Last active September 19, 2024 20:49
improve imperative code? is the reducer better? is there another better way?
function isEligible(value,userID) {
// .. whatever arbitrary logic ..
}
const buckets = [
user1: new Set(),
user2: new Set(),
user3: new Set(),
user4: new Set()
}
@getify
getify / 1.md
Last active August 22, 2024 05:56
counting line-pattern paths in 9 dot (3x3) grid

Problem

How many distinct line-segment patterns -- of varying lengths from 2 dots / 1 segment, up to 9 dots / 8 segments -- can be drawn on those 3x3 dot grids, like the phone unlock screen on Android phones?

Grid

0 1 2
3 4 5
6 7 8
@getify
getify / 1.md
Created June 5, 2024 18:08
The Root of All (Web) Evils

The Root of All (Web) Evils

The consumer web as we know it is around 30 years old, but of course its origins stretch back many years before. In those original days of the web, the infrastructure of how content was distributed and accessed was fairly de-centralized. If I had something to share, I'd put it in a digital location I owned/controlled, and you were invited to get that information directly. Nobody could tell me what I should and shouldn't create and share, and nobody could prevent your access if you wanted to see it.

But over the decades, this infrastructure has consolidated into ever more complex, and ever more expensive, centralized cloud providers. The "server-client" model is so ubiquitous now that it's hard for nearly anyone to imagine a web that could work in any other way than with "Big Cloud". While the centralization of the web has offered numerous scalability (and efficiency) benefits for web developers and web adminstrators, it has come with a vast increase in cost. And no I'm not real

@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();
// ..