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)))
(defmacro spy [expr] `(let [a# ~expr] (println (str '~expr " => " a#)) a#))
@bherrmann7
bherrmann7 / gist:9002398
Created February 14, 2014 14:55
A user script (I use chrome's tamper monkey) for making hacker news cleanly more informational (ie. remove visual clutter... IMHO)
// ==UserScript==
// @name HackerNews Scrubbed
// @namespace http://jadn.com/bob
// @version 0.1
// @description enter something useful
// @match https://news.ycombinator.com/*
// @copyright 2014+, bherrmann
// ==/UserScript==
document.getElementsByTagName("table")[0].getElementsByTagName("tr")[0].style.display="none";
@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
'''
// 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 schema2hibernate('take_this') == 'takeThis'
def schema2hibernate = { table_name ->
boolean lastUnder = false
table_name.collect {
if( it == '_' ){
lastUnder = true
return ''
}
if (lastUnder) {
lastUnder = false
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]