Skip to content

Instantly share code, notes, and snippets.

View hallettj's full-sized avatar

Jesse Hallett hallettj

View GitHub Profile
@hallettj
hallettj / tree-no_classes.js
Last active October 22, 2021 15:14
Algebraic data type in Javascript with Flow
/* @flow */
type Tree<T> =
| { type: "Node", value: T, left: Tree<T>, right: Tree<T> }
| { type: "EmptyTree" }
function find<T>(p: (v: T) => boolean, t: Tree<T>): T | void {
var l, v
if (t.type === "Node") {
@hallettj
hallettj / Cat.lidr
Last active April 2, 2018 15:05
description of category laws in Idris
# Category Theory proofs in Idris
Idris is a language with dependent types, and is similar to Agda.
What distinguishes Idris is that it is intended to be a general-purpose language first,
and a theorem prover second.
To that end it supports optional totality checking
and features to support writing DSLs:
type classes,
do notation,
monad comprehensions (i.e., a more general form of list comprehension),
@hallettj
hallettj / Logic.idr
Created April 18, 2014 20:56
basic mathematical logic in Idris
module Logic
infixr 1 ==>
(==>) : Bool -> Bool -> Bool
False ==> _ = True
True ==> x = x
data Exists : (A : Type) -> (P : A -> Bool) -> Type where
exists : {A : Type} -> {P : A -> Bool} -> (a : A) -> so (P a) -> Exists A P

Keybase proof

I hereby claim:

  • I am hallettj on github.
  • I am hallettj (https://keybase.io/hallettj) on keybase.
  • I have a public key whose fingerprint is A378 B079 9F05 93C0 B499 DD02 8FB4 E35F E86B 913B

To claim this, I am signing this object:

@hallettj
hallettj / array_monad.js
Created March 28, 2014 08:03
Trying to apply ES6 generators to create monad comprehensions. Unfortunately it looks like this will not work with monads that contain multiple values, such as arrays.
/*
* The implementation
*/
function du(comprehension) {
return function(/* args */) {
var gen = comprehension.apply(null, arguments)
return next();
function next(v) {
@hallettj
hallettj / tmux.conf .sh
Last active August 29, 2015 13:57
tmux key bindings to run common git commands in a new split
# open vim in a new split
bind e split-window -h -c "#{pane_current_path}" sensible-editor
# shortcuts for common git operations
bind g split-window -h -c "#{pane_current_path}" 'GIT_PAGER="less -+F" git lg'
bind D split-window -h -c "#{pane_current_path}" 'GIT_PAGER="less -+F" git diff'
bind C split-window -h -c "#{pane_current_path}" 'GIT_PAGER="less -+F" git diff --cached'
bind A split-window -h -c "#{pane_current_path}" 'git add -p'
@hallettj
hallettj / 1. xmodmap .f90
Last active May 7, 2024 03:04
I inverted the number row on my keyboard - meaning that pressing the keys produces symbols by default, and I type numbers by holding shift. As a programmer I use symbols frequently, so I think that this will be advantageous. Here are the details of my configuration.
!
! Invert number row
!
! This changes the behavior of keys in the number row, but does not
! affect the number pad.
!
keycode 10 = exclam 1 1 exclam
keycode 11 = at 2 2 at
keycode 12 = numbersign 3 3 numbersign
keycode 13 = dollar 4 4 dollar
import Control.Applicative ((<$>), (<*>))
import Control.Concurrent.Async (Concurrently(..), runConcurrently)
import Data.Monoid (Monoid, (<>), mappend, mempty)
instance (Monoid a) => Monoid (IO a) where
mappend x y = runConcurrently $ (<>) <$> Concurrently x <*> Concurrently y
mempty = return mempty
-- example:
action = getLine <> getLine
@hallettj
hallettj / mkManifest.js
Last active December 28, 2015 09:39
Substack Rube Goldburg Challenge: runs some input through as many of substack's npm modules as possible.
var fs = require('fs');
var exec = require('child_process').exec;
var templ_ = fs.readFileSync('package.json.template', { encoding: 'UTF-8' });
var templ = JSON.parse(templ_);
var deps = {};
exec("npm search substack | grep '=substack' | awk '{ print $1 }'", function(err, stdout) {
var lines = stdout.toString('UTF-8');
lines.split("\n").forEach(function(line) {
@hallettj
hallettj / mori.markdown
Created October 25, 2013 21:57
Functional data structures in JavaScript with Mori

Functional data structures in JavaScript with Mori

http://swannodette.github.io/mori/

the basic immutable structure: list

var l0 = mori.list(3, 4, 5);

var l1 = mori.cons(2, l0);