Skip to content

Instantly share code, notes, and snippets.

View danieldbower's full-sized avatar

Daniel Bower danieldbower

View GitHub Profile
@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 / 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 / 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 / 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 / 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;
@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 / 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;
@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;
/**