Skip to content

Instantly share code, notes, and snippets.

View philipaconrad's full-sized avatar

Philip Conrad philipaconrad

View GitHub Profile
@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 / 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"
@lukego
lukego / pbook in sed
Created October 24, 2012 13:10
Format program listings for Markdown
sed -E -e 's/^/ /g' -e 's/^ --- ?//g' | pandoc -o listing.pdf -
That expression is a cheap literate programming system for Markdown.
Start commentary lines with '--- ' and they will be
markdown-formatted, the rest will be code. (Uses Lua comment syntax.)
Finally the right implementation of this idea:
http://fresh.homeunix.net/~luke/misc/emacs/pbook.pdf (program)
http://fresh.homeunix.net/~luke/misc/erlang/regtest.pdf (better example)
@mjallday
mjallday / watcher.py
Created March 8, 2012 17:36
File watcher in Python
#!/bin/python
"""
A simple directory watching script that will compute the checksum for all files
within a path and execute a change when the sum changes.
This will not work well with large files as it reads the entire file into
memory.
"""
import argparse