Skip to content

Instantly share code, notes, and snippets.

View danybeltran's full-sized avatar

Dany Beltran danybeltran

  • El Salvador
View GitHub Profile
@danybeltran
danybeltran / storable.ts
Created March 27, 2024 17:02
Create a Writable localStorage store that allows both updating and reading by subscription
import { writable } from 'svelte/store'
const storedKeys: any = {}
/**
* Create a Writable localStorage store that allows both updating and reading by subscription
*/
export function storable<T>(initialValue: T) {
const storedKey = `$-${Object.keys(storedKeys).length}`
@danybeltran
danybeltran / search-params.php
Last active October 12, 2024 04:30
PHP search params
<?php
/**
* Gets the URL search params.
*
* @param string $url The URL to parse. If no URL is passed, `$_SERVER["REQUEST_URI"]` will be used instead
* @param bool $arrays If false, search params that are added at the end will overwrite any existing values
*/
function getQuery(string $url = "", bool $arrays = true)
@danybeltran
danybeltran / store.ts
Last active December 13, 2024 19:32
Boilerplate for a state management library with React.useSyncExternalStore
import { useSyncExternalStore } from "react"
const cache = new Map()
function defaultActions() {
return {}
}
type StateType<R, actionsType> = {
key: string
@danybeltran
danybeltran / index.ts
Last active December 25, 2024 06:59
All shadcn components
export * from './sidebar'
export * from './accordion'
export * from './alert'
export * from './alert-dialog'
export * from './aspect-ratio'
export * from './avatar'
export * from './badge'
export * from './breadcrumb'
export * from './button'
export * from './calendar'