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
| /** | |
| * https://www.youtube.com/watch?v=q5DFpyIN5Xs&t=180s | |
| * | |
| * This type helps resolve complex TypeScript types in simpler readable types | |
| * | |
| * - Take a layered complex type (extending multiple types, using generics, inheriting etc.) | |
| * - Create a dummy type via Prettify (type Dummy = Prettify<ComplexType>) | |
| * - Hover with the mouse on the dummy type to see the "resolved" type | |
| */ | |
| export type Prettify<T> = { |
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
| class DoubleArrayQueue<T> { | |
| inElements: T[] = []; | |
| outElements: T[] = []; | |
| enqueue(element: T) { | |
| this.inElements.push(element); | |
| } | |
| dequeue() { | |
| this.transferElements(); |
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 { createInterface } from "node:readline"; | |
| const DIRECTION_AHEAD = "ahead"; | |
| const DIRECTION_LEFT = "left"; | |
| const DIRECTION_RIGHT = "right"; | |
| const DIRECTION_BACK = "back"; | |
| const MOVE_ATTACK = "attack"; | |
| const MOVE_FLEE = "flee"; |
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
| // Thanks to | |
| // https://github.com/microsoft/tsyringe/issues/66#issuecomment-566755746 | |
| // https://262.ecma-international.org/6.0/#sec-promise-resolve-functions | |
| main(); | |
| async function main() { | |
| const rnd = getRandom(); | |
| console.log(await rnd); | |
| console.log(await rnd); |
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
| // This is a generator function | |
| // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator | |
| function* range(minOrMax: number, max?: number) { | |
| const maxExists = max !== undefined; | |
| const inf = maxExists ? minOrMax : 0; | |
| const sup = maxExists ? max : minOrMax; | |
| for (let i = inf; i < sup; i++) { | |
| yield i; | |
| } |
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
| interface Visitor<TElementTypes = any> { | |
| visit(element: TElementTypes): void; | |
| } | |
| interface ConcreteItem { | |
| accept(visitor: Visitor): void; | |
| } | |
| class ConcreteItemA implements ConcreteItem { | |
| accept(visitor: Visitor): void { |
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
| /** | |
| * What does this script output? Watch out! | |
| */ | |
| package main | |
| import "fmt" | |
| type mystring string | |
| func (s mystring) String() string { |
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
| CREATE TABLE "users" ( | |
| "id" INTEGER NOT NULL UNIQUE, | |
| "email" TEXT NOT NULL UNIQUE, | |
| PRIMARY KEY("id" AUTOINCREMENT) | |
| ); | |
| INSERT INTO "users" ("id", "email") VALUES | |
| (1, "alice@example.com"), | |
| (2, "bob@example.com"), | |
| (3, "charlie@example.com"); |
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
| package main | |
| import "testing" | |
| func BenchmarkConcMap100(b *testing.B) { | |
| b.StopTimer() | |
| input := createRange(100) | |
| output := make([]int, 0, len(input)) | |
| b.StartTimer() |
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
| /** | |
| * How can you loop on promises, really? | |
| * | |
| * This experiment tests how promises and loops interact in JavaScript | |
| * | |
| * TL;DR: for await...of is the clear winner | |
| * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of | |
| */ | |
| run(); // <-- Start here |
NewerOlder