Skip to content

Instantly share code, notes, and snippets.

View yazaldefilimone's full-sized avatar
🍋
lemonc -o main.ln

Yazalde Filimone yazaldefilimone

🍋
lemonc -o main.ln
View GitHub Profile
// result: https://gist.github.com/yazaldefilimone/b1d3749def942013ee5128161837432e
import { Err, Ok, type Result } from "~/utils/result";
export async function safeAsync<T>(asyncFn: () => Promise<T>): Promise<Result<T, Error>> {
try {
const result = await asyncFn();
return Ok(result);
} catch (error) {
return Err(normalizeError(error));
export type Either<L, R> = Left<L, R> | Right<L, R>;
export class Left<L, R> {
constructor(private readonly _value: L) {}
isLeft(): this is Left<L, R> {
return true;
}
isRight(): this is Right<L, R> {
export type Maybe<T> = T | null;
export class Result<T, E extends Error = Error> {
private readonly value: Maybe<T>;
private readonly error: Maybe<E>;
private constructor(value: Maybe<T>, error: Maybe<E>) {
this.value = value;
this.error = error;
@yazaldefilimone
yazaldefilimone / pr.md
Created October 16, 2024 13:10 — forked from piscisaureus/pr.md
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = [email protected]:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@yazaldefilimone
yazaldefilimone / how-to-use.tsx
Last active October 16, 2024 13:01
useWorker.tsx
async function executeWorker(): Promise<string> {
const fakePromise = new Promise<string>((resolve) => {
setTimeout(() => {
resolve('Hi, its me!');
}, 8000);
});
return await fakePromise;
}
class Result<T, E> {
private readonly value: T | null;
private readonly error: E | null;
private constructor(value: T | null, error: E | null) {
this.value = value;
this.error = error;
}
static ok<T, E = never>(value: T): Result<T, E> {
// Nat
type Nat = { kind: "zero" } | { kind: "suc"; pred: Nat };
const zero: Nat = { kind: "zero" };
const suc = (n: Nat): Nat => ({ kind: "suc", pred: n });
const add = (a: Nat, b: Nat): Nat => {
if (a.kind === "zero") return b;
return suc(add(a.pred, b));
};
ast.exe: ast.c
gcc -Werror -Wswitch -Wimplicit-fallthrough ast.c -o ast.exe
clean:
rm -f *.o *.exe *.s a.out
test.s: ast.exe
./ast.exe > test.s
impl<V: Value> core::str::FromStr for NonNormalizingDec<V> {
type Err = &'static str;
#[inline(never)]
#[rustfmt::skip]
fn from_str(s: &str) -> Result<Self, Self::Err> {
/// Converts an ASCII decimal digit to an int.
///
/// In release builds, no range checks are performed and passing a
/// non-digit character will result is undefined (yet safe) behavior.