Skip to content

Instantly share code, notes, and snippets.

View joshareed's full-sized avatar

Josh Reed joshareed

View GitHub Profile
class Person {
String firstName
String lastName
transient getFullName() { "${firstName} ${lastName}" }
}
if (condition)
statement
else {
statement
statement
}
def dir = new File(args.length > 0 ? args[0] : "/Users/josh/Desktop/image")
def fps = args.length > 1 ? args[1] as int : 10
def parser = new java.text.SimpleDateFormat(args.length > 2 ? args[2] : "yyyy_MM_dd_-_hh_mm_ss.SSS")
def formatter = new java.text.SimpleDateFormat("hh:mm:ss")
// find all image files and sort them by the date encoded in the filename
def files = [:] as TreeMap
dir.eachFileMatch(~/.*\.jpg/) { file ->
def date = parser.parse(file.name - "_UTF.jpg")
files[date.time] = file
List.metaClass.safeFirst = { -> delegate[0] }
List.metaClass.safeLast = { -> delegate.size() > 0 ? delegate[-1] : null }
def a = []
assert null == a.safeFirst()
assert null == a.safeLast()
a += [1,2]
assert 1 == a.safeFirst()
assert 2 == a.safeLast()
@joshareed
joshareed / gist:1107973
Created July 26, 2011 20:48
Log output
2011-07-26 16:47:50,809 [TP-Processor25] DEBUG facebook.FacebookController - params: [id:660, action:challenge, controller:facebook]
2011-07-26 16:47:50,812 [TP-Processor25] ERROR util.FacebookHelperService - Couldn't tokenize signedRequest: null
2011-07-26 16:47:50,813 [TP-Processor25] DEBUG facebook.FacebookController - signed request: [:]
2011-07-26 16:47:50,814 [TP-Processor25] DEBUG facebook.FacebookController - person: null person.id: null uid: null pid: null isPageAdmin: null
@joshareed
joshareed / gist:1561792
Created January 4, 2012 20:04
Groovy Assert Gotcha
def sb = new StringBuffer("Foo")
def foo = "Foo"
assert sb == foo
/**
assert sb == foo
| | |
Foo| Foo
false
*/
@joshareed
joshareed / commit-msg
Created December 6, 2012 18:54
Git hook for adding Lean-To tags to commit messages
#!/bin/sh
# A commit hook script that automatically tags commits for Lean-To integration if you use a branching scheme
# bug/<num> or story/<num>
#
# Drop this file into your repos .git/hooks/ directory as 'commit-msg'
LEANTO="1179"
# figure out bug/story and id
14:01:59.232 DEBUG <> [ ] {} (localhost-startStop-1) conf.BootStrap - Registering JSON object marshaller on: Artefact > Location
14:01:59.232 DEBUG <> [ ] {} (localhost-startStop-1) conf.BootStrap - Registering JSON object marshaller on: Artefact > Mode
14:01:59.365 ERROR <> [ ] {} (localhost-startStop-1) context.GrailsContextLoader - Error executing bootstraps: java.lang.ExceptionInInitializerError
org.codehaus.groovy.runtime.InvokerInvocationException: java.lang.ExceptionInInitializerError
at grails.util.Environment.evaluateEnvironmentSpecificBlock(Environment.java:301)
at grails.util.Environment.executeForEnvironment(Environment.java:294)
at grails.util.Environment.executeForCurrentEnvironment(Environment.java:270)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
/**
* Scheduled On and Off
*
* Author: SmartThings
*/
def preferences()
{
return [
sections: [
// simulates random messages from a contact sensor via socket to dev-conn
RANDOM = new Random()
MESSAGES = [
"zone report :: type: 19 value: 0031",
"zone report :: type: 19 value: 0030"
]
ENV = [
josh: [