Skip to content

Instantly share code, notes, and snippets.

View sposterkil's full-sized avatar

Sam Osterkil sposterkil

  • Stateless
  • Boulder, CO
View GitHub Profile
@sposterkil
sposterkil / .zshrc
Last active December 16, 2015 22:19
my .zshrc
#
# Executes commands at the start of an interactive session.
#
# Authors:
# Sorin Ionescu <sorin.ionescu@gmail.com>
#
# Source Prezto.
if [[ -s "${ZDOTDIR:-$HOME}/.zprezto/init.zsh" ]]; then
source "${ZDOTDIR:-$HOME}/.zprezto/init.zsh"
@sposterkil
sposterkil / mvhp.py
Created May 17, 2013 01:32
mvhp-joe
#!/bin/env python
# -*- coding: utf-8 -*-
# This program is free software. It comes without any warranty, to
# the extent permitted by applicable law. You can redistribute it
# and/or modify it under the terms of the Do What The Fuck You Want
# To Public License, Version 2, as published by Sam Hocevar. See
# http://sam.zoy.org/wtfpl/COPYING for more details.
import asyncore
@sposterkil
sposterkil / gist:5737652
Last active December 18, 2015 06:09
Demo
#!/bin/bash
menu(
{
while [[ true ]]; do
echo Your Menu
if [[ option1 ]]; then
subroutine1()
fi
done
@sposterkil
sposterkil / regex
Created September 1, 2013 19:18
Twoliner of "here's what my regex is doing"
regex="[^,. ]{1,3}"
re.findall(regex,string)
@sposterkil
sposterkil / Segmentor.py
Created September 3, 2013 05:03
My handling of exceptions and sys.exit()
def __init__(self, filename, slice_length):
try:
self.file = open(filename, 'r')
self.slice_length = int(slice_length)
except IOError, e:
print "No such file:", sys.argv[1]
sys.exit()
except ValueError, e:
print "\"%s\" isn't a number." % sys.argv[2]
print "Usage: Segmentor.py <file> <slice length>"
@sposterkil
sposterkil / Despereaux
Created September 13, 2013 22:17
Mouse instance named Despereaux, because literary references.
else:
despereaux = Mouse(initial_cell)
done = False
visited_cells = []
route = MazeRoute()
while (despereaux.can_travel() and
not despereaux.current_cell in visited_cells):
if despereaux.current_cell in self._cells:
visited_cells.append(despereaux.current_cell)
else:
@sposterkil
sposterkil / mccabe_modernizer.py
Created November 8, 2013 19:57
Demo of McCabe complexity moving things into a separate function
def prepare_line_list(line):
line_list = re.split("\s+", line)
# Use of re.split adds an empty element to the list
del line_list[len(line_list) - 1]
# Add empty field if we don't have a middle name
if len(line_list) is not 7:
line_list.insert(3, "")
@sposterkil
sposterkil / modernizer.py
Created November 12, 2013 17:59
EECS293 CSV translation project
#!/usr/bin/env python
import fileinput
import re
import sys
def _prepare_line_list(line):
line_list = re.split("\s+", line)
# Use of re.split adds an empty element to the list
del line_list[len(line_list) - 1]
@sposterkil
sposterkil / Recursion?
Created August 31, 2014 18:21
I think this even works
def recurse(input_file):
"""Takes a file and recursively evaluates lines to get an answer."""
children, value = split_line(input_file.read())
# All operations we implement are binary, we should either have zero
# children or two. Anything else is an error.
if children == 0:
return float(value)
elif children == 2:
return operate(value,
recurse(input_file.read()),
@sposterkil
sposterkil / pr01.py
Created September 3, 2014 02:23
new evaluation()
def evaluation(tree):
print tree.label
if len(tree.children) == 0:
return tree
else:
return apply_op(tree.label, evaluation(tree.children[0]), evaluation(tree.children[1]))