Skip to content

Instantly share code, notes, and snippets.

@gfrison
gfrison / groovy-date-time-operations
Created February 5, 2011 15:00
How to add months, days, years to a date in Groovy
Groovy also has a Time Category class which gives you DSL style syntax for manipulating dates. Here is an example:
import org.codehaus.groovy.runtime.TimeCategory
now = new Date()
println now
use(TimeCategory) {
footballPractice = now + 1.week - 4.days + 2.hours - 3.seconds
}
println footballPractice
which will produce output like this:
@gfrison
gfrison / gist:1186421
Created September 1, 2011 15:27
app.config
%% -*- tab-width: 4;erlang-indent-level: 4;indent-tabs-mode: nil -*-
%% ex: ts=4 sw=4 et
[
{default_bucket_props, [{n_val,1},
{allow_mult,false},
{last_write_wins,false},
{precommit, []},
{postcommit, []},
{chash_keyfun, {riak_core_util, chash_std_keyfun}},
{linkfun, {modfun, riak_kv_wm_link_walker, mapreduce_linkfun}}
@gfrison
gfrison / gist:1188105
Created September 2, 2011 07:37
add mapping contentType riak-java-client
Index: src/main/java/com/basho/riak/pbc/RiakObject.java
===================================================================
--- src/main/java/com/basho/riak/pbc/RiakObject.java (revision 84)
+++ src/main/java/com/basho/riak/pbc/RiakObject.java (revision 125)
@@ -244,4 +244,8 @@
return d;
}
+ public String getContentType() {
+ return contentType;
@gfrison
gfrison / gist:1347781
Created November 8, 2011 13:53
groovy camel builder script
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.language.groovy.GroovyRouteBuilder;
import org.apache.camel.*
@Grab(group='org.slf4j', module='slf4j-api', version='1.6.1')
@Grab(group='org.slf4j', module='slf4j-log4j12', version='1.6.1')
@Grab(group='org.apache.camel', module='camel-groovy', version='2.8.0')
@Grab(group='org.apache.camel', module='camel-core', version='2.8.0')
@Grab(group='org.apache.camel', module='camel-jetty', version='2.8.0')
class SampleRoute extends GroovyRouteBuilder {
@gfrison
gfrison / gist:1348082
Last active September 27, 2015 23:18
script bash for performance testing on RESTful services. It measures quickly how long does it take accomplish http requests
#!/bin/bash
START=$(date +%s.%N)
for i in {1..100};
do
curl http://localhosT:3000/rest -d '<request>'>/dev/null 2>&1
done;
END=$(date +%s.%N)
DIFF=$(echo "$END - $START" | bc)
@gfrison
gfrison / Affinity.groovy
Created February 20, 2012 16:34
Rate affinity score between 2 web sites
package com.gfrison
import groovy.json.*
import static org.apache.commons.lang3.StringUtils.*
/**
* @author Giancarlo Frison <giancarlo@gfrison.com>
*
* rate the affinity between 2 different web sites
*
@gfrison
gfrison / gist:2653014
Created May 10, 2012 13:32
truncating a string in javascript according to the REAL length of chars and tooltip the full-size string in the element
//just to avoid 'string ...' with spaces
//trim a string http://stackoverflow.com/a/498995
String.prototype.trim=function(){return this.replace(/^\s\s*/, '').replace(/\s\s*$/, '');};
//improvement of this: http://blog.mastykarz.nl/measuring-the-length-of-a-string-in-pixels-using-javascript/
var visualLength = function(str){
var ruler = document.createElement('span');
ruler.style.visibility = 'hidden';
ruler.style['white-space'] = 'nowrap';
document.body.appendChild(ruler);
@gfrison
gfrison / gist:2701839
Created May 15, 2012 13:36
pack files containing specific text
grep ‘text-2-search’ * | cut -f1 -d':' | xargs tar -zcvf pack.tar.gz
@gfrison
gfrison / main.js
Created January 16, 2014 22:37 — forked from carchrae/main.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;
@gfrison
gfrison / doublets.groovy
Created February 17, 2014 12:04
Dodgsons doublets in Groovy. The rules of the Puzzle are simple enough. Two words are proposed, of the same length; and the Puzzle consists in linking these together by interposing other words, each of which shall differ from the next word in one letter only. That is to say, one letter may be changed in one of the given words, then one letter in…
import com.thoughtworks.xstream.core.util.PrioritizedList
import groovy.transform.Field
import java.text.DecimalFormat
/**
* Dodgsons Duoblets
*
* User: gfrison
* http://programmingpraxis.com/2009/03/20/dodgsons-doublets/