Skip to content

Instantly share code, notes, and snippets.

View davidkuster's full-sized avatar

David Kuster davidkuster

View GitHub Profile
@davidkuster
davidkuster / git_hg_bash_prompt.sh
Last active February 13, 2017 17:09
bash script to include Git and Mercurial branch and status in command prompt
#!/bin/bash
#
# DESCRIPTION:
#
# Set the bash prompt according to:
# * the branch/status of the current git repository
# * the branch of the current subversion repository
# * the return value of the previous command
#
# USAGE:
@davidkuster
davidkuster / test.gradle
Last active May 6, 2016 17:20
Running Gradle tests
// Gradle tests
// single file:
gradle -Dtest.single=TestClass :module-name:test --info
// single method:
gradle :module-name:test --tests *TestClass.methodToTest --info --stacktrace
// single test, Grails 3:
grails test-app -integration com.mypackage.myapp.MySpec.my_test_which_may_need_underscores_for_this_to_work
@davidkuster
davidkuster / grails_akka.groovy
Last active November 4, 2015 00:06
Wrapping Scala (Akka) Futures with Grails Promises. A very common use case. :)
import grails.async.Promise
import grails.async.Promises
import scala.concurrent.Future
import akka.dispatch.Futures
import akka.dispatch.OnComplete
import java.util.concurrent.Callable
def actorSystem = ctx.getBean('actorSystem')
def dispatcher = actorSystem.dispatcher()
/**
* Utility methods to make logging a little cleaner. Instead of having to put
* log.isDebugEnabled() (and etc) checks everywhere we want to log to debug, this will do the
* check in a single place. And because the strings to log are being passed as a closure, they
* will be lazily evaluated.
*
* Note: this trait assumes there is a "log" variable on the class, presumably injected into
* Grails artefacts or through use of the groovy.util.logging.Slf4j annotation.
*
* Note: updated all methods to static so these can be called from static methods. Required
@davidkuster
davidkuster / git_blame_summaries.groovy
Created December 28, 2015 15:16
Poor man's code contributions scratchpad
import groovy.io.FileType
def files = []
def extensions = ['.groovy', '.md', '.yml', '.gradle', '.json', '.html', '.puml', '.properties']
def foldersToExclude = ['/.gradle/', '/.idea/', '/build/']
def dir = new File("/path/to/checked/out/git/repo")
println "dir = $dir"
dir.eachFileRecurse (FileType.FILES) { file ->
@davidkuster
davidkuster / ClassUtils.groovy
Created December 28, 2015 17:32
Util to get the fields defined on a class, as well as converting objects to maps
// TODO: think about whether this makes more sense as a trait...
class ClassUtils {
// exclude all fields that start with these prefixes from the list returned by getFields() method
private static final List<String> EXCLUDED_FIELD_PREFIXES = ['grails_', '$', '__']
// Added exclusion of "grails_" and "$" fields - causes problems with Validateable cmd objs.
// Added exclusion of "__" due to Cobertura adding "__cobertura_counters" field.
/**
@davidkuster
davidkuster / grab.groovy
Created March 18, 2016 19:53
Grape Grab from Groovy console
groovy.grape.Grape.grab(group:'org.springframework', module:'spring-web', version:'4.2.5.RELEASE')
import org.springframework.web.util.UriComponentsBuilder
@davidkuster
davidkuster / GroovyREPL.py
Last active May 12, 2016 17:55
Start of a Sublime Text 2 plugin to use Sublime instead of a browser-based code editor as the front end for a Groovy REPL
import json
import sublime
import sublime_plugin
import threading
import urllib
import urllib2
# Sublime plugin to use Groovy REPL functionality as offered by a Spring Boot
# app with the necessary server-side support.
#
@davidkuster
davidkuster / gist:f485e7675cf56ad95b9ffe18d4511279
Created July 18, 2017 18:59
Quick FizzBuzz implementations
// corrected from initial approach, using % 15. My first attempt was wrong. This is what I get for not writing tests. Although tests on println...hmm...
def fizzBuzz = {
for (int x=1; x <= 100; x++) {
if (x % (15) == 0) println "FizzBuzz"
else if (x % 3 == 0) println "Fizz"
else if (x % 5 == 0) println "Buzz"
else println x
}
}
@davidkuster
davidkuster / mk-start
Created May 17, 2018 04:51
Script to start Minikube
#!/bin/bash
#minikube start --vm-driver=xhyve
minikube start --memory=8000 --vm-driver=xhyve --container-runtime=docker --v=3 --v=10 --alsologtostderr --insecure-registry="docker...io:5000"
kubectl cluster-info