Skip to content

Instantly share code, notes, and snippets.

@bradparker
bradparker / librarything-export-to-table
Created March 3, 2024 02:06
LibraryThing JSON export to Table
#! /usr/bin/env nix-shell
#! nix-shell -i bash -p jq dasel
jq \
'[.[] | { code: .ddc.code[0], code_description: .ddc.wording | (if . == null then null else (. | join(", ")) end), 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*
@bradparker
bradparker / dev
Last active January 8, 2022 02:23
Little typer notes
#!/usr/bin/env bash
main () {
local filename="the-little-typer.rkt"
tmux \
new-window "nix-shell --run 'vim $filename'"\; \
split-window "nix-shell --run 'entr -c racket $filename <<< $filename'"\; \
select-layout even-horizontal\; \
split-window -v "nix-shell --run 'racket -i'"
{-# 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
@bradparker
bradparker / Main.hs
Last active April 15, 2021 07:18
Some funny problem from a blog post (https://blog.ploeh.dk/2021/04/12/threading-context-through-a-catamorphism/). Excuse for recursion schemes
{-# LANGUAGE BlockArguments #-}
{-# OPTIONS_GHC -Wall #-}
-- nix-shell -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/bed08131cd29a85f19716d9351940bdc34834492.tar.gz -p 'haskellPackages.ghcWithPackages (p: [p.recursion-schemes])'
module Main where
import Control.Monad.Reader (Reader, asks, local, runReader)
import Data.Foldable (traverse_)
import Data.Functor.Base (TreeF (NodeF))