Skip to content

Instantly share code, notes, and snippets.

View spratt's full-sized avatar

Simon Pratt spratt

View GitHub Profile
@spratt
spratt / allocate_test.c
Created February 1, 2016 13:39
A bad implementation of malloc using only mmap.
#include <sys/mman.h>
#include <stdio.h>
void* mymalloc(size_t len) {
void* addr = mmap(0,
len + sizeof(size_t),
PROT_READ | PROT_WRITE,
MAP_ANON | MAP_PRIVATE,
-1,
0);
@spratt
spratt / gist:5606662
Created May 19, 2013 04:15
list of movie genres
Aerospace film
Biography
Buddy Cop film
Burlesque film
Chick Flick
Circus film
Comedy film
Black comedy
Gross-out film
Romantic comedy film
@spratt
spratt / rand.py
Last active December 17, 2015 11:59
randomly select from lines of input
#!/usr/bin/env python2.7
import random
from sys import stdin, argv
words = []
for line in stdin:
words.append(line.strip())
n = int(argv[1])
@spratt
spratt / rand.py
Created May 19, 2013 03:55
Randomly select 12 words from input words specified one word per line
#!/usr/bin/env python2.7
import random
from sys import stdin
words = []
for line in stdin:
words.append(line.strip())
print(random.sample(words,12))
for(var i = 0; i &lt; objects.length; i++) {
build_element(objects[i]);
}
(defun ttt-print (board)
"Pretty prints a given board."
(format t "~% 1 2 3 &lt;- cols~%~%")
(format t "1 ~1&lt;~@[~A~]~&gt;|~1&lt;~@[~A~]~&gt;|~1&lt;~@[~A~]~&gt;~% -+-+-~%"
(pop board) (pop board) (pop board))
(format t "2 ~1&lt;~@[~A~]~&gt;|~1&lt;~@[~A~]~&gt;|~1&lt;~@[~A~]~&gt;~% -+-+-~%"
(pop board) (pop board) (pop board))
(format t "3 ~1&lt;~@[~A~]~&gt;|~1&lt;~@[~A~]~&gt;|~1&lt;~@[~A~]~&gt;~%"
(pop board) (pop board) (pop board))
(format t "^~% \\_ rows~%"))
(defun ttt-print (board)
"Prints a tic-tac-toe board."
(let* ((symbol nil)
(nl (string #\Newline))
(str (concatenate 'string
"S|S|S" nl
"-|-|-" nl
"S|S|S" nl
"-|-|-" nl
"S|S|S" nl)))
(defun ttt-print (board)
"Prints a tic-tac-toe board."
(let* ((nl (string #\Newline))
(str (concatenate 'string
"S|S|S" nl
"-|-|-" nl
"S|S|S" nl
"-|-|-" nl
"S|S|S" nl)))
(format t str)))
'(nil nil nil nil X nil nil nil O)
(documentation 'ttt-repl 'function)