Skip to content

Instantly share code, notes, and snippets.

View zach-klippenstein's full-sized avatar

Zach Klippenstein zach-klippenstein

View GitHub Profile
@zach-klippenstein
zach-klippenstein / complex-diff-csv.rb
Created August 11, 2009 23:04
Ugly-as-heck script for diffing two CSV files that differ in both number of rows and row content.
#!/usr/bin/ruby
#
# Ugly-as-heck script for comparing two CSV files whose rows have changed, and
# where rows were added to or removed from the second file. Traditional diff tools
# can't make the connection between these two types of changes, so show every line as having
# changed.
#
# Uses git and gitk.
require 'fileutils'
@zach-klippenstein
zach-klippenstein / gist:202673
Created October 6, 2009 01:25
Prints out a bunch of information about all files in the current directory and subdirectories, recursively (see comment header for more info)
#!/bin/bash
# by Zachary Klippenstein
#
# Prints out a bunch of information about all files in the current
# directory and subdirectories, recursively.
# Info includes:
# - filename
# - file type (as given by 'file' command)
# - file contents (prefixed by filename and line number in file, and for binary files, result of 'strings')
@zach-klippenstein
zach-klippenstein / kyle_newton.java
Created October 29, 2009 05:26
Various implementations of Netwon's method
public ResultPair solveNewton(double init, double epsilon)
{
int numIt = 1;
double root;
double xn;
double xnPlusOne;
double xnMinusOne;
xn = init;
xnPlusOne = xn - eval(xn) / getDeriv().eval(xn);
@zach-klippenstein
zach-klippenstein / postfix_calc.c
Created October 30, 2009 00:24
Simple console calculator. Uses postfix notation.
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#define STACK_SIZE 1000
#define MAX_OPERATORS 10
#define MAX_LINE 300
// Clear any exception
@zach-klippenstein
zach-klippenstein / Contest09Problem4.java
Created October 31, 2009 21:34
Problem 4 solution attempt for 2009 ACM North American Programming competition
import java.io.*;
import java.util.Scanner;
import java.util.HashMap;
import java.util.Collection;
public class Contest09Problem4
{
enum State
{
running,
@zach-klippenstein
zach-klippenstein / linkparser.py
Created December 9, 2009 19:51
Attempt at creating a very simple, breadth-first web crawler. As the test file shows, it was supposed to work on wikipedia. However, it doesn't (Wikipedia seems to send HTML that doesn't actually contain the article content).
from HTMLParser import HTMLParser
class LinkParser(HTMLParser):
def __init__(self):
HTMLParser.__init__(self)
self.links = []
#end __init__()
def reset(self):
HTMLParser.reset(self)
@zach-klippenstein
zach-klippenstein / smb-sync.sh
Created February 1, 2010 01:51
This script takes a local directory and a set of options specifying how/where to connect to a remote Samba server, and a newline-delimited list of paths on standard input. The paths should be relative to the local directory and the remote directory. They
#!/bin/bash
HELP="
Created on: 20/01/2010
By: Zachary Klippenstein
This script takes a local directory and a set of options
specifying how/where to connect to a remote Samba server,
and a newline-delimited list of paths on standard input.
The paths should be relative to the local directory and
@zach-klippenstein
zach-klippenstein / caseglob
Created March 14, 2010 01:07
Returns the path passed to it with the case of components modified to match the actual names. See the comment header for more details.
#!/bin/bash
#
# usage: caseglob [--rename] path
# Prints the path, with the basename corrected to the actual case of the file, if
# a match can be made.
#
# If --rename is specified, if an unambiguous match is found, it will be renamed to
# path and returned in the original case.
#
# If there are 0 or more than 1 matches, the original basename is printed.
@zach-klippenstein
zach-klippenstein / demo.rb
Created March 24, 2010 18:47
Class for parsing sentences from various sources (strings, streams, etc.)
# Demonstrates how to use the SentenceParser class.
require 'sentenceparser'
parser = SentenceParser.new
# Add a string as a source
parser << "This is a string. It has multiple sentences."
parser << "These are" << "a few strings, splitting" << "sentences across them."
#!/bin/bash
#
# Run periodically by cron, and will unarchive data in the
# ~/auto_unarchive/drop_target directory.
# Where the action happens
unarchiveDir="~/auto_unarchive/drop_target"
# Time in seconds between checking for new archives
checkInterval=1.5