Skip to content

Instantly share code, notes, and snippets.

Issac Trotts ijt

  • Oakland, CA
Block or report user

Report or block ijt

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
ijt /
Created Feb 17, 2012
A binary heap in Python
class Heap(object):
def __init__(self, size):
self.num = 0
self.size = size = [None] * size
def __repr__(self):
return '<Thing: %s>' % (,)
def insert(arr, x):
ijt / bits.hs
Created Feb 14, 2012
Check that n & (n - 1) is non-zero for non-power-of-two numbers
View bits.hs
import Data.Bits ((.&.))
import Test.QuickCheck (Property, (==>))
prop_bits :: Int -> Property
prop_bits n = n > 0 ==> intToBool (n .&. (n - 1)) == not (isPowerOfTwo n)
intToBool 0 = False
intToBool _ = True
isPowerOfTwo :: Int -> Bool
ijt / median.hs
Created Feb 14, 2012
Print the median of a newline-separated list of numbers
View median.hs
#!/usr/bin/env runhaskell
import Data.List (sort, (\\))
import Test.QuickCheck (Property, (==>))
main = interact (showLn . median . map read . lines)
showLn :: Show a => a -> String
showLn x = show x ++ "\n"
ijt / random_monad_example.hs
Created Oct 3, 2011
Example of how to use the Random monad in Haskell
View random_monad_example.hs
-- cabal install MonadRandom
-- ghc random_monad_example
-- ./random_monad_example
-- The code here is stolen from a comment in the MonadRandom source code.
import Control.Monad.Random
die :: RandomGen g => Rand g Int
die = getRandomR (1,6)
ijt / qc_test.go
Created Aug 2, 2011
Quickcheck of sorting idempotency in Go (golang)
View qc_test.go
package main
import (
type IntSlice []int
ijt / tailf.hs
Created Jun 30, 2011
Haskell example of tailing a file
View tailf.hs
#!/usr/bin/env runhaskell
-- Example of tailing a file, using two communicating Haskell threads. It's not
-- really necessary to do this concurrently, but the approach here generalizes
-- nicely if we want to filter or transform the output.
import Control.Concurrent
import Control.Monad
import System.Environment
import System.Exit
ijt / logging_example.hs
Created Jun 29, 2011
Example of logging in Haskell
View logging_example.hs
#!/usr/bin/env runhaskell
-- This example uses the hslogger library.
-- For debugging it may be more convenient to use Debug.Trace instead since that
-- allows you to log debugging output from otherwise pure functions.
import System.IO (stderr, Handle)
import System.Log.Logger (rootLoggerName, setHandlers, updateGlobalLogger,
Priority(INFO), Priority(WARNING), infoM, debugM,
warningM, errorM, setLevel)
ijt / demux.hs
Created Jun 28, 2011
Haskell program to demux input
View demux.hs
#!/usr/bin/env runhaskell
import System.Environment
import System.Exit
import System.IO
usage = "usage: cat somefile | demux outfile1 outfile2 ..."
help = "This program alternates sending its input to outfile1 and outfile2."
main = do
ijt / ijt_hoogle.vim
Created Jun 5, 2011
Hoogle plugin for Haskell in Vim
View ijt_hoogle.vim
" $ cabal install hoogle
" Then put this file in ~/.vim/ftplugin/haskell/ijt_hoogle.vim
" Put your cursor over a function name and press \h to find out
" its signature and where it is defined.
command! Hoogle :exec("!hoogle '" . expand("<cWORD>") . "'")
map \h :Hoogle<CR>
ijt / panic_example.go
Created May 24, 2011
Example of exception handling in Go
View panic_example.go
// Exception handling example, fleshed out from Rob Pike's post
// at
package main
import "fmt"
func f(dopanic bool) {
defer func() {
if x := recover(); x != nil {
You can’t perform that action at this time.