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 { useEffect, useState } from "react"; | |
import { Input } from "./ui/input"; | |
type Props = { | |
suggestions: string[]; | |
}; | |
export function AutosuggestionInput({ suggestions }: Props) { | |
const [input, setInput] = useState(""); | |
const [suggestion, setSuggestion] = useState(""); |
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 Result<T> = readonly [T, null] | readonly [null, 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
import { useState } from "react"; | |
export function useArrayState<T>(initialState: T[] = []) { | |
const [state, setState] = useState<T[]>(initialState) | |
const add = (newValue: T) => { | |
setState((currentState) => [...currentState, newValue]) | |
} | |
const remove = (index: number) => { | |
setState( | |
(currentState) => currentState.filter((_, i) => i !== index) |
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
export function download(blob: Blob, fileName: string) { | |
const blobURL = URL.createObjectURL(blob) | |
const link = document.createElement('a') | |
link.href = blobURL | |
link.download = fileName | |
link.click() | |
URL.revokeObjectURL(blobURL) | |
link.remove() | |
} |
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
export function parseCSV<T = Record<string, string>>({ | |
csv, | |
headers, | |
delimiter = "," | |
}: { | |
csv: string | |
delimiter?: string | |
headers?: string[] | |
}) { | |
const header = headers ?? csv.slice(0, csv.indexOf("\n")).split(delimiter) |
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 Led { | |
private: | |
int _pin; | |
int _state; | |
public: | |
Led(int pin, int state = LOW){ | |
_pin = pin; | |
_state = state; | |
pinMode(_pin, OUTPUT); | |
digitalWrite(_pin, _state); |
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
export default class AsyncQueue<T> { | |
private _items: Array<T> = [] | |
private _pending: ((value: T) => void) | null = null; | |
private wait() { | |
return new Promise<T>(resolve => { this._pending = resolve }) | |
} | |
enqueue(item: T) { | |
if (!this._pending) { | |
this._items.push(item) |
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
export class Duration { | |
private _value: number | |
private constructor(value: number) { | |
this._value = value | |
} | |
static miliseconds(value: number) { | |
return new Duration(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
export class ObjectStorage { | |
private buckets: ObjectStorageBucket[] = [] | |
constructor(public readonly storagePath: string) { | |
fs.ensureDirSync(storagePath) | |
} | |
createBucket(bucketName: string) { | |
this.buckets.push(new ObjectStorageBucket(this.storagePath, bucketName)) | |
} | |
getBucket(bucketName: string): ObjectStorageBucket | undefined { |
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 Result<T> { | |
private constructor( | |
private _value?: T, | |
private _error?: Error | |
) {} | |
static success<T>(value: T) { | |
return new Result(value, undefined) | |
} | |
static failure(err: Error) { | |
return new Result(undefined, err) |
NewerOlder