Skip to content

Instantly share code, notes, and snippets.

@gatlin
gatlin / uninstall-haskell-osx.sh
Last active April 11, 2024 22:31
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 February 11, 2024 04:27
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 / typed-racket-monads.md
Last active December 30, 2023 01:59
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
@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"
'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);
@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 / imperative.lhs
Last active April 20, 2023 00:51
Imperative Programming in Haskell
How to add imperative programming to a pure functional language
===
Many people bemoan languages such as Haskell for not supporting imperative
programming; they decry the need for math in their computer science.
![Math? In my computer? Yeah right.](http://i.imgur.com/YDIaEPB.jpg)
I'm here to tell you that not only does Haskell make imperative programming a
cinch, but safe and correct as well. Follow along! This post is written in
@gatlin
gatlin / ucv.sh
Last active January 12, 2023 16:09
unicode character viewer. download the unicode data txt file here: https://github.com/latex3/unicode-data/blob/main/UnicodeData.txt
#!/usr/bin/env bash
############################
# Unicode Character Viewer #
# v1.0 #
# ~*~*~*~*~*~*~*~*~*~*~*~* #
# Author: Gatlin Johnson #
# <gatlin@niltag.net> #
# ~*~*~*~*~*~*~*~*~*~*~*~* #
# Runtime dependencies: #
# - fzf #

Keybase proof

I hereby claim:

  • I am gatlin on github.
  • I am marcus4realius (https://keybase.io/marcus4realius) on keybase.
  • I have a public key whose fingerprint is 5B99 A8B5 30FB 7B4E 8676 A642 06EA 942B A243 5748

To claim this, I am signing this object: