This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 | |
''' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// assert schema2hibernate('take_this') == 'takeThis' | |
def schema2hibernate = { table_name -> | |
boolean lastUnder = false | |
table_name.collect { | |
if( it == '_' ){ | |
lastUnder = true | |
return '' | |
} | |
if (lastUnder) { | |
lastUnder = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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' |
NewerOlder