Skip to content

Instantly share code, notes, and snippets.

Trevor Caira trevorc

Block or report user

Report or block trevorc

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
trevorc / ringbuffer.clj
Created Mar 15, 2012
Persistent Ring Buffer
View ringbuffer.clj
(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))
View Core.hs
module Bunrui.Core
( Command
, Metadata(..)
, Opts(..)
, findSourceFiles
, missingDirectories
, readMetadata
) where
import Control.Applicative ((<$>), (<*), (<*>))
View concatmap.hs
bfs :: Tree a -> [a]
bfs t =
concatMap (map rootLabel) $
takeWhile (not . null) $
iterate (concatMap subForest) [t]
trevorc / deg.html
Created Oct 17, 2011
Convert between degrees, minutes, and seconds and decimal degrees
View deg.html
<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<title>coordinate calculator</title>
<style>h1 { font-size: 1.1em; }</style>
<h1>Convert between degrees, minutes, and seconds and decimal degrees</h1>
<table id="calc">
trevorc / rpn.hs
Created Oct 17, 2011
Haskell RPN calculator
View rpn.hs
module Main where
import System.Environment
runRPN :: (Fractional a, Read a) => String -> [a]
runRPN = foldl doToken [] . words
where doToken (x:y:zs) "+" = (y+x):zs
doToken (x:y:zs) "-" = (y-x):zs
doToken (x:y:zs) "*" = (y*x):zs
doToken (x:y:zs) "/" = (y/x):zs
View Base C++ makefile
-I/usr/local/include -Isrc
CXXFLAGS += -std=c++98 -fno-rtti -fno-exceptions -pipe \
-Wall -Wextra -Werror -Wcast-align -Wstrict-overflow -Wshadow
LDFLAGS += -L/usr/local/lib
INSTALL ?= install
ifdef pkg_config_libs
CPPFLAGS += $(shell pkg-config --cflags $(pkg_config_libs))
trevorc / moments.awk
Created Sep 3, 2011
Compute the first four sample moments about the mean (and the standard deviation) iteratively from a stream of samples
View moments.awk
BEGIN { OFS = "\t" }
accs[0] += 1
accs[1] += $1
accs[2] += (val2 = $1 * $1)
accs[3] += (val3 = val2 * $1)
accs[4] += (val4 = val3 * $1)
mean = accs[1] / accs[0]
trevorc / mutex.c
Created Aug 18, 2011
Python segfault on Mac OS X 10.7
View mutex.c
#include <pthread.h>
pthread_mutex_t mutex;
// compile and link with: cc -c mutex.c; ld -dylib -o libmutex.dylib mutex.o -lpthread
trevorc /
Created May 27, 2011
Backup MongoDB locally
#!/usr/bin/env python
import os
import sys
import bisect
import shutil
import datetime
import operator
import subprocess
#!/usr/bin/env python
import collections
import sys
def tokens(f):
for line in f:
for t in line.split():
yield t
You can’t perform that action at this time.