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
  • 13:33 (UTC -04:00)
View GitHub Profile
@darrend
darrend / final_test_notification.png
Last active July 17, 2020 19:47
teeshout potential blog post
final_test_notification.png
@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);
}
package scripts.rest
def values = [:]
params.each { name, value -> values[name] = value }
headers.each { name, value -> values[name] = value }
cookies.each { name, value -> values[name] = value }
sessionAttributes.each { name, value -> values[name] = value }
return values
@darrend
darrend / counterwithlambda.rb
Last active December 24, 2015 16:58
Is there a tighter way to do this?
num_fragments = 0
counter = lambda { num_fragments += 1 }
@darrend
darrend / bashtricks.markdown
Created October 28, 2015 17:35
bash tricks
yell() { echo "$0: $*" >&2; }
die() { yell "$*"; exit 111; }
try() { "$@" || die "cannot $*"; }
scriptdir() { (cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd) }
/* Author: Darren Day
*/
function handleResponse(data) {
var source = $("#template").html();
var template = Handlebars.compile(source);
var result = template({
"links": data
});
$("#main").append(result);
@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) {
@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 / 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