Skip to content

Instantly share code, notes, and snippets.

@cthom06
cthom06 / godoc output
Created July 18, 2011 12:29
Godoc example
PACKAGE
package example
import "example"
This is the package comment, a top-level piece of documentation
used to explain things about the package (see json or exp/template)
All godoc comments are in this form
with no whitespace between them and what they accompany
@cthom06
cthom06 / quickslice.h
Created July 14, 2011 13:26
Abusing the C preprocessor a bit
#include <stdlib.h>
#include <string.h>
#define QUICKSLICE(SLICETYPE, SLICENAME) \
typedef struct SLICENAME { \
unsigned int len, cap; \
SLICETYPE *data; \
} SLICENAME; \
typedef SLICETYPE (SLICENAME ## _mapper) (SLICETYPE); \
typedef char (SLICENAME ## _folder) (SLICETYPE); \
#!/usr/bin/env python
import random, sys
def br():
c = random.randint(1,5)
if c == 5:
return chr(5)
else:
return chr(2)
@cthom06
cthom06 / gist:968535
Created May 12, 2011 13:54
Modified fish interpreter
#!/usr/bin/python
"""
A python interpreter for the esoteric language ><> (fish). Not very elegantly coded, but it works.
More information: http://esolangs.org/wiki/Fish
"""
@cthom06
cthom06 / circ.go
Created October 19, 2010 14:18
Boolean Circuits (ish) using go channels
// A fun little experiment making boolean circuits with channels
// It's pretty slow (especially with GOMAXPROCS > 1), but neat
// Originally, I had made all the gates structs with methods, etc,
// but they can all be done as functions thanks to closures/gc.
package circ
func NAND(in1, in2 <-chan bool) <-chan bool {
out := make(chan bool)
go func() {
for {