Skip to content

Instantly share code, notes, and snippets.

View danieldbower's full-sized avatar

Daniel Bower danieldbower

View GitHub Profile
@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.
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)
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'
@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
@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