Skip to content

Instantly share code, notes, and snippets.

View GrahamLea's full-sized avatar

Graham Lea GrahamLea

View GitHub Profile
@GrahamLea
GrahamLea / Mastodon_Follow_Locally_Mod_TamperMonkey.js
Created December 17, 2022 04:49
A TamperMonkey script for Mastodon that makes it easy to jump from looking at someone's profile on another server to following them on your server
// ==UserScript==
// @name Mastodon Follow Locally Mod
// @namespace http://www.grahamlea.com/
// @version 0.1
// @description Allows you to follow Mastodon accounts from other servers more easily
// @author Graham Lea (@evolvable@aus.social)
// @match https://*/*
// @require http://code.jquery.com/jquery-latest.js
// @grant none
// ==/UserScript==
@GrahamLea
GrahamLea / docker-cleanup.sh
Created May 20, 2020 13:57
How to cleanup docker containers, images and volumes on your local machine
# Remove containers whose name matches the automatic naming pattern (adjective_name). Won't affect running containers.
docker rm $(docker ps -a | awk '{print $NF}' |egrep '^[a-z]+_[a-z]+$')
# Delete images that don't have any tags or containers.
docker image prune -f
# Delete unused volumes
docker volume prune -f
@GrahamLea
GrahamLea / carrd_google_analytics_scroll_depth.html
Created October 16, 2019 06:52
HTML/JS embed source to get a Carrd web page logging scroll depth events to Google Analytics (should work for any website loading GA via https://www.googletagmanager.com/gtag/js?id=UA-XXXXX-X)
<script>
// TODO: Replace the percentages and names below with those relevant to your website
var percentagesToReport = new Map();
percentagesToReport.set(25, 'Section2');
percentagesToReport.set(50, 'Section3');
percentagesToReport.set(75, 'Section4');
percentagesToReport.set(90, 'Section5');
function reportScroll(scrollLocationName) {
gtag('event', scrollLocationName, {
@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.
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 / 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.
@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 / 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 / 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 / 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,