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://s3.console.aws.amazon.com/s3/buckets/<bucket-name> |
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 utils | |
| import ( | |
| "fmt" | |
| "sync" | |
| ) | |
| type result[T any] struct { | |
| value T | |
| err error |
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
| type Tunnel[T any] struct { | |
| ch chan T | |
| } | |
| func (t *Tunnel[T]) Send(ctx context.Context, value T) error { | |
| select { | |
| case t.ch <- value: | |
| return nil | |
| case <-ctx.Done(): | |
| return ctx.Err() |
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
| async function* readLines(stream: ReadableStream<Uint8Array>) { | |
| const reader = stream.getReader(); | |
| let buffer = '' | |
| try { | |
| while (true) { | |
| const { done, value } = await reader.read(); | |
| if (value !== undefined) { | |
| buffer += new TextDecoder().decode(value) |
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
| func Must[T any](obj T, err error) T { | |
| if err != nil { | |
| panic(err) | |
| } | |
| return obj | |
| } |
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 threading | |
| import time | |
| from typing import Callable, TypeVar, Generic, Any, Dict, Tuple, List | |
| T = TypeVar("T") | |
| class TTLCache(Generic[T]): | |
| def __init__( |
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
| def stopwatch(): | |
| def decorator(func): | |
| def wrapper(*args, **kwargs): | |
| start_time = time.time() | |
| result = func(*args, **kwargs) | |
| end_time = time.time() | |
| elapsed_time = end_time - start_time | |
| print(f"time taken {elapsed_time: 2f}") | |
| return result |
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 * as crypto from 'crypto' | |
| const delimiter = '\0' | |
| export function getFilesHash(files: { name: string; content: string }[]) { | |
| const shasum = crypto.createHash('sha1') | |
| files.forEach(({ name, content }) => { | |
| shasum.update(name) | |
| // Add delimiter to hash to prevent collisions between files where the join of the name and content is the same |
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
| node -e "console.log(require('crypto').randomBytes(64).toString('hex'))" |
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 random | |
| import string | |
| characters = string.ascii_letters + string.digits | |
| def id(length: int): | |
| return "".join(random.choices(characters, k=length)) |
NewerOlder