Skip to content

Instantly share code, notes, and snippets.

View bherrmann7's full-sized avatar

Bob Herrmann bherrmann7

View GitHub Profile
(ns app.fortune
#?(:cljs (:require-macros app.fortune))
(:require #?(:clj [clojure.java.shell :as sh])
[hyperfiddle.electric :as e]
[hyperfiddle.electric-dom2 :as dom]
[hyperfiddle.electric-ui4 :as ui]))
#?(:clj (defn fortune [] (:out (sh/sh "fortune"))))
#?(:clj (defonce !x (atom (fortune))) )
(e/def x (e/server (e/watch !x)))
@bherrmann7
bherrmann7 / gist:518889
Created August 11, 2010 12:11
Java code for finding properties (is/get/set pairs)
// Java code for finding properties (is/get/set pairs)
for(Method method: bean1.getClass().getMethods()){
if(method.getDeclaringClass()!=AccountRequest.class || !(method.getName().startsWith("get") || method.getName().startsWith("is")) || method.getTypeParameters().length!=0)
continue;
String propName = method.getName().substring(2,method.getName().length());
if(method.getName().startsWith("get")){
propName = method.getName().substring(3,method.getName().length());
}
Method setter = null;
try {
@bherrmann7
bherrmann7 / gist:449466
Created June 23, 2010 03:45
Takes table columns and generates fields and get/setters for hibernate classes
// Takes table columns and generates fields and get/setters for hibernate classes
def schema = '''
full_name varchar(64) not null,
given_name varchar(32),
middle_initial varchar(1),
last_name varchar(32),
creation_time datetime, -- some comment
'''
// assert schema2hibernate('take_this') == 'takeThis'
def schema2hibernate = { table_name ->
boolean lastUnder = false
table_name.collect {
if( it == '_' ){
lastUnder = true
return ''
}
if (lastUnder) {
lastUnder = false
// Move text to the clipboard
def clfile = 'some interesting string'
java.awt.datatransfer.StringSelection data = new java.awt.datatransfer.StringSelection(clfile);
java.awt.Toolkit.getDefaultToolkit().getSystemClipboard().setContents(data, data);
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()
}
// 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
// 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]
// 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;
@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'