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
(module $YouTubeURLParser | |
(memory (export "memory") 1) | |
(global $YouTubeURLParser.Input.bump_offset (mut i32) (i32.const 0)) | |
(func $YouTubeURLParser.Input.alloc! (param $byte_count i32) (result i32) | |
(local $new_ptr i32) | |
(global.get $YouTubeURLParser.Input.bump_offset) | |
(local.set $new_ptr) | |
(i32.gt_u (i32.add (local.get $new_ptr) (local.get $byte_count)) (i32.const 65536)) | |
(if | |
(then |
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
defmodule ParseU8 do | |
@moduledoc """ | |
https://lemire.me/blog/2023/11/28/parsing-8-bit-integers-quickly/ | |
""" | |
# Orb lets you write WebAssembly with friendly Elixir syntax: https://github.com/RoyalIcing/Orb | |
use Orb | |
Memory.pages(1) | |
wasm_mode(U32) |
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
const undefinedValue = Symbol(); | |
export class MapWithFallback<Key, Value> { | |
#map: Map<Key, Value>; | |
#fallback: Value; | |
constructor(fallback: Value) { | |
this.#map = new Map(); | |
this.#fallback = fallback; | |
} |
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
// Hard to read nested arrays. | |
const c = new Map([['a', 1], ['b', 2]]) | |
console.log(c) | |
// Have to write using object wrapped in two layers of calls. | |
const d = new Map(Object.entries({ a: 1, b: 2})) | |
console.log(d) |
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
// Constants are values with names. | |
// Functions accept values and return values. | |
const favoriteNumber = 7 | |
const favoriteNumber2 = (n: number) => n * 2 | |
const doubleNumber = (n: number) => n * 2 | |
const a = doubleNumber(favoriteNumber) | |
// = 14 |
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 { start, on } from "https://unpkg.com/[email protected]/dist/yieldmachine.module.js" | |
function TrafficLightsMachine() { | |
const { Green, Yellow, Red } = { | |
*Green() { | |
yield on("timer", Yellow); | |
}, | |
*Yellow() { | |
yield on("timer", Red); | |
}, |
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* ReactComponent() { | |
function* Initial() { | |
yield on("render", Rendering); | |
} | |
function* Rendering() { | |
yield on("resourceSuspended", Suspended); | |
yield on("error", Errored); | |
yield on("commit", Committed); | |
} | |
function* Suspended() { |
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
const Key = primaryKeyText('key'); | |
const Count = column('count', int(1)); | |
const CountersTable = table('counters', [Key, Count]); | |
function* Create() { | |
yield create(CounterTable); | |
} | |
function* QueryCountFor(key) { | |
return select([Count], [where(Key(key))]); |
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
// See: https://twitter.com/buildsghost/status/1529258931809202176 | |
// And: https://twitter.com/lewisl9029/status/1529360924343095296 | |
let db | |
function allProps(object) { | |
Object.fromEntries( | |
await Promise.all( | |
Object.entries(object).map(async ([key, promise]) => { | |
return [key, await promise] |
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* OpenFilter() { | |
function* Closed() { | |
yield on("First", First); | |
yield on("Second", Second); | |
} | |
function* First() { | |
yield on("First", Closed); | |
yield on("Second", Second); | |
} | |
function* Second() { |
NewerOlder