Skip to content

Instantly share code, notes, and snippets.

@tomgullo
tomgullo / pivot_solr.groovy
Created September 25, 2013 17:44
pivot_solr.groovy
.setParam('facet.pivot', 'one,two')
org.apache.solr.common.util.NamedList pivots = resp?.response?.facet_counts?.facet_pivot
def pivot = pivots.get('one,two')
def m = ['name':'root']
m['children'] = []
{
def inner_l = []
for (e2 in e.pivot) {
inner_l << ['name':"${e2.value}", 'size':e2.count]
@tomgullo
tomgullo / convert_ipv6.groovy
Last active December 23, 2015 21:39
convert_ipv6
import java.net.InetAddress
InetAddress ia = InetAddress.getByName("2001:0:4137:9e76:34b7:2e31:3f57:fd9a")
def bi = new BigInteger(ia.getAddress())
println bi
println InetAddress.getByAddress(bi.toByteArray())
@tomgullo
tomgullo / google_guava_cache.groovy
Created September 20, 2013 14:16
Google Guava cache example
import com.google.common.cache.*
import java.util.concurrent.TimeUnit
LoadingCache<String, String> mycache = CacheBuilder.newBuilder()
.maximumSize(1000)
.recordStats()
.expireAfterWrite(5, TimeUnit.SECONDS)
.build(
new CacheLoader<String, String>() {
public String load(String key) throws Exception {
@tomgullo
tomgullo / merge_lists_of_lists.js
Last active December 22, 2015 11:09
merge_lists_of_lists
function process(result, val, temp_val) {
var inner_val = isNaN(val) ? val : [val, val];
if (temp_val.length == 0) { //no temp
temp_val = inner_val;
} else if ( (inner_val[1] -1) > temp_val[1] ) { //flush temp
if (temp_val[0] == temp_val[1]) {
result.push(temp_val[0]);
} else {
result.push(temp_val[0] + '-' + temp_val[1]);
@tomgullo
tomgullo / merge_sort.js
Created September 4, 2013 17:31
merge sort js
l = console.log
l("\n\nstart:")
function merge(left, right){
l("merge: l: " + left + ", r: " + right);
var result = [],
il = 0,
ir = 0;
while (il < left.length && ir < right.length){
@tomgullo
tomgullo / is_tree_balanced.js
Last active December 21, 2015 22:49
is_balanced
log = console.log
function node(name, parent, child) {
var new_node = { name:name, parent:parent }
if (!!child) {
new_node.parent[child] = new_node;
}
return new_node
@tomgullo
tomgullo / SocketServer.groovy
Created August 27, 2013 16:21
Java sockets test
/*
//client
import java.io.*
import java.net.*
def sentence = 'i am testing this'
def clientSocket = new Socket("localhost", 6789)
try {
(new DataOutputStream(
@tomgullo
tomgullo / drop_dos.sh
Created August 21, 2013 11:06
drop_dos.sh
-A INPUT -p tcp -m tcp --dport 80 -m state --state NEW -m recent --set --name DEFAULT --rsource
-A INPUT -p tcp -m tcp --dport 80 -m state --state NEW -m recent --update --seconds 5 --hitcount 20 --name DEFAULT --rsource -j DROP
@tomgullo
tomgullo / java_sync_thread_test.java
Created August 16, 2013 17:52
java synchronization threads test
class Counter {
int val
public Counter() { val = 0; }
public /* synchronized */ void increment() {
val++
}
}
def c = new Counter()
@tomgullo
tomgullo / async_js_example.js
Created August 16, 2013 16:31
async_js_example
$(document).ready(function() {
async.waterfall([
function(next){
setTimeout(function() {
console.log('in this tImeout');
next(null, 'one', 'two');
},
2000);