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
#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 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 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 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 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); |
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 enum Ordering { | |
Less = -1, | |
Equal = 0, | |
Greater = 1, | |
} | |
export interface Eq<T> { | |
eq(other: T): boolean; | |
} |
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 default function createPartialApplication<T extends any[], R>( | |
fn: (...args: T) => R, | |
): PartialApplication<T, R> { | |
return function accumulator(...args1: any[]): any { | |
return args1.length >= fn.length | |
? fn(...(args1 as T)) | |
: (...args2: any[]) => accumulator(...args1.concat(args2)); | |
}; | |
} |
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
use std::collections::HashSet; | |
use std::iter::Peekable; | |
use std::str::Chars; | |
#[derive(Debug, PartialEq, Clone)] | |
enum Token { | |
Lambda, | |
Dot, | |
Variable(String), | |
LParen, |
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
use std::collections::HashSet; | |
use std::iter::Peekable; | |
use std::str::Chars; | |
#[derive(Debug, PartialEq, Clone)] | |
enum Token { | |
Lambda, | |
Dot, | |
Variable(String), | |
LParen, |
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
#include <stdio.h> | |
#include <stdint.h> | |
uint8_t da(uint8_t value) { | |
uint8_t lo = value & 0x0F; | |
uint8_t hi = value >> 4; | |
if (lo > 9) lo += 6; | |
if (hi > 9) hi += 6; | |
return (hi << 4) | lo; | |
} |
NewerOlder