Skip to content

Instantly share code, notes, and snippets.

View GrahamLea's full-sized avatar

Graham Lea GrahamLea

View GitHub Profile
@GrahamLea
GrahamLea / pom.xml
Created June 19, 2012 11:58
A template Maven POM for building Scoobi Hadoop Applications
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example</groupId>
    <artifactId>your-scoobi-app-name</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    <properties>
@GrahamLea
GrahamLea / CSVPivot.scala
Last active December 14, 2015 05:39
A Scala script that takes a CSV as input on stdin, produces a pivot table on two columns using a count() function and outputs the pivot table to stdout.
import collection.mutable
import io.Source
import java.io.FileInputStream
def toIntOption(s: String): Option[Int] = try { Some(s.toInt) } catch { case e: NumberFormatException => None }
val intArgs = args.map(toIntOption).flatten
if (args.length != 2 && intArgs.length != 2) {
System.err.println("usage: <x_column_number> <y_column_number>")
@GrahamLea
GrahamLea / BubbleChart.scala
Created February 26, 2013 07:06
A Scala script that takes in a CSV from stdin and write a bubble chart as a PNG to stdout.
import io.Source
import java.awt.font.GlyphVector
import java.awt.{Font, Graphics2D, Color}
import java.awt.RenderingHints._
import java.awt.geom.{Rectangle2D, Ellipse2D}
import java.awt.image.BufferedImage
import java.io.{File, ByteArrayInputStream}
import javax.imageio.ImageIO
// Change anything in this block to change how the input is interpreted
@GrahamLea
GrahamLea / delete-dependencies-from-local-repository.sh
Created July 31, 2013 12:12
Reads all dependencies from a Maven project and then deletes them all from your local repository.
#!/bin/bash
#
# Reads all dependencies from a Maven project and then deletes them all from your local repository.
#
# You may want to do this if you want to remove <repository> tags from a POM and check that you can still
# access all the dependencies for the project from just the remaining repositories.
#
# This code is in the public domain and may be used in any way you see fit, with the following conditions:
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
@GrahamLea
GrahamLea / parent-pom
Last active January 2, 2016 15:58
Bash script that prints the coordinates of the Parent POM of a Maven POM or multiple POMs. Relies on the xmlstarlet command being available.
#!/bin/bash -e
if [[ $1 = "-?" ]]; then
echo "usage: $(basename $0) [pom_file ...]" >&2
exit 2
fi
function printParentPom() {
if xmlstarlet sel -T -N m=http://maven.apache.org/POM/4.0.0 -t -m /m:project/m:parent -v "concat(m:groupId,':',m:artifactId,':',m:version)" -n $1
then
@GrahamLea
GrahamLea / AutoConnectingObservableExample.java
Created March 26, 2014 11:11
An example of an RxJava Observable decorator that automatically connect()s a ConnectableObservable after a prescribed number of Subscribers have subscribed
import rx.Observable;
import rx.Observable.OnSubscribe;
import rx.Subscriber;
import rx.functions.Action1;
import rx.functions.Func1;
import rx.functions.Func2;
import rx.observables.ConnectableObservable;
import java.util.ArrayList;
import java.util.List;
@GrahamLea
GrahamLea / TestTimeTracer.java
Created December 24, 2014 03:25
A Java class for use in creating time traces in tests when tracking down performance problems. It prints the time between each call to the trace() method, as well as logging when methods are entered and exited. Use it by instantiating a new TestTimeTracer as a field and then calling .trace() on the tracer between each line of code of a test. Whe…
public class TestTimeTracer {
public static final int MILLIS_PER_NANO = 1000000;
private final Stack<Pair<String, Integer>> traceCounts = new Stack<>();
private final NumberFormat numberFormat = NumberFormat.getIntegerInstance();
private String methodName = null;
private int methodTraceCount = 0;
private int lastStackDepth = 0;
@GrahamLea
GrahamLea / messages-and-events
Last active August 29, 2015 14:15
Thoughts on Messages and Events
Here's how I currently think about messages and events.
A message is a simply piece of data passed from one place to another.
Messages come in two flavours: commands and events.
A command is a message sent by a sender when it wants to instruct another component to perform some task.
* The message is sent one-to-one / point-to-point. It is destined for one receiver.
* The sender knows (at least) the name of the receiver.
* The sender knows something of the domain of the receiver, as it chooses to send the command.
Here is a letter I just wrote to my local MP about child abuse in detention centres.
I encourage you to also write to your MP. Feel free to copy my letter and insert the appropriate names at the top and bottom.
Email your local MP easily at: https://www.getup.org.au/campaigns/refugees/speak-up-for-kids-in-detention/write-to-your-mp
~~~~~~~~~~
<Local Member's Name>,
@GrahamLea
GrahamLea / ClimateEmergencyPetitionLetterTemplate.txt
Created September 29, 2019 22:40
A letter which people may use as a template in writing to their federal MP about the climate emergency petition.
THIS IS A TEMPLATE:
* CHANGE THE SALUTATION AT THE START
* UPDATE THE NUMBER OF PETITION SIGNATORIES IN THE 3RD PARAGRAPH
* INSERT YOUR NAME AT THE END
Dear PICK ONE: Prime Minister / Mr Speaker / Minister / Assistant Minister / Madam / Sir
I am writing to you as my local representative in the federal parliament’s House of Representatives.
Very soon a petition will come before the House; Petition EN1041 - Declare a Climate Emergency. At the time of writing, this petition has over 147,000 signatories.