Skip to content

Instantly share code, notes, and snippets.

View jbranchaud's full-sized avatar

Josh Branchaud jbranchaud

View GitHub Profile
@jbranchaud
jbranchaud / PAGisEVIL
Created January 31, 2013 19:59
Solution for Parity Analysis
TYPE
StrSet = set(str)
StrLifted = lift(StrSet)
State = Var -> StrLifted
PROBLEM Constant_Propagation
direction : forward
carrier : State
@jbranchaud
jbranchaud / QuickJavaSearch.bash
Created November 16, 2012 17:44
Quick search through a large Java project for a string
#!/bin/bash
# the first argument is the string you are looking for --> $1
searchString="$1"
for f in `find . -type f -name "*.java"`
do
result=`grep "$searchString" $f`
@jbranchaud
jbranchaud / validate_directory.py
Created November 5, 2012 04:37
A quick and tolerant directory validator for unix systems in Python
import os
"""
validate_directory: string -> string
given a string that represents a directory, this function will go through and
do some basic validation on it. If there is a problem with the directory as
given, it will be converted to the home directory and returned as is.
"""
def validate_directory(directory=None):
if directory == None or directory == '~' or not os.path.isdir(directory):
@jbranchaud
jbranchaud / wpcodesplitter
Created October 19, 2012 16:15
A quick function to split up/remove the <br /> tags when a WP sourcecode example gets auto-formatted.
import os
import sys
# add the offending text to file1.txt
f = open("file1.txt", 'r')
content = f.read()
contentArray = content.split('<br />')
for item in contentArray:
print item
# then copy/paste the console output
@jbranchaud
jbranchaud / RSVPCounter
Created August 24, 2012 19:17
Count people that have RSVP'd
cat rsvpresults.yaml | grep 'totalPeople' | sed 's/totalPeople: //' | awk '{s+=$1} END {print s}'
@jbranchaud
jbranchaud / CSVtoLaTeX.bash
Created April 19, 2012 04:36
Convert CSV to LaTeX table
# Convert a CSV like the following:
# a,b,c,d,e,f,g
# To the LaTeX table format like the following:
# {a} & {b} & {c} & {d} & {e} & {f} & {g} \\\hline
sed 's/,/} \& {/g' Table1.csv | sed 's/^/{/' | sed 's/$/} \\\\\\hline/' > Table1Format.txt
@jbranchaud
jbranchaud / createParser
Created February 7, 2012 21:09
Create an ASTParser (CompilationUnit) for the JDT using a char[]
public CompilationUnit createParser(char[] contents) {
// Create the ASTParser which will be a CompilationUnit
ASTParser parser = ASTParser.newParser(AST.JLS4);
parser.setKind(ASTParser.K_COMPILATION_UNIT);
parser.setSource(contents);
parser.setResolveBindings(true);
CompilationUnit parse = (CompilationUnit) parser.createAST(null);
return parse;
@jbranchaud
jbranchaud / getFileContents
Created February 7, 2012 20:30
Read file contents into a char[]
public char[] getFileContents(File file) {
// char array to store the file contents in
char[] contents = null;
try {
// Read in the contents line by line storing them in a StringBuffer
BufferedReader br = new BufferedReader(new FileReader(file));
StringBuffer sb = new StringBuffer();
String line = "";
@jbranchaud
jbranchaud / GetSortedOccurrenceList.bash
Created December 14, 2011 17:19
Get a sorted list of unique items in a file with their number of occurrences.
#!/bin/bash
# Given a file, output a sorted list of unique items with the number of occurrences for each item next to it
fname=$1
cat $fname | sort | uniq -c
exit 0
@jbranchaud
jbranchaud / GetPrevRevision.bash
Created November 29, 2011 22:44
Find the revision number previous to the given one for the given file
#!/bin/bash
# Given a filename and a revision number, find the revision number previous to this one.
fname=$1
curr=$2
prev=""
for revnum in `svn log -q $fname | awk '/^r/ {print $1}' | sed -e 's/r//' | sort -n`
do