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 { exec, type ChildProcess } from "child_process"; | |
/** | |
* Enum representing ANSI escape codes for text colors in the terminal. | |
* | |
* This enum provides a set of color codes that can be used to add color | |
* to text output in terminal environments. These colors are commonly | |
* supported across various terminal emulators. | |
* | |
* @example |
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 path from "path"; | |
import chokidar from "chokidar"; | |
import fs from "fs"; | |
import type { ServerWebSocket } from "bun"; | |
const CONFIG = Object.freeze({ | |
srcDir: "./src", | |
outDir: "./public", | |
entrypoints: ["index.ts"], | |
}); |
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
#!/bin/sh | |
print_usage() { | |
echo "usage: compress_video <input_file>" | |
echo "supported formats: mp4, webm, mkv, mov, avi, flv" | |
} | |
get_extension() { | |
f="${1##*/}" | |
case "$f" in |
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 ( | |
"image/color" | |
"log" | |
"math" | |
"github.com/hajimehoshi/ebiten/v2" | |
"github.com/hajimehoshi/ebiten/v2/ebitenutil" | |
"github.com/hajimehoshi/ebiten/v2/vector" |
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
let merge arr l m r max = | |
let i = ref l in | |
let j = ref (m + 1) in | |
let k = ref l in | |
while !i <= m && !j <= r do | |
if arr.(!i) mod max <= arr.(!j) mod max then ( | |
arr.(!k) <- arr.(!k) + (arr.(!i) mod max * max); | |
incr k; | |
incr i) | |
else ( |
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
#include <stdint.h> | |
uint32_t hash_djb2(unsigned char *str) { | |
uint32_t hash = 5381; | |
uint32_t c; | |
while ((c = *str++)) | |
hash = ((hash << 5) + hash) + c; /* hash * 33 + c */ | |
return hash; |
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 { describe, it, expect, spyOn } from "bun:test"; | |
import { fetchJson } from "./fetchJson"; | |
class MockResponse { | |
static instanceCount = 0; | |
constructor( | |
public readonly ok: boolean, | |
private jsonSuccess: boolean | "bad parse", | |
) { | |
MockResponse.instanceCount++; |
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 { describe, it, expect, beforeAll, afterAll } from "bun:test"; | |
import { fileContains, BoyerMooreSearcher } from "./fileContains"; | |
import fs from "fs"; | |
import path from "path"; | |
describe("fileContains", () => { | |
const testDir = path.join(__dirname, "test-files"); | |
beforeAll(() => { | |
if (!fs.existsSync(testDir)) { |
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
/** | |
* Transforms a function that returns either a direct value or a thunk (a | |
* no-argument function that returns a value) into a function that only returns | |
* a direct value. It does this by repeatedly evaluating the function if it | |
* returns a thunk, until a direct value is obtained. | |
* | |
* @template T The type of the value to be returned by the trampoline function. | |
* @template A The type tuple representing the argument types accepted by the | |
* function f. | |
* @param f A function that takes arguments of type A and returns either a |
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 { describe, it, expect, mock } from "bun:test"; | |
import { Timeout } from "./shared"; | |
describe("Timeout", () => { | |
it("should call the callback after a specific time", async () => { | |
expect.hasAssertions(); | |
return await new Promise<void>((resolve) => { | |
const start = Date.now(); | |
Timeout.set(() => { | |
expect(Date.now() - start).toBeGreaterThanOrEqual(100); |