Skip to content

Instantly share code, notes, and snippets.

View philipaconrad's full-sized avatar

Philip Conrad philipaconrad

View GitHub Profile
@philipaconrad
philipaconrad / gen_junit_stubs.py
Last active December 13, 2017 07:35
Generate JUnit test stubs using Python/regexes.
from __future__ import print_function
import os
import sys
import re
import string
template_decl = " @Test public void test{}()"
template_get_body = """ assertTrue(my{}.{}() == /* ... */);"""
template_set_body = """ my{}.{}();
@philipaconrad
philipaconrad / sig.py
Created April 14, 2015 04:08
Command line utility for checking hashes and checksums of files easily. [MIT License]
# sig.py -- Basic hash and checksum utility in Python.
# Copyright (c) Philip Conrad, 2015. All rights reserved.
# Released under the MIT License. (http://opensource.org/licenses/MIT)
import hashlib
import sys
import argparse
# Function for incrementally reading text from HUGE files.
def read_file(f, block_size=1024):
@philipaconrad
philipaconrad / md5.py
Created December 26, 2014 06:47
Command line script that shows the MD5 checksum for a given file.
# md5.py -- Simple MD5 checksum tool in Python.
# By Philip Conrad on 2014-12-26. Public Domain.
import hashlib
import sys
if __name__ == '__main__':
try:
m = hashlib.md5()
text = open(sys.argv[1], "rb").read()
m.update(text)
@philipaconrad
philipaconrad / lukegoLRU.py
Created July 2, 2013 06:29
A near-exact port of Luke Gorrie's table data structure that "garbage collects" not-recently-used items in O(1) time. Find the original at: https://gist.github.com/lukego/4706097
class lukegoLRU:
def __init__(self):
# Initialize 'old' and 'new' to empty tables
self.old = {}
self.new = {}
def insert(k, v):
self.new[k] = v
@philipaconrad
philipaconrad / morse.py
Created June 23, 2013 18:28
Generates ITU-Standard morse code (in bit format) from ASCII text.
#morse.py -- Generates ITU-Standard morse code (in bit format) from ASCII text.
#MIT License -- Copyright (c) Philip Conrad 2013, all rights reserved.
import time #used for testing later.
morseITUStandard = {
"a" : [1, 0, 1,1,1], #dot dash
"b" : [1,1,1, 0, 1, 0, 1, 0, 1], #dash dot dot dot
"c" : [1,1,1, 0, 1, 0, 1,1,1, 0, 1], #dash dot dash dot
@philipaconrad
philipaconrad / howto-cisco-catalyst-3560G-switch.md
Created May 10, 2013 17:04
A short bundle of recipes for dealing with Cisco Catalyst 3560G network switches.

How to talk to a Cisco Catalyst 3560G Switch

This is a short bundle of recipes for dealing with Cisco Catalyst 3560G ethernet switches.

Setup (Linux-side):

The Cisco Catalyst 3560G switch expects certain things when using its serial console port (labeled CONSOLE on the back of the device), pariticularly a 9600 baud rate for the serial connection.

@philipaconrad
philipaconrad / lsystem.py
Created May 9, 2013 05:59
A basic algae L-system, as described on http://en.wikipedia.org/wiki/L-System.
# lsystem.py -- simple algae L-System, as described on Wikipedia.
# Copyright (c) Philip Conrad 2013 -- MIT License
def IterSystem(inString):
out = ""
inLen = len(inString)
for i in range(0, inLen):
c = inString[i]
if(c == "A"):
out += "AB"