Skip to content

Instantly share code, notes, and snippets.

@maiah
maiah / ProgressBar.astro
Created July 14, 2026 23:41
Astro Top Bar Loader
---
// src/components/ProgressBar.astro
---
<div id="top-progress-bar"></div>
<style is:global>
#top-progress-bar {
position: fixed;
top: 0;
@maiah
maiah / ClientRouterWithCache.astro
Created July 14, 2026 23:34
Astro Client Router with Cache
---
import { ClientRouter } from "astro:transitions";
---
<ClientRouter />
<script>
import { pathCache } from "./path-cache";
document.addEventListener("astro:before-preparation", (ev) => {
@maiah
maiah / create-route.ts
Last active July 14, 2026 23:35
Astro Create Route for Client routing
import type { z } from "astro/zod";
type ExtractParams<T extends string> =
T extends `${string}[${infer Param}]${infer Rest}`
? { [K in Param | keyof ExtractParams<Rest>]: string }
: {};
type IsEmptyObject<T> = keyof T extends never ? true : false;
type HrefArgs<T extends string, S extends z.ZodTypeAny | undefined> =
@maiah
maiah / spawn.ts
Last active July 2, 2026 04:19
Spawn
import { Semaphore } from "es-toolkit";
const totalCpuCores = 8; // TODO: Should be set to total number of cpu cores
const totalClients = Math.ceil(totalCpuCores * 1.5); // We want to have more clients than the number of cpu cores to avoid starvation
const lock = new Semaphore(totalClients);
class RpcClient {
createAccount(name: string): Promise<string> {
return Promise.resolve(`Account ${name} created`);
@maiah
maiah / main.go
Last active April 7, 2016 05:41
Syncing and Cancellable gophers
package main
import (
"errors"
"sync"
"time"
)
func main() {
sm := NewSyncedMessage("abc")
@maiah
maiah / pokemon.js
Last active December 10, 2015 01:22
Pokemon evolution with Javascript streams
'use strict';
const f = require('from');
const t = require('through');
const pokemons = f(['charmander', 'bulbasaur', 'squirtle']);
const evolve = t((pokemon) => {
'use strict';
let evolvedPokemon = pokemon;
defmodule P2 do
def num_to_list(mx) do
if mx > 1 do
Enum.reduce(1..mx, fn (x, acc) -> "#{acc},#{x}" end)
else
"#{mx}"
end
end
defmodule P2 do
def num_to_list(mx) when mx > 1 do
num_to_list(mx, mx - 1)
end
def num_to_list(mx) do
"#{mx}"
end
@maiah
maiah / main.go
Last active October 26, 2015 08:14
Beautiful Streaming Filter, Map, and Collect using Channel Struct-wrapper
package main
import (
"fmt"
"strconv"
)
type Power struct {
up int
}
@maiah
maiah / main.go
Last active October 20, 2015 23:50
Reader wrapper to have functional programming style of reading io (no mutables)
package main
import (
"fmt"
"io"
"os"
)
func main() {
f, err := os.Open("./temp")