Skip to content

Instantly share code, notes, and snippets.

/*
* HumanTime.java
*
* Created on 06.10.2008
*
* Copyright (c) 2008 Johann Burkard (<mailto:jb@eaio.com>) <http://eaio.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
#!/usr/bin/env ruby
require 'fileutils'
require 'rexml/document'
class IntellijIml
def initialize(iml_file)
@iml_file = iml_file
@rhyskeepence
rhyskeepence / gist:713483
Created November 24, 2010 10:57
Print a message if connecting is taking too long
private void attachListener() {
ScheduledFuture<?> activemqWarning = scheduleWarningIfJmsConnectionTakesTooLong();
try {
// perform some operation that may hang if ActiveMq is not running
} finally {
activemqWarning.cancel(true);
}
}
private ScheduledFuture<?> scheduleWarningIfJmsConnectionTakesTooLong() {
@rhyskeepence
rhyskeepence / Regex.java
Created March 28, 2012 14:03
Simplify the insanity of Regex in Java
import com.googlecode.totallylazy.Callable1;
import com.googlecode.totallylazy.Option;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static com.googlecode.totallylazy.Option.none;
import static com.googlecode.totallylazy.Option.some;
import static com.googlecode.totallylazy.numbers.Numbers.range;
import com.googlecode.totallylazy.Option;
import com.googlecode.totallylazy.Sequences;
import org.junit.Test;
import static com.googlecode.totallylazy.Sequences.sequence;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
public class RegexTest {
@rhyskeepence
rhyskeepence / gist:3284565
Created August 7, 2012 11:04
Scalaz inspired Validation in Java / ewwww
import com.googlecode.totallylazy.Callable1;
import com.googlecode.totallylazy.Callers;
import static sky.sns.bumblebee.io.Regex.regex;
public abstract class Validation<E, A> {
public abstract <X> X fold(final Callable1<E, X> fail, Callable1<A, X> success);
public static <E, A> Validation<E, A> fail(final E e) {
return new Validation<E, A>() {
@rhyskeepence
rhyskeepence / gist:3621591
Created September 4, 2012 14:21
group by day with aggregate function
db.prod.aggregate(
{ $match : { _id: { $gte: someTimestamp }}},
{ $group :
{
_id : { $subtract: ["$_id", { $mod: ["$_id", 86400000] } ] } ,
averagePerDay : { $avg : "$threadCount" }
}
}
)
@rhyskeepence
rhyskeepence / gist:3635341
Created September 5, 2012 11:32
group by day via map reduce
var m = function() {
emit(this._id - (this._id % 86400000), { aggregate:0, count:1, sum: this['threadCount'] } );
};
var r = function (name, values) {
var result = { aggregate:0, count:0, sum:0 };
values.forEach(function(f) {
result.sum += f.sum;
result.count += f.count;
});
@rhyskeepence
rhyskeepence / gist:3635507
Created September 5, 2012 11:48
mongo db aggregation output
command: { aggregate: "activemq_berylcoral", pipeline: [ { $match: { _id: { $gte: 1346281200000 } } }, { $group: { _id: { $divide: [ "$_id", 86400000 ] }, aggregation: { $avg: "$jvmThreadCount" } } } ] } ntoreturn:1 keyUpdates:0 numYields: 1 locks(micros) r:2162903 reslen:246035 1379ms
command: { mapreduce: "activemq_berylcoral", map: "function() { emit(this._id - (this._id % 86400000), { aggregate:0, count:1, sum: this['jvmThreadCount'] } );}", reduce: "
function (name, values) {
var result = { aggregate:0, count:0, sum:0 };
values.forEach(function(f) {
result.sum += f.sum;
...", verbose: false, out: { inline: true }, query: { _id: { $gte: 1346281200000 } }, finalize: "
@rhyskeepence
rhyskeepence / gist:3653338
Created September 6, 2012 08:59
profile output
> db.runCommand({aggregate:"prod", pipeline:pipeline, explain:true});
{
"serverPipeline" : [
{
"query" : {
"_id" : {
"$gte" : 1346281200000
}
},
"projection" : {