Skip to content

Instantly share code, notes, and snippets.

View finnjohnsen's full-sized avatar

Finn Johnsen finnjohnsen

  • Kodemaker
  • Oslo, Norway
  • 22:12 (UTC +02:00)
View GitHub Profile
void "starting jobs creates threads"() {
when:
myService.startJobs()
Thread.sleep(300)
then:
Thread.getAllStackTraces().keySet().findAll \\
{Thread thread -> thread.name.contains "Job"}.size() > 1
cleanup:
myService.endJobs() //important, or you risk threads contaminating your next test. (happened to me)
}
void "end jobs should leave no threads"() {
setup:
myService.startJobs()
when:
myService.endJobs()
Thread.sleep(300)
then:
Thread.getAllStackTraces().keySet().findAll \\
{Thread thread -> thread.name.contains "Job"}.size() == 0
}
@finnjohnsen
finnjohnsen / gist:4949716
Created February 14, 2013 00:34
IllegalArgumentException Key must be integer
(defn strong? [person] (= (person :name) "Arnold"))
;#'user/strong?
(def people {"arnie" {:name "Arnold"} "joe" {:name "joe"}})
;#'user/people
(filter strong? people)
@finnjohnsen
finnjohnsen / whatever.groovy
Created December 10, 2012 16:38
Groovy sample
@Test
void "should be able to find follow up status"() {
//setup:
prepareMock()
//given
StatusInstance existing = insertStatusInstance()
//when
StatusCode followup = service.findFollowupStatus(existing.id.toString())
@finnjohnsen
finnjohnsen / handlebars-src-loader.js
Created November 13, 2012 14:48
handlebars-src-loader.js
/*
* Detects all scripts in DOM with src tag, and loads then into the html.
*/
var HandlebarsSrcLoader = function() {
}
HandlebarsSrcLoader.prototype = {
load : function (callback) {
var thiz=this;
var callback=callback;
@finnjohnsen
finnjohnsen / .auto_grails_switch.sh
Created October 16, 2012 13:10
auto switches symlinks to your grails project
#!/bin/bash
# This is ~/.auto_grails_switch, and it switches your grails runtime.
# 1. add this file to the bottom of ~/.bashrc
# source ~/.auto_grails_switch.sh
# 2. Make sure .auto_grails_switch is run every time you change dir. add \$(auto_grails_switch) to PS1
# PS1='debian_chroot:+($debian_chroot)}\$(auto_grails_switch)\$ '
@finnjohnsen
finnjohnsen / csvread.sh
Created October 1, 2012 11:50
read csv file in shell
#!/bin/bash
LINES=0
while read line
do
$(echo $line | cut -d\; -f3 >> '/tmp/bash.txt')
let LINES=LINES+1
done < "prior_notifications.csv"
echo LINES $LINES
@finnjohnsen
finnjohnsen / UDPListenerService
Created September 6, 2012 11:18
Android UDP Broadcast listener service
package no.nsb.ombord;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;
import org.apache.http.util.ExceptionUtils;
@finnjohnsen
finnjohnsen / setgrails
Created September 12, 2011 08:09
convenient script for changing grails version
#!/bin/bash
VERSION=$1
if [ $VERSION = "2" ]
then
VERSION="2.0.0.M1"
fi
rm /opt/grails-current
ln -sf /opt/grails-$VERSION /opt/grails-current