Skip to content

Instantly share code, notes, and snippets.

View cbarrett's full-sized avatar
🏴
Revolting

Colin Barrett cbarrett

🏴
Revolting
View GitHub Profile
@cbarrett
cbarrett / Amb.hs
Last active August 29, 2015 13:58
SICP's amb is the list monad, by example
-- You can find the original in section 4.3.2 of SICP: http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-28.html#%_sec_4.3.2
import Data.List
distinct :: Eq a => [a] -> Bool
distinct xs = length (nub xs) == length xs
require :: Bool -> [[a]] -> [[a]]
require b e = if b then e else return []
@cbarrett
cbarrett / NiceURLConnection.m
Created May 31, 2009 05:01
A sketch for an implementation of a better NSURLConnection, NiceURLConnection
// by Colin Barrett (colin at springs and struts dot com)
// I release this sketch to the community under the MIT License.
// No really this is just a sketch I haven't even compiled it or anything.
// Other ides:
// - Failure & success completion selectors ?
// - Single delegate method called on both success and failure.
@interface NiceURLConnection : NSURLConnection {
@cbarrett
cbarrett / run.sh
Created November 30, 2009 23:05
I'm going through the Crenshaw tutorial http://compilers.iecc.com/crenshaw/ but translating from TurboPascal/68K to Python/x86. I've only just begun: I just finished the second section of the tutorial, but I have found this helpful. Works on Snow Leopard
#!/bin/sh
# (c) 2009 Colin Barrett <colin@springsandstruts.com>
# MIT Licensed.
echo ' .cstring
format_string:
.asciz "Result: %d\\n"
.text
.globl _main
_main:
% cat main.py
from config import config, set_config, print_config
print "1: %s" % (config)
set_config({'hello': 'world'})
print "3: %s" % (config)
print_config()
% cat config.py
config = None
@cbarrett
cbarrett / BLOCK bself macro
Created March 16, 2011 04:25
I think this was it. I stopped using it because it made Xcode 3 put all errors or warnings for the block on the line of the macro invocation; total nonstarter.
#define BLOCK(...) ({ __block __typeof__(self) bself = self; __VA_ARGS__(); )}
% ls -lah .dropbox ~
total 89776
drwxr-xr-x 11 cbarrett staff 374B May 13 11:40 .
drwxr-xr-x+ 56 cbarrett staff 1.9K Apr 20 18:54 ..
-rw-r--r-- 1 cbarrett staff 33K May 13 11:40 config.db
-rw-r--r-- 1 cbarrett staff 3B May 3 17:29 dropbox.pid
-rw------- 1 cbarrett staff 8.0M May 13 11:40 filecache.db
drwxr-xr-x 5 cbarrett staff 170B Feb 28 2010 finderplugin
-rw-r--r-- 1 cbarrett staff 73B May 3 17:30 host.db
-rw-r--r-- 1 cbarrett staff 24B Aug 23 2010 ignore.db
@cbarrett
cbarrett / gist:1157321
Created August 19, 2011 16:53
zsh vcs_info example
autoload -Uz vcs_info
zstyle ':vcs_info:*' enable hg
zstyle ':vcs_info:hg*' formats "%F{green}%b%f"
zstyle ':vcs_info:hg*' actionformats "%F{red}%a%f %F{green}%b%f"
zstyle ':vcs_info:hg*+set-message:*' hooks no-default-branch
function +vi-no-default-branch() {
[[ "${hook_com[branch_orig]}" != "default" ]] && return 0
ret=1
tell application "Terminal"
open (path to desktop folder)
end tell
@cbarrett
cbarrett / Lich.hs
Created October 10, 2012 16:59
Simple Lich parsing and encoding in Haskell
import Control.Applicative
import Control.Monad
import qualified Data.ByteString as B
import qualified Data.ByteString.Char8 as C
import qualified Data.Map as M
import Text.Parsec hiding ((<|>), many)
import qualified Text.PrettyPrint.HughesPJ as P
type Parser = Parsec B.ByteString ()
@cbarrett
cbarrett / Lich.hs
Created October 10, 2012 18:22 — forked from patrickt/Lich.hs
Simple Lich parsing and encoding in Haskell
import Control.Applicative
import Control.Monad
import Data.ByteString (ByteString)
import qualified Data.ByteString as B
import qualified Data.ByteString.Char8 as C
import Data.Map (Map)
import qualified Data.Map as M
import Text.Parsec hiding ((<|>), many)
import Text.PrettyPrint.HughesPJ ((<>), brackets, text, braces, hsep)
import qualified Text.PrettyPrint.HughesPJ as P