Skip to content

Instantly share code, notes, and snippets.

View barend's full-sized avatar
☀️

Barend Garvelink barend

☀️
View GitHub Profile
@barend
barend / OnlyOnWindowsRunner.java
Created March 10, 2011 17:26
A JUnit Runner that behaves like the default runner on Windows and ignores all tests on other operating systems.
//http://www.apache.org/licenses/LICENSE-2.0
package nl.fnord.junit;
import org.junit.runner.notification.RunNotifier;
import org.junit.runners.BlockJUnit4ClassRunner;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.InitializationError;
/**
* A JUnit {@code Runner} that behaves like the default runner on Windows and
@barend
barend / gist:1018771
Created June 10, 2011 12:44
Burgerservicenummer Elfproef Validator
/** Validate BSN according to http://nl.wikipedia.org/wiki/Burgerservicenummer */
private boolean isValidBSN(int candidate) {
if (candidate <= 9999999 || candidate > 999999999) {
return false;
}
int sum = -1 * candidate % 10;
for (int multiplier = 2; candidate > 0; multiplier++) {
int val = (candidate /= 10) % 10;
sum += multiplier * val;
@barend
barend / gist:6791274
Created October 2, 2013 09:34
Find string literals in smali
find . -name '*.smali' \
| grep -vE 'actionbarsherlock|watson|support' \
| xargs grep -F const-string \
| awk '{ print substr($0, index($0, "\"")) }' \
| sort \
| uniq
# Processes Ant JUnit logging output into tab separated values.
#
# [junit] Running com.myapp.MyTest
# [junit] Tests run: 2, Failures: 0, Errors: 0, Time elapsed: 0.721 sec
#
# Suite Num tests Num failed Num error Time (s)
# com.myapp.MyTest 2 0 0 0.721
#
BEGIN {
testname=""
@barend
barend / gist:085f5c9a7a0f14a54c11
Created August 3, 2014 18:46
Process GPS log of Sony camera
# Sony camera emits GPS data in NMEA format [1]
#
# The $GPRMC records contain velocity
#
# $GPRMC,043151.097,A,5203.5674,N,513.4071,E,14.56,,010814,,,A*43
# ^ ^ ^ ^ ^ ^ ^
# | | | | | | \-Checksum
# | | | | | |
# | | | | | \- date, ddmmyy
# | | | | \-------- velocity in knots
@barend
barend / LoggingInputConnectionWrapper.java
Created September 2, 2014 11:21
Android InputConnectionWrapper, as-is delegate with logging.
package com.example;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.inputmethod.CompletionInfo;
import android.view.inputmethod.CorrectionInfo;
import android.view.inputmethod.ExtractedText;
import android.view.inputmethod.ExtractedTextRequest;
import android.view.inputmethod.InputConnection;
import android.view.inputmethod.InputConnectionWrapper;
@barend
barend / logging-config.json
Created November 12, 2015 16:37
Pretty much the same as [carlcarl/python_logging_dict_config][pldc], but doesn't rely on eval().
{
"version": 1,
"disable_existing_loggers": true,
"formatters": {
"debug": {
"format": "[%(levelname)s][%(asctime)s](%(funcName)s/%(lineno)d) %(message)s",
"datefmt": "%Y-%m-%d %H:%M:%S"
},
"simple": {
"format": "[%(levelname)s][%(asctime)s] %(message)s",
@barend
barend / logging-config.json
Last active November 16, 2015 09:16
Pretty much the same as carlcarl/python_logging_dict_config, but doesn't rely on eval().
{
"version": 1,
"disable_existing_loggers": true,
"filters": {
"my_filter": {
"()": "filters.MyFilter"
}
},
"formatters": {
"debug": {
@barend
barend / gist:72a54afb92bbd7a71202
Created March 23, 2016 17:28
Mac OS X stop-it-with-the-curly-quotes-and-dashes-already
# Disables automatic substitution of "" by “”
defaults write NSGlobalDomain NSAutomaticQuoteSubstitutionEnabled -bool false
# Disables automatic subsitution of -- by –
defaults write NSGlobalDomain NSAutomaticDashSubstitutionEnabled -bool false
@barend
barend / GitFunctions.groovy
Created April 19, 2016 13:08
Obtain a git hash in gradle, using JGit. Useful in environments where people frown on just putting a shell exec in your gradle file like so: "git log -1 --pretty=%H".execute().
// In buildSrc/src/main/groovy/
import org.eclipse.jgit.api.Git
import org.eclipse.jgit.lib.RepositoryBuilder
import org.gradle.api.Project
class GitFunctions {
public static String headCommitAndStatus(Project project) {
def repo = new RepositoryBuilder()