Chronological feed of everything captured from Amjad Masad.
github_gist / amasad / Aug 17
RequireBin provides a live coding environment where developers can require NPM modules like 'buffer' directly in the browser, automatically bundling them via browserify-cdn. The demo creates a 100-byte Buffer instance and verifies that subarray(50,100) returns a 50-byte view, demonstrating efficient array slicing without data copying. This showcases polyfill Buffer implementation with full Node.js API compatibility including read/write methods, encoding support, and TypedArray augmentation when available.
nodejs-bufferbrowserify-cdnrequirebinbrowser-polyfilljavascript-runtimebuffer-subarrayamjad-masad
“RequireBin bundles NPM modules client-side using browserify-cdn”
github_gist / amasad / Nov 22
Amjad Masad published a GitHub Gist titled /clowtown.js containing HTML/JavaScript that embeds another Gist. The embedded Gist displays a single line of text: "clowntown". This structure serves as a self-referential or humorous placeholder with no functional code beyond rendering the term.
github-gistamjad-masadclowtownjavascriptunicode-trickembed-code
“The Gist is created by user amasad (Amjad Masad)”
github_gist / amasad / Aug 6
In Node.js v0.12 with --expose-gc, loading and transforming a large Babel browser bundle consumes 430 MB heap, which drops to 19.8 MB immediately after gc(). However, heapTotal remains fixed at 240 MB while heapUsed slowly increases over time without further allocations. This demonstrates V8's heap allocator does not shrink committed memory post-GC, leading to persistent high RSS usage.
node-jsmemory-leakgarbage-collectionheap-memoryv8-enginebabel-coreperformance-debugging
“After explicit GC in Node.js v0.12, heapUsed drops from 430 MB to under 20 MB”
github_gist / amasad / Aug 6
Node.js script allocates 20 million empty objects in a loop, spiking heapUsed from ~3.5 MB to ~782 MB. Explicit gc() call then reclaims nearly all allocated memory, dropping heapUsed back to ~3.4 MB consistently across repeated cycles. Demonstrates V8's garbage collector handles large, short-lived object arrays with high efficiency when manually triggered.
heap-reclamationmemory-managementjavascriptnode-jsgarbage-collectionperformance-testing
“Allocating 20 million empty objects increases heapUsed from ~3.5 MB to ~782 MB”
github_gist / amasad / Jan 18
js-csp channels enable a concise, generator-based implementation of a client that buffers requests to a single-threaded RPC math worker process, avoiding explicit state variables and queues. The core loop awaits ready signals, serializes requests via channels, and dispatches responses without manual state transitions. This contrasts with traditional state machine approaches using enums and queues, offering better locality for multi-turn interactions like iterative number guessing.
js-cspconcurrencystate-machineschild-processasync-programmingnode-jscode-comparison
“js-csp implementation handles concurrent add/subtract calls without explicit state queue”
github_gist / amasad / Jan 4
In Flow, checking a nullable parameter with `if (n == null)` correctly narrows it to non-null, enabling safe use like `n > 10`. The same pattern fails for class properties, where `if (this.n == null)` does not narrow `this.n : ?number`, causing type errors on `this.n > 10`. This reveals an inconsistency in Flow's type narrowing for `this` properties versus function parameters.
flow-typejavascripttype-checkinggithub-gistamasadtype-bugnull-check
“Flow correctly narrows a function parameter typed as `?number` after `if (n == null)` check”
github_gist / amasad / Aug 22
Amjad Masad explores TDZ violations in JavaScript default parameters when closures reference later parameters. He questions if early references (e.g., bar referencing x) are allowed due to hoisting equivalence, but suspects mutual dependencies (e.g., bar referencing x=bar()) should throw. Nested TDZ in closure parameters (e.g., function(y=x)) likely triggers errors, necessitating static TDZ checks for transpilation.
javascriptdefault-parameterstemporal-dead-zoneclosurestdzfunction-parameters
“Closure in early default parameter referencing a later parameter (bar = () => x, x=1) evaluates successfully to 1”
github_gist / amasad / Dec 1
This Racket code implements Conway's Game of Life using 2htdp libraries for a grid-based cellular automaton. It defines cell and board structures, neighbor counting via bounded iteration, and applies standard survival/birth rules: live cells survive with 2-3 neighbors, die otherwise; dead cells birth with exactly 3 live neighbors. The board animates via big-bang with on-tick updates at 0.25s intervals, rendering scaled black squares on white background for live cells, including a cross pattern initializer.
conways-game-of-liferacket-programmingcellular-automatafunctional-programmingcode-gistanimation-simulation
“Live cells survive if they have exactly 2 or 3 live neighbors”
github_gist / amasad / Oct 31
This self-executing JavaScript function scans Facebook links ending in .gif, replacing their img src attributes with the direct GIF URL to trigger native animation. It uses a debounced scroll event handler (300ms delay) to efficiently reprocess links as the user scrolls, ensuring animated thumbnails load dynamically. Initial execution runs on load, targeting only links with matching href patterns and excluding those with onmouseover handlers containing 'gif' by dispatching the event instead.
javascriptbrowser-scriptgif-playbackfacebook-hackscroll-debouncedom-manipulationgithub-gist
“The script targets anchor elements with href attributes ending in '.gif'”
github_gist / amasad / Jun 6
Cons constructs a pair by returning a selector function that applies its argument to the pair's components. Car and cdr extract the first and second elements by passing selector functions that return a or b respectively. The implementation supports nested pairs, demonstrated by cons(1, cons(2, cons(3, null))) yielding expected car/cdr results.
javascriptlispcons-car-cdrfunctional-programmingcode-gistamasad
“cons(a, b) returns a function that applies its selector argument to a and b”
github_gist / amasad / Jan 2
This GitHub Gist demonstrates ES6 Proxy usage to intercept property access on an object named 'adam'. The Proxy's get trap handles the 'getName' message by returning "Adam of Eden", throwing an error for unknown messages. It showcases basic Proxy interception without a target object via Proxy.create (pre-Proposal syntax).
javascriptproxyes6code-examplegithub-gistamjad-masad
“The adam object returns 'Adam of Eden' when getName is accessed”
github_gist / amasad / Dec 28
This JS router parses window.location.pathname into segments and matches against route patterns using a stack-based arg collector for params and nested scopes. It supports optional path segments via parentheses, parameterized routes with :names, and regex constraints via regHash objects. Core APIs—scope (partial match with path advancement), match (full path consumption), part (partial match without advancement)—enable hierarchical routing as shown in the '/en/sections/123abc/1' example.
javascriptrouterurl-routingclient-sidepath-matchingunderscore-jsweb-development
“Router supports optional path segments denoted by parentheses”