This file contains hidden or 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 { setState } from "react"; | |
| class SharedState<State> extends EventTarget { | |
| #state: State; | |
| constructor(state: State) { | |
| super(); | |
| this.#state = state; | |
| } | |
| get current() { | |
| return this.#state; |
This file contains hidden or 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
| FROM ruby:2.4-alpine | |
| ENV PATH /root/.yarn/bin:$PATH | |
| RUN apk update && apk upgrade && \ | |
| apk add --no-cache bash git openssh build-base nodejs tzdata | |
| RUN apk update \ | |
| && apk add curl bash binutils tar gnupg \ | |
| && rm -rf /var/cache/apk/* \ |
This file contains hidden or 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 hidden or 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 hidden or 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
| -- Runs using the open source Mac app https://www.hammerspoon.org | |
| -- Install Hammerspoon, and then copy this Gist into a file at ~/.hammerspoon/init.lua | |
| require("hs.ipc") | |
| hs.ipc.cliInstall() | |
| local math = require("hs.math") | |
| currentSpeech = nil |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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/yieldmachine@0.5.1/dist/yieldmachine.module.js" | |
| function TrafficLightsMachine() { | |
| const { Green, Yellow, Red } = { | |
| *Green() { | |
| yield on("timer", Yellow); | |
| }, | |
| *Yellow() { | |
| yield on("timer", Red); | |
| }, |
This file contains hidden or 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() { |
NewerOlder