Skip to content

Instantly share code, notes, and snippets.

View davidkuster's full-sized avatar

David Kuster davidkuster

View GitHub Profile
@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 ->
/**
* 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 / 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()
@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 / 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 / .bash_profile
Last active July 17, 2020 03:13
OSX bash profile
# history tweaks (Setting HISTSIZE and HISTFILESIZE to something nonnumeric makes for no limits)
export HISTFILESIZE="SAVE_IT_ALL_YO"
export HISTSIZE="SAVE_IT_ALL_YO"
export HISTTIMEFORMAT='%Y-%m-%d %H:%M.%S | '
export HISTIGNORE="ll:exit:history:[bf]g:jobs"
export HISTCONTROL=ignorespace
shopt -s histappend
# think about separating out history files
#export HISTFILE="${HOME}/.history/$(date -u +%Y/%m/%d.%H.%M.%S)_${HOSTNAME}_$$"
@davidkuster
davidkuster / singlyLinkedList.groovy
Created August 5, 2015 15:38
Reversing a Singly Linked List
// comparing my thoughts on how to answer this common question, vs what was found at the following link:
// http://www.programmerinterview.com/index.php/data-structures/reverse-a-linked-list/
// In the link above, the recursive solution works in an interview to prove you can think recursively,
// but doesn't work in a real-world scenario because it's prone to stack overflow errors.
class Node {
Node next
Integer i
String toString() { i as String }
@davidkuster
davidkuster / fib.groovy
Created August 5, 2015 15:09
Tail Recursive Fibonacci
// Single stack frame. Returns the "Nth" Fibonacci number - aka the Nth number in the sequence.
def fibIter
fibIter = { int step, int endStep, long currVal, long nextVal ->
if ( step == endStep ) return currVal
fibIter.trampoline( ++step, endStep, nextVal, currVal+nextVal )
}.trampoline()
def fibonacci = { int seqNum ->
if ( seqNum < 0 ) println "fail" // needs better error handling
@davidkuster
davidkuster / .bash_aliases
Created December 30, 2014 13:56
bash aliases
# directory shortcuts
alias home='cd ~'
alias work='cd ~/workspace'
alias proj='cd ~/projects'
alias doc='cd ~/Documents'
alias down = 'cd ~/Downloads'
# navigation shortcuts
alias ..='cd ..'
alias ..2='cd ../..'
@davidkuster
davidkuster / .slate.js
Last active March 7, 2017 21:36
Slate JS config
// slate javascript config
// global configs
slate.log("-- setting up global configs --");
slate.configAll({
defaultToCurrentScreen: false,
orderScreensLeftToRight: true,
checkDefaultsOnLoad: true,
nudgePercentOf: "screenSize",