Skip to content

Instantly share code, notes, and snippets.

View oehme's full-sized avatar

Stefan Oehme oehme

View GitHub Profile
@oehme
oehme / wrapping-calion-and-boolean
Created June 13, 2012 15:08
Object wrapper extended to calion and booleans
@Override
public TemplateModel wrap(Object object) throws TemplateModelException {
//Joda time stuff omitted
if (object instanceof Enum && object.getClass().isAnnotationPresent(BaseName.class)) {
return super.wrap(lookUp((Enum<?>) object));
}
if (object instanceof MessageParameterObj) {
return super.wrap(lookUp((MessageParameterObj) object));
}
@oehme
oehme / localized-boolean
Created June 13, 2012 15:11
Localized Boolean
public class LocalizedBooleanModel implements TemplateScalarModel, TemplateBooleanModel {
private final boolean value;
private final String yes;
private final String no;
public LocalizedBooleanModel(boolean value, String yes, String no) {
this.value = value;
this.yes = yes;
this.no = no;
@oehme
oehme / I18n-easyway-finished-java
Created June 13, 2012 15:14
Freemarker i18n the easy way - Java side
public static Map<String, Object> getDataModel() {
HashMap<String, Object> datamodel = new HashMap<>();
datamodel.put("date", new LocalDate());
datamodel.put("time", new LocalTime());
datamodel.put("month", new YearMonth());
datamodel.put("boolean", true);
datamodel.put("greeting", new MessageParameterObj(Messages.HELLO, "Freemarker"));
return datamodel;
}
@oehme
oehme / I18n-easyway-finished-ftl
Created June 13, 2012 15:15
Freemarker i18n the easy way - FTL side
${date}
${time}
${month}
${boolean}
[#if boolean]${greeting}[/#if]
@oehme
oehme / gist:4352166
Last active December 10, 2015 00:38
Vivify Enlive example
class AnimalRow extends Snippet {
new(Animal animal, int idx) {
super("/animal/animal.html", ".per_animal_row")
transform
=> sub [
select("input.true_name")
=> newName("true_name",idx)
=> attr("value", animal.trueName)
select("input.species")
@oehme
oehme / gist:4352207
Created December 21, 2012 11:15
Enlive Example HTML
<form action="/herd_changes" method="post" id="animal_addition_form">
<table>
<tr class="per_animal_row">
<td>
<input type="text" class="true_name" name="true_name"/>
</td>
<td>
<select class="species" name="species">
<option selected="selected">Bovine</option>
@oehme
oehme / Usually.xtend
Last active December 11, 2015 10:39
Active Annotations finally bring the preciseness of the specification into my code.
Xtend:
@Usually
def doStuff() {
println("This usually doesn't fail")
}
generated Java:
public void doStuff() {
@oehme
oehme / gist:4737130
Created February 8, 2013 06:42
Force drop user in Oracle database
DECLARE
open_count integer;
BEGIN
-- prevent any further connections
EXECUTE IMMEDIATE 'alter user @USERNAME account lock';
--kill all sessions
FOR session IN (SELECT sid, serial#
FROM v$session
WHERE username = '@USERNAME')
LOOP
@oehme
oehme / gist:5180879
Last active December 15, 2015 01:38
Memoized fibonacci method - Xtend source
@Memoize def BigInteger fibonacci(int n) {
switch n {
case 0: 0bi
case 1: 1bi
default: fibonacci(n - 1) + fibonacci(n - 2)
}
}
@oehme
oehme / gist:5180925
Last active December 15, 2015 01:38
Memoized fibonacci method - Generated Java code
@Memoize
public BigInteger fibonacci(final int n) {
try {
return fibonacci_cache.get(n);
} catch(Throwable e) {
throw Exceptions.sneakyThrow(e.getCause());
}
}
private BigInteger fibonacci_init(final int n) {