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 / fork_with_new_connection.rb
Created February 24, 2011 17:58
Forking Processes In Ruby On Rails
# Logic for forking connections
# The forked process does not have access to static vars as far as I can discern, so I've done some stuff to check if the op threw an exception.
def fork_with_new_connection
# Store the ActiveRecord connection information
config = ActiveRecord::Base.remove_connection
pid = fork do
# tracking if the op failed for the Process exit
success = true
@danieldbower
danieldbower / canon-date.sh
Created June 8, 2011 13:00
Rename Canon picture files with ExifTool
###############################################################
# canon-date.sh
# Renames photos taken by Canon Digital Cameras into something
# more sortable and useful.
#
# Depends on exiftool
#
# Download, make executable, and then run ./canon-date.sh in the
# directory of the photos you want to rename. The script will
# create sub-directories by year and month.
@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 / pom.xml
Created May 25, 2017 15:13
snippet of pom showing excluding of bouncycastle libs from maven shade / dropwizard
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<excludes>
<exclude>org.bouncycastle:*</exclude>
@danieldbower
danieldbower / xmlfile.py
Last active March 28, 2017 13:29 — forked from benbramley/xmlfile.py
Ansible lookup plugin for XML files
from __future__ import (absolute_import, division)
__metaclass__ = type
from ansible.errors import AnsibleError
from ansible.plugins.lookup import LookupBase
from ansible.utils.listify import listify_lookup_plugin_terms
import xml.etree.ElementTree as etree
# Version for Ansible 2.0
# forked from https://gist.github.com/benbramley/xmlfile.py
@danieldbower
danieldbower / gist:2044916
Created March 15, 2012 15:53
ExternalConfigLoader
package com.example.app.config.logging;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
@danieldbower
danieldbower / ApacheCommonsConfigPropertySource.java
Created May 15, 2012 15:06
ApacheCommonsConfigPropertySource for using Apache Commons Config with Spring Property Sources
package com.bowerstudios.config;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.commons.configuration.Configuration;
import org.springframework.core.env.EnumerablePropertySource;
/**
@danieldbower
danieldbower / someClasses.java
Created March 2, 2012 14:50
Serializing BindingResult Errors to JSON
package model;
import java.util.List;
import java.util.Map;
import org.codehaus.jackson.annotate.JsonAutoDetect;
import org.codehaus.jackson.annotate.JsonAutoDetect.Visibility;
import org.codehaus.jackson.annotate.JsonProperty;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;