Skip to content

Instantly share code, notes, and snippets.

View rnorth's full-sized avatar

Richard North rnorth

View GitHub Profile
@rnorth
rnorth / Factorial.java
Last active August 29, 2015 14:10
Java 8 functional play
import java.math.BigInteger;
import java.util.stream.IntStream;
public class Factorial {
public static void main(String[] args) {
System.out.println(Factorial.factorial(1));
System.out.println(Factorial.factorial(5));
System.out.println(Factorial.factorial(120000));
}
@rnorth
rnorth / gist:4a9651c2c36ba71a5ab2
Created September 22, 2014 02:36
Fish function: chmox
function chmox
chmod +x $argv
end
@rnorth
rnorth / gist:f7e2fad195662fd2cb26
Created September 19, 2014 06:38
Check bitbucket open repository count is expected
[[ $(http "https://bitbucket.org/api/2.0/repositories/{username}" | jq '.values | length') == 0 ]]
@rnorth
rnorth / bc
Last active August 3, 2016 00:49
Boxcar push notification shell script
#!/bin/bash
# Sends a Boxcar push notification through the Boxcar HTTP API
# Usage examples
# $ bc # Just sends a notification with title 'bc'
# $ bc "Done" # Sends a notification with title 'Done'
# $ echo foobar | bc # Sends a notification with title 'bc' and message body 'foobar'
# $ echo foobar | bc "Done" # Sends a notification with title 'Done' and message body 'foobar'
#
# Expects a file ~/.boxcar to exist with content like
@rnorth
rnorth / gist:7019921
Created October 17, 2013 06:23
Quick example of using Quasar channels. Must run using the Quasar JVM agent. https://github.com/puniverse/quasar/ Example output: 'Hello 1' -> 'Hello 2' -> 'Hello 3' -> 'Hello 4' -> 'Hello 5' -> 'Hello 6' -> 'Hello 7' -> 'Hello 8' -> -> 'Hello 1' 'Hello 9' -> -> 'Hello 2' 'Hello 10' -> -> 'Hello 3' 'Hello 11' -> -> 'Hello 4' 'Hello 12' -> -> 'He…
import co.paralleluniverse.fibers.Fiber;
import co.paralleluniverse.fibers.SuspendExecution;
import co.paralleluniverse.strands.SuspendableRunnable;
import co.paralleluniverse.strands.channels.Channel;
import co.paralleluniverse.strands.channels.Channels;
import jsr166e.ForkJoinPool;
import java.util.concurrent.ExecutionException;
import static java.lang.String.format;
@rnorth
rnorth / hello_ratpack.sh
Created August 28, 2013 20:18
A ratpack web application in a shell script - just requires groovy (2.1+?) and JDK 1.7+ on the local machine.
#!/usr/bin/env groovy
@GrabResolver("http://oss.jfrog.org/artifactory/libs-snapshot")
@Grab("org.ratpack-framework:ratpack-groovy:0.9.0-SNAPSHOT")
import static org.ratpackframework.groovy.RatpackScript.ratpack
ratpack {
handlers {
get {
response.send "Hello ratpack!"
@rnorth
rnorth / per_app_postgres.sh
Last active December 18, 2015 10:59
A 'predeploy' script for dokku to automatically create an empty postgres database for new apps. Would require pre/post deploy hook support in dokku.
#!/bin/bash
set -e
export APP_NAME=$1
export PGHOST=$(< $HOME/predeploy.d/postgres_host)
export PGUSER=admin
if [ -f $HOME/$APP_NAME/DATABASE_URL ]; then
# Database URL is already set - DB must exist
DATABASE_URL=$(cat $HOME/$APP_NAME/DATABASE_URL)
for (job in Hudson.instance.items) {
if (! job.logRotator ) {
job.logRotator = new hudson.tasks.LogRotator ( 30, 40, 30, 10) // days to keep, num to keep, artifact days to keep, num to keep
println "$job.name edited and changed to statement below"
}
}
@rnorth
rnorth / gist:3780792
Created September 25, 2012 09:13
Tampermonkey script: Apple Dev ID team selection helper
// ==UserScript==
// @name Apple Dev ID team selection helper
// @namespace git://gist.github.com/3780792.git
// @version 0.1
// @description Makes the select team dropdown more helpful if you have Dev and Enterprise enrolments for the same firm
// @match https://developer.apple.com/*/selectTeam.action
// @copyright 2012, Richard North
// ==/UserScript==
var options = document.getElementsByTagName("option");
@rnorth
rnorth / gist:2031652
Created March 13, 2012 21:14
Cookie-based authentication with nginx
worker_processes 1;
error_log logs/error.log;
events {
worker_connections 1024;
}