Skip to content

Instantly share code, notes, and snippets.

@bradparker
bradparker / .envrc
Last active February 26, 2025 06:13
Nix development shell with PostgreSQL management scripts
use flake
export PGDATA=$PWD/database/pgdata
export PGHOST="localhost"
export PGPORT="5432"
export PGDATABASE="my-wonderful-database"
export PGUSER="postgres"
export PGPASSWORD="password"
@bradparker
bradparker / Lehmer.hs
Last active June 22, 2025 11:54
Lehmer.hs
module Books where
import qualified Data.Aeson as Aeson
import Data.List (elemIndex, uncons, unfoldr)
import qualified Data.List as List
import Data.Map (Map)
import qualified Data.Map as Map
import Data.Maybe (mapMaybe)
import Data.Vector (Vector, (!))
import qualified Data.Vector as Vector
@bradparker
bradparker / librarything-export-to-table
Last active November 6, 2024 12:13
LibraryThing JSON export to Table
#! /usr/bin/env nix-shell
#! nix-shell -i bash -p jq dasel
jq \
'[.[] | { code: .ddc.code[0], author: .primaryauthor, title: .title }] | sort_by(.code)' \
< $1 | dasel -r json -w csv
@bradparker
bradparker / discriminatedChunks.ts
Last active December 15, 2023 02:54
Chunk array of discriminated union by discriminant?
const isDiscriminant = <TypeName extends string, T extends { type: TypeName }>(
type: TypeName,
candidate: { type: string }
): candidate is T => type === candidate.type;
type Chunk<
TypeName extends string,
T extends { type: TypeName } = any & { type: TypeName }
> = {
type: TypeName;
@bradparker
bradparker / app.ts
Last active November 14, 2023 12:11
React?
import { useState, createElement as h, render, type Element } from "./index.js";
const Counters = () => {
const [count, setCount] = useState(0);
return h(
"div",
{ style: "display: flex; flex-direction: column; gap: 1rem" },
h(
"div",
@bradparker
bradparker / recurrence.sql
Last active September 22, 2022 23:20
Spiking iCal recurrence rules in SQL
-- TODO: perhaps better approach is to generate a sequence of days,
-- weeks, months and years. Then join them.
--
-- TODO: I think I want the 'week of month' to work more like the
-- 'recurrence week index', in that it could still respect "real" weeks. I
-- think the same questions can be answered that way while being a little
-- less surprising (that a string of 7 1s doesn't mean Mon-Sun).
CREATE OR REPLACE FUNCTION recurrence_days (start_at timestamp, end_at timestamp, timezone text)
RETURNS TABLE (
@bradparker
bradparker / relation.rb
Last active June 1, 2022 04:22
Notes from going through Time and Relational Theory by C.J. Date, Hugh Darwen and Nikos A. Lorentzos
require "set"
module ArrayExtras
refine Array do
def second
self[1]
end
def split_at(i)
[first(i), drop(i)]
@bradparker
bradparker / .gitignore
Last active April 29, 2022 05:54
Streaming server
cabal.project.local
dist-newstyle
*.prof*
*.pem
*.html*
{-# LANGUAGE ExplicitForAll #-}
module Combinations (combinations) where
import Control.Arrow ((&&&))
import Control.Monad (replicateM)
import Control.Monad.State (StateT (StateT), evalStateT)
import Data.List (uncons, unfoldr)
unconses :: forall a. [a] -> [(a, [a])]
@bradparker
bradparker / Main.hs
Last active May 10, 2021 10:16
Learning about recursion schemes
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
module Main where