Skip to content

Instantly share code, notes, and snippets.

@carchrae
carchrae / dust-context.js
Created June 20, 2013 18:01
add this javascript after you load dust.js and it will allow you to reference dot path contexts in nested scopes and globals. see https://github.com/linkedin/dustjs/pull/271 for more details
//supports dot path resolution, function eval, and searching global paths
Context.prototype.getPath = function(cur, down) {
var ctx = this.stack,
len = down.length,
tail = cur ? undefined : this.stack.tail;
if (cur && len === 0) return ctx.head;
ctx = ctx.head;
var i = 0;
package glwt.dust.rebind;
import java.io.PrintWriter;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import com.google.gwt.core.ext.CachedGeneratorResult;
@carchrae
carchrae / gist:5885201
Created June 28, 2013 14:42
ace to support versions of file
var editor = ace.edit("editor-container");
editor.setTheme("ace/theme/monokai");
if (!glwt.ace){
glwt.ace = { sessions : {} };
}
var oldSession = glwt.ace.sessions["{template.name}"];
var src = "{template.source|s|j}";
if (oldSession){
editor.setSession(oldSession);
@carchrae
carchrae / gist:5976820
Last active December 19, 2015 15:29
weird behaviour with gwt java editor
package bug;
import com.google.gwt.core.client.GWT;
public class FormatBug {
public boolean testVar;
public static void testMethodString(String s) {
GWT.log(s);
@carchrae
carchrae / main.js
Last active December 22, 2015 11:08
javascript verticle for template rendering with dust.js
var vertx = require("vertx.js")
var console = require('vertx/console');
console.log('module ' + JSON.stringify(module));
var dust;
var x = function(){
var module = undefined;
Handler<Throwable> onError = new Handler<Throwable>(Throwable.class) {
@Override
public Throwable handle(Throwable value) {
value.printStackTrace();
return value;
}
};
@carchrae
carchrae / Promise.java
Created October 2, 2013 14:19
My take on a java promise interface
public interface Promise<T> {
Promise<T> resolve(T value);
Promise<T> resolve(Promise<T> promise);
Promise<Throwable> reject(Throwable e);
Promise<T> then(CallbackFunction onResolved);
@carchrae
carchrae / build.xml
Created October 24, 2013 16:04
An ant build that includes source in a jar
<?xml version="1.0" encoding="utf-8" ?>
<project name="glwt" default="jar" basedir=".">
<property name="gwt.sdk" location="/home/tom/bin/gwt" />
<property name="dust.version" location="1.2.6" />
<property name="dust.path" location="/home/tom/code/javascript/dustjs" />
<property name="dust.path.src" location="${dust.path}/dist" />
<property name="dust.path.dst" location="src/glwt/dust/client/js" />
@carchrae
carchrae / Log.java
Created October 24, 2013 18:11
snippit of code for grabbing the stack/filename/lines in GWT
public class Log {
/*
* type - is "INFO", "DEBUG", "ERROR" etc
* object - is an "id" of the person calling it. as a convention, I use 'this' unless it is a static method, then I pass in the class
* msg - the log message
*/
public static void log(String type, Object object, String msg) {
ClientGetter playClientGetter = new ClientGetter() {
private int playPort;
private String playHost;
{
String portString = System.getenv("PLAY_PORT");
if (portString == null)
portString = "9000";
playPort = Integer.parseInt(portString);
playHost = System.getenv("PLAY_HOST");