Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

bfs :: Tree a -> [a]
bfs t =
concatMap (map rootLabel) $
takeWhile (not . null) $
iterate (concatMap subForest) [t]
module Bunrui.Core
( Command
, Metadata(..)
, Opts(..)
, findSourceFiles
, missingDirectories
, readMetadata
) where
import Control.Applicative ((<$>), (<*), (<*>))
@trevorc
trevorc / ringbuffer.clj
Created March 15, 2012 07:37
Persistent Ring Buffer
(ns com.caira.util.ringbuffer
(:import (clojure.lang Counted IPersistentCollection IPersistentVector
Indexed RT SeqIterator Seqable Util)
(java.util Collection List)))
(defn ^:private iterables-equiv? [^Iterable i1 ^Iterable i2]
(let [it1 (.iterator i1)
it2 (.iterator i2)]
(loop []
(or (not (.hasNext it1))
@trevorc
trevorc / defwith.clj
Created March 23, 2012 19:24
defwith -- sugar for try-finally macros
(defmacro defwith [name finalizer]
(let [bindings-sym (gensym "bindings")
body-sym (gensym "body")]
`(defmacro ~name [~bindings-sym & ~body-sym]
(cond
(empty? ~bindings-sym) `(do ~@~body-sym)
(symbol? (~bindings-sym 0))
`(let ~(subvec ~bindings-sym 0 2)
(try
(~'~name ~(subvec ~bindings-sym 2) ~@~body-sym)
@trevorc
trevorc / distribute_setup.py
Created April 5, 2012 05:59
distribute setup
#!python
"""Bootstrap distribute installation
If you want to use setuptools in your package's setup.py, just include this
file in the same directory with it, and add this to the top of your setup.py::
from distribute_setup import use_setuptools
use_setuptools()
If you want to require a specific version of setuptools, set a download
@trevorc
trevorc / htpinstaller.sh
Created April 5, 2012 06:00
How To Program ubuntu installer
#!/bin/sh
set -eu
DISTRIBUTE_SETUP=https://raw.github.com/gist/2308340/d2c2899afa9894be579f48a7a6d4193e84a55b6b/distribute_setup.py
sudo -k
which easy_install &> /dev/null || wget -qO- $DISTRIBUTE_SETUP | sudo python
sudo easy_install django
sudo easy_install dotcloud
@trevorc
trevorc / gist:2341940
Created April 9, 2012 06:27
emacs startup script
#!/bin/sh
app=/Applications/Emacs.app/Contents/MacOS/Emacs
for arg; do
case $arg in
-version|--version|-f|-l|-eval|-batch|-nw) exec $app "$@"
esac
done
set autowriteall
set backspace=indent,eol,start
set cinoptions=Ws,(0,t0
set directory=~/.config/vim/swap,/tmp
set encoding=utf-8
set expandtab
set formatoptions=q
set hidden
set hlsearch
set incsearch
@trevorc
trevorc / init.el
Last active October 6, 2015 14:08
;;;;;;;;;;;;;;;;;;;;
;; Initialization ;;
;;;;;;;;;;;;;;;;;;;;
(require 'cl)
(defmacro* dolist* ((iterator list &optional return-value) &rest body)
"Like `dolist' but `destructuring-bind's the elements of LIST.
If ITERATOR is a symbol then dolist* is just like `dolist' except
{-# LANGUAGE TupleSections #-}
module RPN (main) where
import Control.Applicative ((<$>))
import Control.Monad (forM_, unless)
import Control.Monad.Instances ()
import Data.List (find, intercalate)
import Data.Maybe (listToMaybe)
import System.IO (stdout, hFlush)