Skip to content

Instantly share code, notes, and snippets.

@jtobin
jtobin / flake.nix
Created November 28, 2025 17:25
taproot-assets flake
{
description = "taproot-assets";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
@jtobin
jtobin / CRP.hs
Created September 2, 2024 13:00
Chinese Restaurant Process in an embedded language with recursion schemes
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE LambdaCase #-}
import Control.Monad.Free
import qualified Control.Monad.Trans.Free as TF
import qualified Data.Foldable as F
import qualified Data.List as L
import Data.Functor.Foldable
import qualified System.Random.MWC.Probability as MWC
import qualified Data.IntMap.Strict as IMS
@jtobin
jtobin / up-bench.hoon
Last active August 26, 2021 22:17
+up benchmarks
:- %say
|= $: *
[ben=?(%put %vip %get %bot %del) ~]
[min=(list (pair @ @)) mit=(pry @ _~) nit=_| ~]
==
:- %noun
:: +up benchmarks
::
=/ pi (up @ _~)
::
@jtobin
jtobin / error.log
Created July 9, 2019 08:35
~zod testnet scrollback
worker_send_replace 47276 hole
worker_send_replace 47276 crud
%hole event failed:
bail: exit
/:<[18.151 15].[18.169 27]>
/:<[18.152 15].[18.169 27]>
/:<[18.153 15].[18.169 27]>
/:<[18.153 31].[18.153 46]>
/:<[18.224 3].[18.237 13]>
/:<[18.225 3].[18.237 13]>
@jtobin
jtobin / CPS.hs
Created August 4, 2018 23:35
Some CPS transformations.
-- see: http://matt.might.net/articles/cps-conversion
{-# OPTIONS_GHC -Wall #-}
{-# LANGUAGE OverloadedStrings #-}
import Data.Monoid
import Data.Text (Text)
import qualified Data.Text as T
import Data.Unique
import qualified Text.PrettyPrint.Leijen.Text as PP
@jtobin
jtobin / speedy.hs
Last active November 12, 2016 06:15
such speed
import Data.Vector.Unboxed as U
import System.Random.MWC
main :: IO ()
main = withSystemRandom . asGenIO $ \gen -> do
x <- uniformVector gen 10000000 :: IO (U.Vector Double)
print (U.sum x)
-- jtobin@castor:~/sandbox$ time ./Rand +RTS -s
-- 4999721.338394913
@jtobin
jtobin / optimizing.hs
Created October 28, 2016 07:18
Tweaking comonadic inference for performance
{-# OPTIONS_GHC -Wall #-}
{-# OPTIONS_GHC -fno-warn-type-defaults #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
import Control.Comonad
import Control.Comonad.Cofree
@jtobin
jtobin / pp-comonad.hs
Created October 27, 2016 00:57
Probabilistic programming using comonads.
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
import Control.Comonad
import Control.Comonad.Cofree
import Control.Monad
import Control.Monad.ST
@jtobin
jtobin / Prob.hs
Created October 18, 2016 08:52
A simple embedded probabilistic programming language
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE LambdaCase #-}
import Control.Monad
import Control.Monad.Free
import qualified System.Random.MWC.Probability as MWC
data ModelF r =
BernoulliF Double (Bool -> r)
| BetaF Double Double (Double -> r)
@jtobin
jtobin / Metropolis.hs
Created October 1, 2016 11:13
A Metropolis sampler.
module Metropolis where
import Control.Monad
import Control.Monad.Primitive
import System.Random.MWC as MWC
import System.Random.MWC.Distributions as MWC
propose :: [Double] -> Gen RealWorld -> IO [Double]
propose location gen = traverse (perturb gen) location where