Skip to content

Instantly share code, notes, and snippets.

View lucashcl's full-sized avatar
🔎

Lucas Cipriano Lima lucashcl

🔎
View GitHub Profile
@lucashcl
lucashcl / autosuggestionsInput.tsx
Created June 17, 2025 23:44
Shadcn Autosuggestion Input
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("");
@lucashcl
lucashcl / Result.ts
Created June 11, 2025 17:19
Result type
type Result<T> = readonly [T, null] | readonly [null, Error]
@lucashcl
lucashcl / useArrayState.ts
Created February 5, 2025 19:31
UseArrayState react hook
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)
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()
}
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)
@lucashcl
lucashcl / Led.cc
Last active January 28, 2025 19:40
Led class for arduino
class Led {
private:
int _pin;
int _state;
public:
Led(int pin, int state = LOW){
_pin = pin;
_state = state;
pinMode(_pin, OUTPUT);
digitalWrite(_pin, _state);
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)
export class Duration {
private _value: number
private constructor(value: number) {
this._value = value
}
static miliseconds(value: number) {
return new Duration(value)
}
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 {
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)