Skip to content

Instantly share code, notes, and snippets.

View jgrimes's full-sized avatar

Justin Grimes jgrimes

  • Durham, North Carolina
View GitHub Profile
@jgrimes
jgrimes / Job.hs
Created November 9, 2017 14:16
simple example of type safe deserialization + dynamic dispatch
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE ExistentialQuantification #-}
module Job where
import Data.Serialize (Serialize, encode, decode)
import Data.Typeable
import GHC.Generics
import Control.Monad (join)
import qualified Data.ByteString as B
@jgrimes
jgrimes / trampoline.clj
Created October 6, 2016 20:30
Trampolined Style in Clojure
#!/usr/bin/env boot
;;
;; Threads & concurrency without hardware threads or continuations
;;
;; Most of this is from the paper "Trampolined Style" by Ganz, Friendman, and Wand
;;
(defrecord Done [value])
(defrecord Doing [thunk])
@jgrimes
jgrimes / boot.go
Last active January 3, 2016 18:02
modified boot.go to run a script
package main
import (
"fmt"
"github.com/jackpal/bencode-go"
"net"
"os"
"path/filepath"
"strconv"
"strings"
@jgrimes
jgrimes / gist:c0e048c8a0b8bc9efd7b
Last active August 29, 2015 14:16
reducing multiple functions
lambda.match> (time (sidelong-count-and-sum (range 100000000)))
"Elapsed time: 89361.517429 msecs"
[100000000 4999999950000000]
lambda.match> (time (reduce #((juxt
(partial (fn [x y] (+ x 1)) (first %)) ; count
(partial + (second %))) ; sum
%2)
[1 0]
(range 1 100000000)))
module Main where
import Control.Monad
import Data.List
import Data.Char (intToDigit)
perms xs n = do
l <- replicateM n xs
guard (length l <= n)
let z = do x <- [0..(n - 1)]