Guice Documentation
Drawing Trees using d3.js
This is a great article on how to construct plant like images from simple rules in d3:
Generating artificial plants using stochastic Lindenmayer systems with d3.js
This could be the basis of a tamogotchi game.
Minimal Groovy neo4j client
@Grab(‘org.codehaus.groovy.modules.http-builder:http-builder:0.7.2’)
import groovyx.net.http.RESTClient
import groovy.json.JsonSlurper
def authToken = ‘neo4j:password’.bytes.encodeBase64().toString()
def auth = “Basic: $authToken”.toString()
// send Cypher statement to Neo4j Server
def client = new RESTClient( ‘http://localhost:7474’, ‘application/json’ )
client.defaultRequestHeaders.’Authorization’ = auth
def body = “””{
“statements” : [ {
“statement” : “CREATE (wordsworth:Author {firstname:’William’, lastname: ‘Wordsworth’})”
} ]
}”””
def resp = client.post( path : ‘/db/data/transaction/commit’, body : body )
println resp.data.toString()
Handlebars (Java) Templates and Extensions are really powerful
I have recently moved a project from using Thymeleaf to using Handlebars.
Handlebars is a templating library (think mail merge for code if you are a non-developer).
Handlebars uses the {{ }} tags to surround items to be replaced.
{{{ }}} will not escape content provided.
{{ > path/to/file }} Renders a template. You can supply named blocks that get substituted into that template.
By default the template uses whatever data that the template was bound to. Typically we bind nested Maps.
One of the principles of handlebars is that the templates should be logic free. This means that you are limited to {{#if }}, {{#unless }} and {{#each }} blocks.
#If will check the truthiness of a value. The intent is to include a block of template only if a certain item is present, say an optional middle name.
#unless is the inverse, it will only show the block if the condition is false. This is ideal for providing defaults for missing data.
Any logic above this must be handled by an extension method.
This is not as difficult as it sounds. With a little effort extension methods can be written to:
- Invoke a template name specified in a variable.
- Perform custom sorting of data acting as a custom loop over a supplied block.
By keeping the logic isolated it becomes independently testable and simplifies the templates.
Adding Handlebars Extensions
https://jknack.github.io/handlebars.java/helpers.html
The trick would be to replicate the mustache versions.
Macs are fundamentally insecure
This article shows how to reset the admin password:
http://www.cnet.com/uk/how-to/reset-bypass-password-mac-macbook/
This means that if you have physical access to a mac then security is a joke.
Note to self on Kindle
Convert epub to mobi then send to Kindle.
Thoughts on Groovy
I have been working in Groovy for about a month now.
It’s definitely a step up from Java in terms of dialing down the ceremony.
However the scripting nature can be nasty on occasions where the compiler just does not protect you from obvious mistakes.
JRuby on windows fix
Could not load FFI Provider: (NotImplementedError) FFI not available