Skip to content

Instantly share code, notes, and snippets.

@levelsio
levelsio / 💁‍♀️ Karen Bot by @levelsio
Last active March 3, 2026 14:30
💁‍♀️ Karen Bot is an AI robot that lets you report problems in your neighborhood or city to your local city council
<?php
// Karen Bot by @levelsio
//
// ask Claude Code or Cursor to adapt it to your city
// mine is for Lisbon in Portuguese but it should work with any city and any language!
// save it as council.php and add a Nginx route /council on your server to use it
// make sure to add /council?key= and set a key below to use it privately
//
// more info: https://x.com/levelsio/status/2009011216132526407?s=20
import { FormError } from '$lib/errors.js';
import { db } from '$lib/server/db.js';
import { GROUP_QUERY } from '$lib/server/queries/group.query.js';
import {
expenses_table,
group_members_table,
ledger_table,
users_table,
} from '$lib/server/schema.js';
import { listify_names, sum_arr } from '$lib/utils.js';
@devagrawal09
devagrawal09 / dev's store.ts
Last active January 31, 2023 19:12
Simple reactive store for state management
export type QueryStatus = "loading" | "error" | "success";
export type ReadonlyStore<T> = {
getState: () => T;
subscribe: (
listenerOrStore: ((state: T) => void) | Store<any>
) => () => void;
};
export type Store<T> = ReadonlyStore<T> & {
setState: (newStateOrReducer: T | ((state: T) => T)) => void;
import { z } from 'zod'
export function preprocessFormData<Schema extends z.ZodTypeAny>(
formData: FormData,
schema: Schema,
) {
const shape = getShape(schema)
return mapObj(shape, ([name, propertySchema]) =>
transformFormDataValue(
getFormValue(formData, String(name), propertySchema),
import { Router } from 'next/router';
import { useEffect } from 'react';
import { publicConfig } from '~/shared/config';
import { trpc } from '~/utils/trpc';
let initVersion = publicConfig.GIT_COMMIT;
function useDetectVersionChange() {
const healthQuery = trpc.health.useQuery(undefined, {
refetchInterval: 10_000,
@jacob-ebey
jacob-ebey / deferred-overview.md
Last active February 28, 2025 05:42
Deferred Overview

Remix Deferred

Remix Deferred is currently implemented on top of React's Suspense model but is not limited to React. This will be a quick dive into how "promise over the wire" is accomplished.

SSR + Hydration

It isn't rocket science, but a quick recap of how frameworks such as react do SSR:

  1. Load data
  2. Render the app
/**
* @link https://raw.githubusercontent.com/NaturalCycles/js-lib/master/src/promise/pProps.ts
* Promise.all for Object instead of Array.
*
* Inspired by Bluebird Promise.props() and https://github.com/sindresorhus/p-props
*
* Improvements:
*
* - Exported as { promiseProps }, so IDE auto-completion works
@jozanza
jozanza / borshDecoder.ts
Last active February 9, 2022 12:30
Borsh parsing is really pretty simple
// https://gist.github.com/diafygi/90a3e80ca1c2793220e5/
const B58_CHARS = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
// prettier-ignore
const toBase58: (buf: Uint8Array, map?: string) => string = (B: any, A: any = B58_CHARS) => {let d: any = [], s = '', i: any, j: any, c, n; for(i in B){j=0,c=B[i];s+=c||s.length^i?"":1;while(j in d||c){n=d[j];n=n?n*256+c:c;c=n/58|0;d[j]=n%58;j++}}while(j--)s+=A[d[j]];return s;}
export const toJSON = (data: any) => {
return JSON.stringify(
data,
(_key, value) => (typeof value === 'bigint' ? value.toString() : value),
2,
@kentcdodds
kentcdodds / session.server.ts
Created November 18, 2021 21:04
Authentication in Remix applications
import * as bcrypt from "bcrypt";
import { createCookieSessionStorage, redirect } from "remix";
import { db } from "./db.server";
export type LoginForm = {
username: string;
password: string;
};
@intergalacticspacehighway
intergalacticspacehighway / useKeyboardBottomInset hook
Created August 10, 2021 04:54
Hook to get keyboard height in React Native and add bottom/padding inset on a view.
import { Keyboard, Platform, KeyboardEvent } from 'react-native';
const useKeyboardBottomInset = () => {
const [bottom, setBottom] = React.useState(0);
const subscriptions = React.useRef([]);
React.useEffect(() => {
function onKeyboardChange(e) {
if (
e.startCoordinates &&