Skip to content

Instantly share code, notes, and snippets.

View darrend's full-sized avatar
💻
Learning

Darren Day darrend

💻
Learning
  • Growth Acceleration Partners
  • Lexington, KY
  • 08:10 (UTC -04:00)
View GitHub Profile
@darrend
darrend / WindupMockingExperiment.java
Created June 11, 2010 16:37
wrote this before Chuck told me about mockito; i guess this has the advantage of no dependencies at all
import java.util.List;
import java.util.LinkedList;
import java.util.Arrays;
import java.lang.reflect.Proxy;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
/**
* Mocks interfaces with a series of pre-determined calls and preloaded return values.
*
#! /usr/local/bin/ruby
# First stab at a svn log watcher for user ohnojoe.
# SvnRecord also allows you to easily extend the script to match on certain file names/package names
# that you want to watch.
SVN_CMD = 'svn log -l 30 -v https://my.svn.server.com/Project/branches/'
FILE_MATCH = '\/branches\/.*'
USERS_WATCHED = %w{ ohnojoe }
#! /usr/bin/ruby
require 'time'
ASIDES_FILE = "/Users/darrend/anaside.txt"
# grab something and stick it somewhere
if(ARGV.nil? ||ARGV.empty?)
puts %x(cat #{ASIDES_FILE})
else
line = ARGV.join(" ")
File.open(ASIDES_FILE, 'a') {|f| f.puts("#{Time.now.iso8601} | #{line}")}
@darrend
darrend / daemonesque_preamble.rb
Created February 4, 2011 21:35
This dirty dirty preamble allows you to drop a ruby script into a cronfile...it will kill the previous incarnation...so lame it is awesome
# kill the process if it is running
PIDFILE = "/var/run/stream_load.pid"
def read_pidfile
begin
File.open(PIDFILE,"r") { |file| return file.gets.to_i }
rescue
puts "pidfile not found or invalid"
end if File.exists?(PIDFILE)
puts "no pidfile readable"
@darrend
darrend / deepCopyJAXB.java
Created February 10, 2011 21:45
deep copy an object using jaxb
public static <T> T deepCopyJAXB(T object, Class<T> clazz) {
try {
JAXBContext jaxbContext = JAXBContext.newInstance(clazz);
JAXBElement<T> contentObject = new JAXBElement<T>(new QName(clazz.getSimpleName()), clazz, object);
JAXBSource source = new JAXBSource(jaxbContext, contentObject);
return jaxbContext.createUnmarshaller().unmarshal(source, clazz).getValue();
} catch (JAXBException e) {
throw new RuntimeException(e);
}
@darrend
darrend / DeepCopier.java
Created May 19, 2011 19:49
using jaxb to create deepcopies of objects, and build them from strings
import javax.xml.bind.*;
import javax.xml.bind.util.JAXBSource;
import javax.xml.namespace.QName;
import javax.xml.transform.stream.StreamSource;
public class DeepCopier<T> {
private static QName qname = new QName("deepcopy");
private Unmarshaller unmarshaller;
private JAXBElement<T> contentObject;
private Marshaller marshaller;
@darrend
darrend / tcold.rb
Created May 19, 2011 19:53
a halfassed model for utility scripting for specific cases
#!/usr/bin/env ruby
# just some hackity hack to manage the remote tomcat on old-darrend-desktop
class TomcatOldEnvironment
def initialize targetslot
@targetslot = targetslot
end
def targetslot
@darrend
darrend / user.xml
Created February 27, 2012 20:37
idea live template to generate builder with clauses
<?xml version="1.0" encoding="UTF-8"?>
<templateSet group="user">
<template name="with" value="public $FooBuilder$ with$Foo$($FooType$ $foo$) {&#10; this.$foo$ = $foo$;&#10; return this;&#10;}" description="generate a builder with param setter" toReformat="true" toShortenFQNames="true">
<variable name="foo" expression="" defaultValue="" alwaysStopAt="true" />
<variable name="FooBuilder" expression="className()" defaultValue="" alwaysStopAt="false" />
<variable name="FooType" expression="typeOfVariable(foo)" defaultValue="" alwaysStopAt="false" />
<variable name="Foo" expression="capitalize(foo)" defaultValue="" alwaysStopAt="false" />
<context>
<option name="JAVA_CODE" value="true" />
<option name="JAVA_COMMENT" value="false" />
@darrend
darrend / Builder.java
Created February 28, 2012 16:00
a generic builder
import java.lang.reflect.Field;
/**
* Utility method for quickly building mock models
*/
public class Builder {
public static <T> T build(Class<T> clazz, Object... keyValues) {
try {
return build(clazz, clazz.newInstance(), keyValues);
} catch (InstantiationException e) {
/* Author: Darren Day
*/
function handleResponse(data) {
var source = $("#template").html();
var template = Handlebars.compile(source);
var result = template({
"links": data
});
$("#main").append(result);