Skip to content

Instantly share code, notes, and snippets.

View jbranchaud's full-sized avatar

Josh Branchaud jbranchaud

View GitHub Profile
@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 / 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 / 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 / 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 / dafny-exercise0
Created March 11, 2013 01:09
Exercise 0 from Microsoft's Dafny tutorial on Rise4Fun.com
/*
* Write a method Max that takes two integer parameters and returns
* their maximum. Add appropriate annotations and make sure your code
* verifies.
*/
method Max(a: int, b:int) returns (c: int)
ensures c >= a && c >= b;
{
if (a > b) {
return a;
@jbranchaud
jbranchaud / dafny-exercise1
Last active December 14, 2015 18:39
Exercise 1 from Microsoft's Dafny on Rise4Fun.com
/*
* Write a test method that calls your Max method from
* Exercise 0 and then asserts something about the result.
*/
method Max(a: int, b:int) returns (c: int)
ensures c >= a && c >= b;
ensures a > b ==> c == a;
ensures a <= b ==> c == b;
{
if (a > b) {
@jbranchaud
jbranchaud / dafny-exercise2
Created March 11, 2013 01:55
Exercise 2 from Microsoft's Dafny on Rise4Fun.com
/*
* Using a precondition, change Abs to say it can only be
* called on negative values. Simplify the body of Abs into
* just one return statement and make sure the method still
* verifies.
*/
method Abs(x: int) returns (y: int)
requires 0 > x;
ensures 0 <= y;
ensures 0 <= x ==> x == y;
@jbranchaud
jbranchaud / dafny-exercise3
Created March 11, 2013 02:14
Exercise 3 from Microsoft's Dafny on Rise4Fun.com
/*
* Keeping the postconditions of Abs the same as above, change
* the body of Abs to just y := x + 2. What precondition do you
* need to annotate the method with in order for the verification
* to go through? What precondition doe you need if the body is
* y := x + 1? What does that precondition say about when you can
* call the method?
*/
method Abs(x: int) returns (y: int)
requires x == -1;
@jbranchaud
jbranchaud / dafny-exercise4
Created March 11, 2013 02:20
Exercise 4 from Microsoft's Dafny on Rise4Fun.com
/*
* Write a function max that returns the larger of two given
* integer parameters. Write a test method using an assert that
* checks that your function is correct.
*/
function max(a: int, b: int): int
{
if a > b then a else b
}
method Testing() {
@jbranchaud
jbranchaud / dafny-exercise5
Created March 12, 2013 14:40
Exercise 5 from Microsoft's Dafny on Rise4Fun.com
/*
* Change your test method from Exercise 4 to capture the value
* of max to a variable, and then do the checks from Exercise 4
* using the variable. Dafny will reject this program because you
* are calling max from real code. Fix this problem using a
* function method.
*/
function method max(a: int, b: int): int
{
if a > b then a else b