Skip to content

Instantly share code, notes, and snippets.

View rossrobino's full-sized avatar

Ross Robino rossrobino

View GitHub Profile
@rossrobino
rossrobino / actions.ts
Created January 13, 2025 22:13
Next.js form with useActionState and useOptimistic
"use server";
export async function submitAction(
previousState: { count: FormDataEntryValue | null },
formData: FormData,
) {
// delay
await new Promise((res) => setTimeout(res, 1000));
const name = formData.get("name");
@rossrobino
rossrobino / djb2.ts
Last active October 7, 2024 18:47
DJB2 Hash
/**
* Fast hashing algorithm for generating etags
* http://www.cse.yorku.ca/~oz/hash.html
*
* taken from sveltekit
* https://github.com/sveltejs/kit/blob/25d459104814b0c2dc6b4cf73b680378a29d8200/packages/kit/src/runtime/hash.js
*/
const djb2 = (...values: (string | ArrayBufferView)[]) => {
let hash = 5381;