Skip to content

Instantly share code, notes, and snippets.

View bgamari's full-sized avatar

Ben Gamari bgamari

View GitHub Profile
import Data.Set (Set)
import qualified Data.Set as S
import Data.EnumMap (EnumMap)
import qualified Data.EnumMap as EM
import Data.EnumSet (EnumSet)
import qualified Data.EnumSet as ES
data Priors = Priors { aLambda :: Double
@bgamari
bgamari / gist:1706324
Created January 30, 2012 19:59
Hedis thunk leak
{-# LANGUAGE OverloadedStrings #-}
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as BS
import Data.Serialize
import Control.Monad
import System.IO
import Database.Redis
import Data.List.Split
@bgamari
bgamari / gist:1712651
Created January 31, 2012 20:16
Directed separation
import qualified Data.Array as A
import Data.Tuple (swap)
import Data.List (nub, (\\))
import Data.Graph
type Path = [Vertex]
type Givens = [Vertex]
adjacent :: Graph -> Vertex -> [Vertex]
adjacent = (A.!)
@bgamari
bgamari / pandadaq.config
Created March 2, 2012 00:28
PandaDAQ kernel config
#
# Automatically generated file; DO NOT EDIT.
# Linux/arm 3.3.0-rc5 Kernel Configuration
#
CONFIG_ARM=y
CONFIG_SYS_SUPPORTS_APM_EMULATION=y
CONFIG_HAVE_SCHED_CLOCK=y
CONFIG_GENERIC_GPIO=y
# CONFIG_ARCH_USES_GETTIMEOFFSET is not set
CONFIG_GENERIC_CLOCKEVENTS=y
@bgamari
bgamari / split.sh
Created April 27, 2012 15:45
Script to split file into chunks
#!/bin/bash
nchunks=$1
file=$2
nlines=$(wc -l $file)
let n=$nlines/$nchunks
for i in $(seq 1 $nchunks); do
let startline=$i*$n
tail -n +$startline $file | head -n $n > $file.$i
done;
@bgamari
bgamari / Turing.hs
Created June 23, 2012 17:33
Turing machine
-- Turing machine
-- Author: Ben Gamari
import Graphics.Gloss
import Data.List
import Data.Function
type Symbol = Int
type Position = Int
type Tape = [(Position, Symbol)]
@bgamari
bgamari / implicitcad-proposal.hs
Last active December 10, 2015 20:28
A proposal for structuring ImplicitCAD's primitives
class HasBox a box | a -> box where
getBox :: a -> box
class HasImplicit a obj | a -> obj where
getImplicit :: a -> obj
type Obj2 = (Double,Double) -> Double
type Obj3 = (Double,Double) -> Double
data ImplicitObj obj = forall a. HasImplicit a obj => ImplicitObj a
@bgamari
bgamari / gist:4525799
Created January 13, 2013 19:31
`std::vector` allocation failure
#0 abort () at gcc4mbed/src/gcc4mbed.c:87
#1 0x0001ffb8 in operator new(unsigned int) ()
#2 0x0000a2c0 in allocate (__n=<optimized out>, this=<optimized out>)
at /home/ben/reprap/repos/Smoothie/gcc4mbed/gcc-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/include/c++/4.6.2/ext/new_allocator.h:92
#3 _M_allocate (__n=<optimized out>, this=<optimized out>)
at /home/ben/reprap/repos/Smoothie/gcc4mbed/gcc-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/include/c++/4.6.2/bits/stl_vector.h:150
#4 std::vector<Gcode, std::allocator<Gcode> >::_M_insert_aux<Gcode const&>(__gnu_cxx::__normal_iterator<Gcode*, std::vector<Gcode, std::allocator<Gcode> > >, Gcode const&&&) (this=0x10005600, __position=...)
at /home/ben/reprap/repos/Smoothie/gcc4mbed/gcc-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/include/c++/4.6.2/bits/vector.tcc:324
#5 0x0000a504 in push_back (__x=..., this=0x10005600)
at /home/ben/reprap/repos/Smoothie
Continuing.
Breakpoint 1, 0x0002b694 in malloc ()
#0 0x0002b694 in malloc ()
#1 0x00028948 in operator new(unsigned int) ()
#2 0x00028168 in std::string::_Rep::_S_create(unsigned int, unsigned int, std::allocator<char> const&) ()
#3 0x00028376 in std::string::_Rep::_M_clone(std::allocator<char> const&, unsigned int) ()
#4 0x00028416 in std::string::reserve(unsigned int) ()
#5 0x0000d9b2 in SerialConsole::on_main_loop (this=0x10001ef0, argument=0x10001600) at src/modules/communication/SerialConsole.cpp:53
#6 0x00007cee in Kernel::call_event (this=0x10001600, id_event=ON_MAIN_LOOP) at src/libs/Kernel.cpp:133
Continuing.
Breakpoint 3, 0x0002b694 in malloc ()
#0 0x0002b694 in malloc ()
#1 0x00028948 in operator new(unsigned int) ()
#2 0x00028168 in std::string::_Rep::_S_create(unsigned int, unsigned int, std::allocator<char> const&) ()
#3 0x00028376 in std::string::_Rep::_M_clone(std::allocator<char> const&, unsigned int) ()
#4 0x00028416 in std::string::reserve(unsigned int) ()
#5 0x0000d9b2 in SerialConsole::on_main_loop (this=0x10001ef0, argument=0x10001600) at src/modules/communication/SerialConsole.cpp:53
#6 0x00007cee in Kernel::call_event (this=0x10001600, id_event=ON_MAIN_LOOP) at src/libs/Kernel.cpp:133