Skip to content

Instantly share code, notes, and snippets.

View mrenouf's full-sized avatar

Mark Renouf mrenouf

View GitHub Profile
@mrenouf
mrenouf / Bootstrap.java
Created October 12, 2012 01:14
Guice bootstrap for Android
package com.bitgrind.android.guice;
import com.google.common.base.Throwables;
import com.google.inject.Binder;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Module;
import com.google.inject.util.Modules;
import android.app.Application;
@mrenouf
mrenouf / adb.py
Created September 28, 2012 00:47
An adb convenience wrapper
#!/usr/bin/python
# Handles call to adb and prompts for device selection if
# necessary when more than once device is connected.
#
# by Mark Renouf <mrenouf@google.com>
# To install:
# 1. Place this script somewhere in your path, and make it executable.
# 2. Make sure 'adb' is also in your path.
@mrenouf
mrenouf / reverse-tether.sh
Created August 11, 2012 23:01
USB reverse tethering script (only tested on Ubuntu 12.04 with Galaxy Nexus)
#!/bin/bash
ADB="/home/mrenouf/bin/adb"
# We need root on the host to mess with networking
if [[ $(whoami) != "root" ]]; then
echo "You must be root to run this script!"
exit 1
fi;
@mrenouf
mrenouf / gist:1870082
Created February 20, 2012 16:52
PID control
package com.bitgrind.control;
public class PID {
/**
* Low pass filter cutoff frequency for the derivative term.
*/
private static final int LOWPASS_CUTOFF_HZ = 20;
private static final double RC = 1 / (2 * Math.PI * LOWPASS_CUTOFF_HZ);
@mrenouf
mrenouf / git_merge_meld.sh
Created September 28, 2011 10:09
Merge helper script for using 'git mergetool' with meld, fixes http://stackoverflow.com/questions/7501666/
#!/bin/bash
# Handles proper use of Meld from Git.
#
# Instead of launching meld with $MERGED as the base revision, this
# script makes a copy of $BASE and handles copying the result back
# to $MERGED if the result was saved.
# As an extra tweak, it also presents branch names (if known) as
# the file name prefix, instead of just "LOCAL" and "REMOTE".
@mrenouf
mrenouf / PropertyFilter.java
Created April 3, 2011 22:54
Simplest possible streaming (filter) expansion of property references like ${property}
/*
* Copyright (C) 2011, Mark Renouf
*
* This code is licensed to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the
* License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
@mrenouf
mrenouf / copyFile
Created March 27, 2011 23:15
Efficient file copy in Java (pre-JDK7)
public static void copyFile(File sourceFile, File destFile) throws IOException {
if (!destFile.exists()) {
destFile.createNewFile();
}
FileInputStream fIn = null;
FileOutputStream fOut = null;
FileChannel source = null;
FileChannel destination = null;
try {
fIn = new FileInputStream(sourceFile);
@mrenouf
mrenouf / gist:845403
Created February 26, 2011 17:25
HTML skeleton -- Pretty me up!
<!doctype html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type="text/javascript" language="javascript" src="demo/demo.nocache.js"></script>
</head>
<body>
<input type="text" id="passphrase">
<input type="key" id="key">
<textarea id="plaintext"></textarea>
@mrenouf
mrenouf / PluralsTest.java
Created February 1, 2011 11:45
Test cases for Plurals.java
package com.bitgrind.text;
import org.junit.experimental.theories.DataPoints;
import org.junit.experimental.theories.Theories;
import org.junit.experimental.theories.Theory;
import org.junit.runner.RunWith;
import static org.junit.Assert.assertThat;
import static org.junit.Assume.assumeNotNull;
@mrenouf
mrenouf / Plurals.java
Created February 1, 2011 11:44
Pluralization rules for english
/*
* Original code from:
* Mattias Fagerlund
* http://lotsacode.wordpress.com/2010/03/05/singularization-pluralization-in-c/
* Matt Grande
* http://mattgrande.wordpress.com/2009/10/28/pluralization-helper-for-c/
*
* Converted Java by Mark Renouf
*/