Skip to content

Instantly share code, notes, and snippets.

View danieldbower's full-sized avatar

Daniel Bower danieldbower

View GitHub Profile
@danieldbower
danieldbower / ClipboardUtils.groovy
Created May 31, 2012 18:31
Working with the System Clipboard from Groovy
import java.awt.datatransfer.StringSelection
import java.awt.Toolkit
import java.awt.datatransfer.*
class ClipboardUtils{
static final Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard()
static void setClipboardContents(final String contents){
clipboard.setContents(new StringSelection(contents), null)
}
@danieldbower
danieldbower / pom.xml
Created July 24, 2012 19:11
jasperreports-maven-plugin usage in a web application
<properties>
<jasperreports.version>4.6.0</jasperreports.version>
<groovy.version>1.8.6</groovy.version>
</properties>
<dependencies>
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>${jasperreports.version}</version>
@danieldbower
danieldbower / load-java-alternatives.groovy
Created August 16, 2012 17:30
Load-java-alternatives (another way of doing it)
//sudo update-alternatives --display
//sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/java-6-sunjdk-amd64/bin/java" 1
Map<String, String> javaVersions=['6':"java-6-openjdk-amd64", '6s':"java-6-sunjdk-amd64", '7':"java-7-openjdk-amd64"]
javaVersions.each{String version, String name ->
StringBuilder sb = new StringBuilder()
String jreBinaryPath="/usr/lib/jvm/${name}/jre/bin/"
@danieldbower
danieldbower / javaSwitch.sh
Created August 16, 2012 17:43
Switch Java Versions on Debian/Ubuntu
#!/bin/sh
clear
f_o6 () {
export JAVA_HOME=/usr/lib/jvm/java-6-openjdk-amd64;
sudo update-alternatives --set java /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java;
}
f_s6 () {
@danieldbower
danieldbower / pom.xml
Created September 6, 2012 17:46
CAS 3.5 with attributes
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.bowerstudios</groupId>
<artifactId>cas</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<build>
@danieldbower
danieldbower / deployerConfigContext.xml
Created September 6, 2012 17:59
CAS 3.5 with attributes
<?xml version="1.0" encoding="UTF-8"?>
<!-- | deployerConfigContext.xml centralizes into one file some of the declarative
configuration that | all CAS deployers will need to modify. | | This file
declares some of the Spring-managed JavaBeans that make up a CAS deployment.
| The beans declared in this file are instantiated at context initialization
time by the Spring | ContextLoaderListener declared in web.xml. It finds
this file because this | file is among those declared in the context parameter
"contextConfigLocation". | | By far the most common change you will need
to make in this file is to change the last bean | declaration to replace
the default SimpleTestUsernamePasswordAuthenticationHandler with | one implementing
@danieldbower
danieldbower / DbUtil.java
Created October 29, 2013 15:20
Extract underlying Oracle connection from Jboss Wrapped connection, and create Oracle Clob Parameter
package com.bowerstudios.myapp.dao;
import java.io.Writer;
import java.sql.Connection;
import java.sql.SQLException;
import oracle.jdbc.OracleConnection;
import oracle.sql.CLOB;
import org.jboss.resource.adapter.jdbc.WrappedConnection;
@danieldbower
danieldbower / retainAllExample.groovy
Created January 30, 2014 21:55
Groovy retainAll example with Closure
def a = [[id:"a"], [id:"b"], [id:"c"]]
def b = ["a", "b"]
a.retainAll(){
println it
b.contains(it.id)
}
println a
@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")
}