Skip to content

Instantly share code, notes, and snippets.

View mrenouf's full-sized avatar

Mark Renouf mrenouf

View GitHub Profile
/**
* <p>ScrollabilityCache holds various fields used by a View when scrolling
* is supported. This avoids keeping too many unused fields in most
* instances of View.</p>
*/
private static class ScrollabilityCache implements Runnable {
/**
* Scrollbars are not visible
*/
#include <util/delay.h>
#include <avr/sleep.h>
#include <avr/power.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <string.h>
#include <stdio.h>
#include "port_macros.h"
#include "teensy_20.h"
#include "cpu_clock.h"
els = document.getElementsByTagName('li');
for(i = 0; i < els.length; i++) {
els[i].addEventListener('click',
function() {
alert(i);
},
false);
}
@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 <[email protected]>
# 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);