Skip to content

Instantly share code, notes, and snippets.

package examples
import (
"github.com/XANi/loremipsum"
"github.com/go-chi/chi/v5"
. "github.com/starfederation/datastar-dev/site/shared"
datastar "github.com/starfederation/datastar/sdk/go"
"math/rand/v2"
"net/http"
"time"
@elithrar
elithrar / index.html
Created February 25, 2025 14:27
Claude 3.7 + building Cloudflare Agents using the agents-sdk
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Simple Cloudflare Agent Chat</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 800px;
@AlperRehaYAZGAN
AlperRehaYAZGAN / golang-like-error-helper.ts
Last active April 22, 2025 21:12
a simple golang error returner like helper function in javascript https://www.npmjs.com/package/promise-like-go
// executeAsync is golang like function that returns [result,err] pair.
export async function executeAsync<T>(fn: () => Promise<T>): Promise<[T | null, any]> {
try {
const result = await fn();
return [result, null];
} catch (error) {
return [null, error];
}
}
@t3dotgg
t3dotgg / try-catch.ts
Last active July 3, 2025 10:47
Theo's preferred way of handling try/catch in TypeScript
// Types for the result object with discriminated union
type Success<T> = {
data: T;
error: null;
};
type Failure<E> = {
data: null;
error: E;
};
@guilhermerodz
guilhermerodz / settings.json
Last active February 26, 2025 19:44
Tailwind Styled Utility inspired by styled-components and emotion
// .vscode/settings.json
{
"tailwindCSS.experimental.classRegex": [
["cva\\(([^)]*)\\)", "[\"'`]([^\"'`]*).*?[\"'`]"],
["cn\\(([^)]*)\\)", "(?:'|\"|`)([^']*)(?:'|\"|`)"],
["styled\\(([^)]*)\\)", "(?:'|\"|`)([^']*)(?:'|\"|`)"]
],
}
@dhh
dhh / linux-setup.sh
Last active June 7, 2025 21:00
linux-setup.sh
# THIS LINUX SETUP SCRIPT HAS MORPHED INTO A WHOLE PROJECT: HTTPS://OMAKUB.ORG
# PLEASE CHECKOUT THAT PROJECT INSTEAD OF THIS OUTDATED SETUP SCRIPT.
#
#
# Libraries and infrastructure
sudo apt update -y
sudo apt install -y \
docker.io docker-buildx \
build-essential pkg-config autoconf bison rustc cargo clang \
@KristofferEriksson
KristofferEriksson / useGesture.ts
Created February 7, 2024 10:27
A custom React Typescript hook for advanced touch gestures in UI
import { useEffect, useRef } from "react";
type GestureType =
| "swipeUp"
| "swipeDown"
| "swipeLeft"
| "swipeRight"
| "tap"
| "pinch"
| "zoom";
@AndrewIngram
AndrewIngram / CurrentTime.tsx
Created November 21, 2023 00:04
Current time in React without hydration errors
import { Suspense } from "react";
import CurrentTimeClient from "./CurrentTimeClient";
export default function CurrentTime() {
const locale = "en-GB";
const dateConfig = {
hour: "numeric",
minute: "numeric",
second: "numeric",
import * as React from 'react';
const useIsFirstRender = (): boolean => {
const isFirst = React.useRef(true);
if (isFirst.current) {
isFirst.current = false;
return true;
} else {
@trvswgnr
trvswgnr / concurrency.js
Last active January 20, 2024 09:29
run up to n concurrently, catching and returning errs
async function processItems(items, fn) {
const errs = [];
let i = 0;
const workers = Array(25)
.fill()
.map(async () => {
while (i < items.length) {
await fn(items[i++]).catch((e) => errs.push(e));
}
});