This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[[], java.util.List].each { | |
it.metaClass.butLast = { | |
delegate - delegate.last() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 -> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FileRouter extends org.apache.camel.language.groovy.GroovyRouteBuilder { | |
/** | |
* Define routes for Camel. | |
*/ | |
protected void configure() { | |
// | |
// Route 1 | |
// | |
// Watch directory for incoming file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Convert list of integer to one integer: [1,2,3,4] to 1234. | |
intListToInt :: [Integer] -> Integer | |
intListToInt = foldl (\a x -> x + a * 10) 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Hompare | |
( | |
jaroWinkler | |
, levenshtein | |
, cologneMethod | |
) | |
where | |
import Prelude | |
import Data.Char (toUpper) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode 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 |
OlderNewer