Skip to content

Instantly share code, notes, and snippets.

@yosemitebandit
yosemitebandit / linked_list.py
Created August 12, 2015 22:32
linked list in python
class Node(object):
def __init__(self, value):
self.value = value
self.next = None
def __repr__(self):
return 'Node %s' % self.value
class LinkedList(object):
@yosemitebandit
yosemitebandit / stack.py
Created August 12, 2015 23:02
stacks in python
import re
class Stack(object):
def __init__(self):
self.items = []
def push(self, item):
self.items.append(item)
@yosemitebandit
yosemitebandit / queue.py
Created August 13, 2015 00:46
python FIFO queue
class Node(object):
def __init__(self, value):
self.value = value
self.next = None
def __repr__(self):
return 'Node %s' % self.value
class Queue(object):
@yosemitebandit
yosemitebandit / binary_search_tree.py
Created August 13, 2015 08:22
binary trees in python
class Node(object):
"""A node referencing other nodes, forming a subtree."""
def __init__(self, data):
self.left = None
self.right = None
self.data = data
def __repr__(self):
"""A (not-so-good) display."""
@yosemitebandit
yosemitebandit / Procfile
Created September 1, 2015 01:17
a clojure webapp with ring for deploying on heroku
web: java $JVM_OPTS -cp target/webdev.jar clojure.main -m webdev.core $PORT
@yosemitebandit
yosemitebandit / core.clj
Last active September 2, 2015 18:39
pingping -- start of a pong game with quil
(ns pingping.core
(:import [java.awt.event KeyEvent])
(:require [quil.core :as q]))
(defn draw-rect [r]
(q/rect (:x r) (:y r) (:w r) (:h r)))
;; define left- and right-side rackets, as well as a ball and ball velocity
@yosemitebandit
yosemitebandit / serial_test.py
Created September 12, 2015 00:11
testing fona modules with serial commands on the beaglebone black
import Adafruit_BBIO.UART as UART
import serial
UART.setup("UART1")
ser = serial.Serial(port="/dev/ttyO1", baudrate=9600, timeout=1)
ser.close()
ser.open()
@yosemitebandit
yosemitebandit / csv-processor.py
Created June 30, 2011 17:28
process a csv, write to another csv
input_data = open('data.csv', 'r')
output_data = open('out.csv', 'w')
for line in input_data:
data = line[0:-2] # snip off the new line character and trailing comma
output_data.write( data + '\n' ) # add the newline back
input_data.close()
output_data.close()
#!/usr/bin/env python
'''
optparse_testing.py
some recipes from http://www.alexonlinux.com/pythons-optparse-for-human-beings
'''
import optparse
parser = optparse.OptionParser()
# basics
@yosemitebandit
yosemitebandit / baby_thread.py
Created August 19, 2011 00:09
small threading example
# http://www.neotitans.com/resources/python/python-threads-multithreading-tutorial.html
import sys
import time
import random
import threading
def worker(name):
print 'I am %s and starting now' % name
wait = random.randint(2,7)
time.sleep(wait)