Skip to content

Instantly share code, notes, and snippets.

View danieldbower's full-sized avatar

Daniel Bower danieldbower

View GitHub Profile
@danieldbower
danieldbower / .bashrc
Created March 4, 2014 02:21
Disable -m (message parameter) in git command in bashrc
function git {
for arg
do
if [[ $arg == -m* || $arg == -[^-]*m* ]]
then
annoy_me
return 1
fi
done
command git "$@"
@danieldbower
danieldbower / groovyTruth.groovy
Last active August 29, 2015 13:59
Groovy Truth Examples
Map vals = ['Zero':0, 'Negative decimal':-0.01, 'Negative decimal':-0.05, 'Negative whole number':-1,
'Negative decimal':-1.5, 'One':1, 'Positive decimal':0.01, 'Positive decimal':0.05,
'Positive decimal':1.5, 'Empty string':'', 'Empty list':[], 'Empty hash':[:],
'Lower character':'a', 'Upper character':'A', 'Null':null
]
vals.each{ k, v ->
println (v ? "$k ( $v ) is true" : "$k ( $v ) is false")
}
@danieldbower
danieldbower / MinusEquals.groovy
Created April 15, 2014 13:28
Groovy minus equals
def vals = [50, 25, 5, 0, -5, -25, 50]
vals.each{
println "\n\nVal is $it"
int i = 50
i =- it
println "(50 =- $it) is equal to $i"
i = 50
@danieldbower
danieldbower / runtime.groovy
Created June 24, 2014 16:39
Arbitrary Groovy at Runtime
def binding = new Binding()
def shell = new GroovyShell(binding)
def script = '''println "hello world" '''
shell.evaluate(script)
@danieldbower
danieldbower / InfinumMysqlDialect.groovy
Created October 15, 2014 16:47
InfinumMysqlDialect - Add Decimal to RegisterColumnType
package com.infinum
import java.sql.Types
import org.hibernate.dialect.MySQL5Dialect
import org.hibernate.type.StandardBasicTypes
class InfinumMysqlDialect extends MySQL5Dialect {
InfinumMysqlDialect () {
super ()
@danieldbower
danieldbower / mangle.groovy
Created March 1, 2011 16:10
Example for Beginner's Guide to a Scripting Language
//
// data
//
def values = """821;1529;56
733;1530;56
749;1533;56
728;1534;56"""
//
// code
Date enddate = new Date()
Date startdate = enddate - 20
//headers
println "Date - Year - Quarter - Month - Month - Month - WeekOfYear - WeekOfMonth - DayInYear - DayInMonth - DayInWeek - DayInWeek - DayInWeek - Weekday/Weekend"
//loop through each day
(startdate..enddate).each{ day ->
//Is this a weekend or a weekday?
def weekendStatus = 'Weekday'
File file = new File("/tmp/time.csv")
//headers
file.append "key; hh:MMxm; HH:MM; hh; HH; MM; ampm;\n"
int key = 0
(0..23).each{ hour ->
String ampm = "am"
String upperHString = String.format('%02d', hour)
@danieldbower
danieldbower / motorolaDate.groovy
Created June 8, 2011 13:12
Rename Droid X picture files Groovy
/*
* motorolaDate.groovy
* Renames photos taken by Droid X Cameras into something
* more sortable and useful.
*
* runs with groovy http://groovy.codehaus.org/
*
* Download, edit the dirName variable, and then run:
* groovy motorolaDate.groovy
* The script will create sub-directories by year and month.
@danieldbower
danieldbower / TransferObjectListFactory.java
Created March 15, 2012 16:08
TransferObjectListFactory
package factory;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.collect.Lists;
import transferobject.TransferObject;