Skip to content

Instantly share code, notes, and snippets.

View maxcountryman's full-sized avatar
👶

Max Countryman maxcountryman

👶
View GitHub Profile
@maxcountryman
maxcountryman / weasel.clj
Created March 18, 2012 13:11
Weasel in Clojure
;; weasel
(def TARGET "ME THINKS IT IS LIKE A WEASEL")
(def ALPHABET "ABCDEFGHIJKLMNOPQRSTUVWXYZ ")
(def RATE 0.05)
(def rand-seed
"Generate a random seed as long as the target."
(take (count TARGET) (repeatedly #(rand-nth ALPHABET))))
@maxcountryman
maxcountryman / markov.py
Created March 10, 2012 15:47
Markov Chain bot utilizing IrcTK
mport re
import os
import random
from irctk import Bot
_DEFAULT_CHAIN_LEN = 2
_DEFAULT_WORD_RANGE = 26
PUNCTUATION = '.\?|.!|.\.'
TALKATIVE = 0.3
@maxcountryman
maxcountryman / bf_redux.c
Created February 1, 2012 01:13
A brainfuck interpreter in C with dynamic memory allocation
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char* add_cell(char* tape, size_t *tape_size) {
char* tmp = (char*)realloc(tape, (++*tape_size) * sizeof(char));
if (tmp == NULL) {
printf("FATAL: Could not reallocate tape memory!");
@maxcountryman
maxcountryman / bf.c
Created January 29, 2012 17:20
A simple brainfuck interpreter in C
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
// initialize the tape with 30,000 zeroes
unsigned char tape[30000] = {0};
// set the pointer to point at the left-most cell of the tape
unsigned char* ptr = tape;
@maxcountryman
maxcountryman / terminal.py
Created January 15, 2012 02:02
A "point of price" terminal simulator (expects Python 2.7.x)
'''
terminal
--------
A simple checkout simulator.
'''
class Terminal(object):
'''A "point of sale" terminal object.'''
@maxcountryman
maxcountryman / weasel.c
Created December 20, 2011 02:16
Weasel in C
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
char* ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ ";
char* TARGET = "ME THINKS IT IS LIKE A WEASEL";
float RATE = 0.05;
int GENERATIONS = 250;
int ALPHABET_LEN = 27;
@maxcountryman
maxcountryman / radioreddit.py
Created September 13, 2011 18:58
radio redit plugin for an irctk app
# radioreddit stuff
@bot.command
def status(stream):
streams = [
'rock',
'electronic',
'hiphop',
'random',
'talk',
@maxcountryman
maxcountryman / ringbuffer.py
Created August 5, 2011 18:22
A simple circular "ring" buffer class
class RingBuffer(object):
'''This data structure provides a circular "ring" queue, limited by
n-number of positions as `length`. Once the ring is full, i.e. the length
is exceed, the head of the queue is deleted. In this way we acheive a
first in, first out circular buffer.'''
def __init__(self, length):
self.queue = []
self.keys = []
self.length = length
@maxcountryman
maxcountryman / sleep_sort.py
Created June 20, 2011 13:27
Sleep sort in Python
import thread
from time import sleep
items = [2, 4, 5, 2, 1, 7]
def sleep_sort(i):
sleep(i)
print i
[thread.start_new_thread(sleep_sort, (i,)) for i in items]
@maxcountryman
maxcountryman / add.py
Created April 18, 2011 09:24
recursive bitwise addition
add = lambda x, y : add((x & y) << 1, x ^ y) if x != 0 else y; add(13,29)
def add_again(x, y):
if x == 0:
return y
else:
return add_again((x & y) << 1, x ^ y)