Skip to content

Instantly share code, notes, and snippets.

View bbody's full-sized avatar
⌨️
Smashing out mad code

Brendon Body bbody

⌨️
Smashing out mad code
View GitHub Profile
@bbody
bbody / munger.php
Created November 2, 2012 11:41
Email Address Munger
<html>
<head>
<title>Email Address Munger</title>
</head>
<body>
<h3>Put your email in below</h3>
<form method='POST'>
<input type=text name='email'>
<input type=submit>
</form>
@bbody
bbody / testing.cs
Last active December 12, 2015 02:48
Quick automated GUI example.
[TestMethod]
public void MultiplicationNegativeBoth()
{
this.UIMap.StartApplication();
// Both negative decimal
this.UIMap.NegativePressed();
this.UIMap.FivePressed();
this.UIMap.MultiplicationPressed();
this.UIMap.NegativePressed();
private boolean postIssue(String description, String title, String username,
String password, String stub, String ownerUsername){
// Set up authentication
String authentication = username + ":" + password;
String encoding = Base64.encodeToString(authentication.getBytes(),
Base64.NO_WRAP);
URL url;
try {
// Setup URL with specified username (Owner) and repository stub
@bbody
bbody / Calculator.java
Created April 21, 2013 06:44
Simple Integer Calculator class (Division deliberately wrong)
public class Calculator{
private int a, b;
public Calculator(int a, int b){
this.a = a;
this.b = b;
}
public int addition(){
return this.a + this.b;
}
@bbody
bbody / testcases.java
Last active December 16, 2015 11:39
Set of test cases for integer division.
@Test
public void division(){
// Positive
Calculator c = new Calculator(4, 2);
assertEquals("Basic division", c.division(), 2);
c = new Calculator(8, 3);
assertEquals("Division with decimals", c.division(), 2);
c = new Calculator(50000000, 10000000);
@bbody
bbody / DirectionSpinner.java
Last active December 17, 2015 00:29
A bad example of a need for refactoring and UI decoupling
private void setupDirectionSpinner(){
busStop = inputTextEdit.getText().toString();
boundSpinner = (Spinner) this.findViewById(R.id.boundSpinner);
// Set up bound list
boundList = new ArrayList<String>();
boundList.add("Direction");
boundList.addAll(dbhelper.getDirections(busStop));
// Set up adapter
@bbody
bbody / addition_parser_test.py
Last active February 15, 2016 09:48
Test suite for a string addition parser for a TDD video
import unittest
def calculate_addition_string(expression):
numbers = expression.split('+')
total = 0
for number in numbers:
total += int(number)
return total
class TestAdditionMethods(unittest.TestCase):
@bbody
bbody / db.rake
Last active April 1, 2018 02:14
Useful rake task to restart database from scrap for Rails applications, do not use in production
# lib/tasks/db.rake
namespace :db do
desc 'Drop, create, migrate then seed the development database'
task reseed: [ 'db:drop', 'db:create', 'db:migrate', 'db:seed' ] do
puts 'Reseeding completed.'
end
end
@bbody
bbody / compare_images.sh
Created May 15, 2018 03:58
Compares two folders of files and outputs diffs (if any) to a folder called diffs
# compare_images.sh
# Requires imagemagick `brew update && brew install imagemagick`
for entry in "$1"/*
do
if [ -f "$entry" ];then
NAME=`basename "$entry"`
DIFF=`compare -metric AE "$1/$NAME" "$2/$NAME" null: 2>&1`;
if [ "${DIFF}" -eq "0" ]; then
@bbody
bbody / video_to_gif.sh
Created December 22, 2018 08:41
Video to GIF with colour optimization
#!/bin/sh
# Arguments:
# First argument: input file
# -ss: start time [optional]
# -t: end time [optional]
# Example usage:
# ./video_to_gif.sh input_file.mov
# ./video_to_gif.sh input_file.mov -ss 1.00