Run a terminal from inside your terminal.
The purpose of this code is to demonstrate how to have applications running in a PTY (psedoterminal) environment.
Be sure to have Go installed.
import * as bigintConversion from "bigint-conversion"; | |
const extendedGcd = ( | |
a: bigint, | |
b: bigint | |
): { result: bigint; x: bigint; y: bigint } => { | |
if (a === 0n) return { result: b, x: 0n, y: 1n }; | |
const { result, x: x1, y: y1 } = extendedGcd(b % a, a); | |
return { result, x: y1 - (b / a) * x1, y: x1 }; | |
}; |
I wrote this to teach myself on how React and other JSX library work behind the scenes.
First, you will need a bundler that doesn't exclusively work with React. Unfortunately, how to configure it is beyond the scope of this README file, since every bundler has their own way of converting JSX to JavaSript.
That said, there are some tutorials on how to do that.
Think of a bounded variable no different than a bounded queue to solve the consumer—producer problem.
A very common use case is for me is to push to a single variable from one producer, and pull from that single variable from one consumer.
Go has a very simple solution: channels.
But I was curious: can we improve the performance?
/** | |
Copyright 2023 Sal Rahman | |
Permission is hereby granted, free of charge, to any person obtaining a copy of | |
this software and associated documentation files (the “Software”), to deal in | |
the Software without restriction, including without limitation the rights to | |
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | |
the Software, and to permit persons to whom the Software is furnished to do so, | |
subject to the following conditions: |
interface ReadOnlyMapNoGetter<K, V> { | |
has(key: K): boolean; | |
entries(): IterableIterator<[K, V]>; | |
forEach(cb: (value: V, key: K, map: ReadOnlyMapNoGetter<K, V>) => void): void; | |
keys(): IterableIterator<K>; | |
values(): IterableIterator<V>; | |
readonly size: number; | |
} | |
interface ReadOnlyMap<K, V> extends ReadOnlyMapNoGetter<K, V> { |
class Trie { | |
private children: Map<string, Trie> = new Map(); | |
insert(value: string) { | |
if (value === "") { | |
return; | |
} | |
const first = value[0]; | |
if (!first) { | |
throw new Error("Expected the first element to not be an empty string."); |
type List<T1> = [T1, List<T1> | null]; | |
function* iterateCons<T>([left, right]: List<T>): IterableIterator<T> { | |
if (right) { | |
yield* iterateCons(right); | |
} | |
yield left; | |
} | |
const cons = <T1, T2>(left: T1, right: T2): [T1, T2] => [left, right]; |