Skip to content

Instantly share code, notes, and snippets.

@tomgullo
tomgullo / update_ltree.sql
Created April 3, 2013 12:46
update_ltree.sql
update t_tree set path = text2ltree(replace( ltree2text(path), 'us.va', 'us.fl') );
@tomgullo
tomgullo / json_from_solr.groovy
Last active December 15, 2015 10:38
json_from_solr.groovy
def data = new URL(s).text
json = slurper.parseText(data)
json.response.docs
json.highlighting
json.facet_counts
json.responseHeader.QTime
json.response.numFound
for (e in docs) {
@tomgullo
tomgullo / ipv4.groovy
Last active December 15, 2015 03:09
ip to decimal conversion
def toStringIp(long l) {
return ( (l >> 24) & 0xFF) + "." + ( (l >> 16) & 0xFF) + "." +
( (l >> 8) & 0xff) + "." + (l & 0xFF);
}
def long toLong(String ip) {
if (!ip) {
return -1
}
def octets = ip.split("\\.")
@tomgullo
tomgullo / get_blob.groovy
Created February 12, 2013 12:20
get blob
//try
def blobFile = new File(fileName)
def outStream = new FileOutputStream(blobFile)
def blob = (oracle.sql.BLOB) result[0]
def inStream = blob.getBinaryStream()
int length = -1
int size = blob.getBufferSize()
byte[] buffer = new byte[size]
@tomgullo
tomgullo / stack_test.groovy
Created February 7, 2013 14:14
stack that is fast for push, pop and min
l = []
l2 = []
def push(def num) {
if (l) {
l2 << ( (l[l.size() - 1] < num) ? l[l.size() -1] : num )
} else {
l2 << num
}
l << num
@tomgullo
tomgullo / fibonacci.groovy
Created January 25, 2013 17:29
fibonacci test
def fibo(x) {
if (x < 2) {
return x
} else {
return fibo(x-1) + fibo(x-2)
}
}
println( (1..10).collect { fibo(it) }.join(",") )
@tomgullo
tomgullo / get_coordinate_pascal_triangle.groovy
Created January 24, 2013 20:00
get coordinate for pascal triangle
/*
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
*/
@tomgullo
tomgullo / get_max_using_recursion.groovy
Last active December 11, 2015 06:09
get max using recursion
def getMax(List list, int max) {
/* TODO - error handling null values etc */
if (list.size() == 1) {
return (list[0] > max) ? list[0] : max
} else if ( list[0] > max) {
getMax(list[1..-1], list[0])
} else {
getMax(list[1..-1], max)
}
@tomgullo
tomgullo / create_threads.groovy
Last active December 11, 2015 05:58
simple test using threads
import java.util.concurrent.CountDownLatch
class MyRunnable implements Runnable {
def myParam, latch
public MyRunnable(String myParam, CountDownLatch latch){
this.myParam = myParam;
this.latch = latch
}
public void run(){
try {
/*
write out data to excel spreadsheet
*/
static def writeExcel(ouputstream, headers, rows, cell_sizes) {
def workbook = Workbook.createWorkbook(outputstream)
WriteableSheet sheet = workbook.createSheet("R", 0)
for (e in cell_sizes) {
sheet.setColumnView(Integer.pareseInt(e.key), Integer.parseInt(e.value) )
}