Skip to content

Instantly share code, notes, and snippets.

View bherrmann7's full-sized avatar

Bob Herrmann bherrmann7

View GitHub Profile
// Groovy script to dump the browser's headers
ServerSocket ss = new ServerSocket();
ss.bind(null)
println "listening on "+ss.getLocalPort();
Socket s = ss.accept()
s.getInputStream().eachLine { line ->
println line
/*
* HumanTime.java
*
* Created on 06.10.2008
*
* Copyright (c) 2008 Johann Burkard (<mailto:[email protected]>) <http://eaio.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
// Firebug script to set all checkboxs
ee = document.getElementsByTagName("input"); for(i=0;i<ee.length;i++){ ee[i].checked = true };
package jbum.pdf;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
int numberOfColumns = row.getMetaData().getColumnCount();
print "Columns:"
(1..numberOfColumns).each {n ->
print " $n:${row.getMetaData().getColumnName(n)}"
}
println('')
@bherrmann7
bherrmann7 / gist:208598
Created October 12, 2009 18:21
how to record some of what a closure does when it runs
// CriteriaRecorder - this gist lets you wrap a closure so you can record and manipulate the list of things the closure attempts to invoke.. Good for unit testing closures which build up GORM requests
class Node {
String name
def args
String render(StringBuilder sb, int level){
sb.append ' '.multiply(level*4)
sb.append name+'('+args.join(',')+')\n'
// validate a schema using relagNG
// 1. download jing from http://code.google.com/p/jing-trang/
// 2. copy the jing.jar into $GROOVY_HOME/lib
// 3. now copy/paste this into the groovy console and have fun!!!
import com.thaiopensource.util.PropertyMapBuilder;
import com.thaiopensource.validate.*
import com.thaiopensource.validate.rng.CompactSchemaReader;
import com.thaiopensource.xml.sax.ErrorHandlerImpl;
import org.xml.sax.InputSource;
// input: someGroovyCodeToTakeCamelCaseAndMakeItNicer
// output: Some Groovy Code To Take Camel Case And Make It Nicer
def str = 'someGroovyCodeToTakeCamelCaseAndMakeItNicer'.collect {
(Character.isUpperCase(it as char)?' ':'') + it
}.join()
str = str[0].toUpperCase() + str[1..-1]
// Just cut/paste this into a GroovyConsole to evaluate. (last line is used for testing)
// input: MY_ENUM_NAME output: myEnumName
String enumToJava(String name){
boolean lastUnder=false
name.collect {
if(it=='_') {
lastUnder = true;
return ''
}
def c = it
assert getEnumName('getPoeHoeFoe') == 'POE_HOE_FOE'
String getEnumName(methodName){
def str = methodName.collect {
(Character.isUpperCase(it as char)?'_':'') + it
}.join()
str = str[4..-1].toUpperCase()
}