based on the keynote
The past, present, and future of AI for application developers
by Steve Sanderson
at NDC London 2025
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { parse } from 'acorn'; | |
import { simple } from 'acorn-walk'; | |
import { generate } from 'escodegen'; | |
import fs from 'fs'; | |
// https://astexplorer.net/ | |
function addCounterToNode(node) { | |
if (node.loc) { | |
const li = node.loc.start.line; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// array of [outcome, weight] | |
export function weightedRandom(arr) { | |
const outcomeCuts = []; | |
let accum = 0; | |
for (const [out, weight] of arr) { | |
accum += weight; | |
outcomeCuts.push([out, accum]); | |
} | |
const r = accum * Math.random(); | |
let best; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// import { webcrypto as crypto } from 'node:crypto'; // NODE | |
// eslint-disable-next-line no-undef | |
const crypto = globalThis.crypto; // BROWSER | |
const subtle = crypto.subtle; | |
const ALGO = 'AES-CBC'; | |
// HELPER FUNCTIONS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function defer<T>(): { | |
promise: Promise<T>; | |
resolve: (resp: T) => void; | |
reject: (err: any) => void; | |
} { | |
const answer: any = {}; | |
answer.promise = new Promise((resolve, reject) => { | |
answer.resolve = resolve; | |
answer.reject = reject; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { test } from 'node:test'; | |
import { strictEqual, deepEqual } from 'node:assert'; | |
/* | |
inspired by https://www.youtube.com/watch?v=umSuLpjFUf8 | |
3 3 * 4 4 * + sqrt | |
equivalent to | |
Math.sqrt(3*3 + 4*4) | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createReadStream } from 'fs'; | |
export function streamSplitBy(file, onMatch, splitBy='\n') { | |
return new Promise((resolve) => { | |
const stream = createReadStream(file); | |
let ongoing = ''; | |
stream.on('data', buff => { | |
const chunk = buff.toString(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function spy(fn: Function, prot = fn.prototype) { | |
function proxyFn() { | |
const args = Array.prototype.slice.call(arguments); | |
const call = { args, result: undefined, error: undefined, real: true }; | |
proxyFn.calls.push(call); | |
let responded = false; | |
// check if preparedCalls can answer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type SortableType = number | string | boolean; | |
type SortFn<T> = (el: T) => SortableType; | |
interface SortHelperApi<T> { | |
sortBy(fn: SortFn<T>, decrescent?: boolean): SortHelperApi<T>; | |
execute(): T[]; | |
} | |
/** |
NewerOlder