Skip to content

Instantly share code, notes, and snippets.

View finnjohnsen's full-sized avatar

Finn Johnsen finnjohnsen

  • Kodemaker
  • Oslo, Norway
  • 17:24 (UTC +02:00)
View GitHub Profile
@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
@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 / .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 / 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 / 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 / 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)
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 / MyService.groovy
Last active December 16, 2015 07:38
Timer spawning service
import java.util.*
// very silly example spawning a thread
class MyService {
TimerTask task
Timer timer
def startJobs() {
timer = new Timer("Job") //Setting job name is important for the test
task = timer.runAfter(10000, {})
@finnjohnsen
finnjohnsen / exposeEHCache.groovy
Created November 21, 2013 13:34
Put this in Bootstrap.groovy and Ehcache will be exposed in JMX.
net.sf.ehcache.management.ManagementService.registerMBeans(
grailsApplication.mainContext.getBeansOfType(net.sf.ehcache.CacheManager).values().first(),
grailsApplication.mainContext.getBeansOfType(javax.management.MBeanServer).values().first(),
true, true, true, true)