Skip to content

Instantly share code, notes, and snippets.

View rbe's full-sized avatar

Ralf Bensmann rbe

View GitHub Profile
@rbe
rbe / butlast.groovy
Created August 28, 2010 10:26
butLast
[[], java.util.List].each {
it.metaClass.butLast = {
delegate - delegate.last()
}
}
package com.bensmann.xml
class CachedDTD {
/**
* Return DTD 'systemId' as InputSource.
* @param publicId
* @param systemId
* @return InputSource for locally cached DTD.
*/
def static entityResolver = [
resolveEntity: { publicId, systemId ->
class GroovyHelper {
/**
* Copy a stream using a certain buffer size.
*/
def static copyStream = { from, to, bufKb = 1 ->
byte[] buf = new byte[bufKb * 1024]
def len = 0
while ((len = from.read(buf)) > 0) {
to.write(buf, 0, len)
class FileRouter extends org.apache.camel.language.groovy.GroovyRouteBuilder {
/**
* Define routes for Camel.
*/
protected void configure() {
//
// Route 1
//
// Watch directory for incoming file
public class CPTest {
public static void main(String[] args) {
// Create queue
Queue q = new Queue();
// Start producers
Producer p = new Producer(q);
for (int i = 0; i < 3; i++) {
new Thread(p).start();
}
// Start consumer
#!/bin/sh
OOO_HOME=/Applications/OpenOffice.org.app/Contents
OOO_HOST=
OOO_PORT="2002 2003 2004 2005"
USER_HOME=/tmp
_create_home() {
port=$1
home=${USER_HOME}/user/port${port}
mkdir -p ${home}
public class PipeTest {
public static void main(String[] args) throws java.io.IOException, java.lang.InterruptedException {
java.lang.Runtime rt = java.lang.Runtime.getRuntime();
// Start three processes: ps ax | grep rbe | grep JavaVM
java.lang.Process p1 = rt.exec("ps ax");
java.lang.Process p2 = rt.exec("grep rbe");
java.lang.Process p3 = rt.exec("grep JavaVM");
// Start piping
java.io.InputStream in = Piper.pipe(p1, p2, p3);
@rbe
rbe / intListToInt.hs
Created January 20, 2011 15:20
Convert a list of integers into a single integer
-- Convert list of integer to one integer: [1,2,3,4] to 1234.
intListToInt :: [Integer] -> Integer
intListToInt = foldl (\a x -> x + a * 10) 0
@rbe
rbe / Hompare.hs
Created January 20, 2011 15:23
Hompare Module
module Hompare
(
jaroWinkler
, levenshtein
, cologneMethod
)
where
import Prelude
import Data.Char (toUpper)
@rbe
rbe / commonPrefix.hs
Created January 20, 2011 15:24
Common prefix of two strings, upto first four characters
-- Common prefix of two strings; up to 4 characters
commonPrefix :: String -> String -> String
commonPrefix "" "" = ""
commonPrefix "" _ = ""
commonPrefix _ "" = ""
commonPrefix s1 s2
| s1 == s2 = take 4 s1
| otherwise = cp s1 s2 []
where
cp s1 s2 acc