Skip to content

Instantly share code, notes, and snippets.

@gatlin
gatlin / BiblePlan.hs
Last active June 14, 2026 02:14
(partially) vibe coded bible reading planner
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE GeneralisedNewtypeDeriving #-}
module BiblePlan where
import qualified Data.Time as T
import qualified Data.Time.Calendar.WeekDate as WD
import qualified Data.Text as T
import qualified Data.Vector as V
import Text.Printf (printf)
@gatlin
gatlin / uninstall-haskell-osx.sh
Last active October 18, 2025 20:23
Uninstall Haskell from Mac OS X
#!/bin/bash
# source: http://www.haskell.org/pipermail/haskell-cafe/2011-March/090170.html
sudo rm -rf /Library/Frameworks/GHC.framework
sudo rm -rf /Library/Frameworks/HaskellPlatform.framework
sudo rm -rf /Library/Haskell
rm -rf ~/.cabal
rm -rf ~/.ghc
rm -rf ~/Library/Haskell
@gatlin
gatlin / 1-js-lenses.md
Last active June 5, 2025 19:20
Simple implementation of lenses in JavaScript

What is a lens?

Note: you can copy the file 2-lenses.js below over to repl.it and play along from home!

A lens in programming, much like a lens in the real world, allows you to focus in on a small part of a larger whole and then do something with or to

@gatlin
gatlin / sat.hs
Created February 6, 2012 23:05
SAT Solver in Haskell
-- This is going to be on Hackage soon! https://github.com/gatlin/surely
{-# LANGUAGE BangPatterns #-}
-- |
-- Module : AI.Surely
-- Copyright : 2012 Gatlin Johnson
-- License : LGPL 3.0
-- Maintainer : rokenrol@gmail.com
-- Stability : experimental
@gatlin
gatlin / nn_repa.hs
Last active March 14, 2025 14:54
Simple neural network with backpropagation in Haskell, using Repa. Inspired by: http://iamtrask.github.io/2015/07/12/basic-python-network/
{- cabal:
build-depends: base, repa, repa-algorithms
-}
{- To run:
1. Install Haskell tools (https://www.haskell.org/ghcup/)
2. cabal run Main.hs -- +RTS -s -}
module Main where
@gatlin
gatlin / cast.sh
Created July 19, 2019 17:22
Use VLC without a UI to cast videos to chromecast
#!/bin/bash
MEDIA_FILE="$1"
if [ -z "$1" ]; then
echo "Please specify a media file as the first argument."
exit 1
fi
CHROMECAST_IP4_ADDRESS="$2"
@gatlin
gatlin / expralgebra.ts
Last active October 8, 2024 00:26
Evaluate expressions with F-algebras in TypeScript
// inspiration:
// https://www.schoolofhaskell.com/user/bartosz/understanding-algebras
/**
* Higher-kinded Types.
* A higher-kinded type is a type that abstracts over some type that, in turn,
* abstracts over another type.
*
* To support them in TypeScript we have to write a few types first.
*/
declare const Type: unique symbol;
@gatlin
gatlin / typed-racket-monads.md
Last active September 24, 2024 16:43
A simple definition and demonstration of monads in Typed Racket

What the fuck is a monad?

Or: functor? I 'ardly know 'er!

Monads are difficult to explain without sounding either patronizing or condescending: I would sound patronizing if I came up with some facile analogy and I would be condescending to describe it categorically.

Instead, I'll frame a problem and piece-by-piece solve the problem with what will turn out to be a monad.

@gatlin
gatlin / lc3.hs
Last active October 19, 2023 07:45
Unfinished proof of concept LC3 emulator in Haskell. My strategy is to build an EDSL which can be built up programmatically.
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
import Prelude hiding (not,and,log)
import Control.Monad
import Control.Monad.State
import Control.Monad.Free
import Control.Monad.Trans
import Control.Monad.Writer
import qualified Data.Vector.Unboxed as U
'use strict';
let str = "the quick brown fox jumps over the lazy dog";
let fw = Array.prototype.map
.call(str, (c) => c === ' '
? ' '
: String.fromCodePoint(c.codePointAt(0) + 0xFEE0))
.join('');
console.log(fw);