Skip to content

Instantly share code, notes, and snippets.

@ejain
ejain / gist:9522320
Created March 13, 2014 05:28
Block all IPs that requested a specific file, temporarily.
sudo grep xmlrpc /var/log/apache2/access.log \
| cut -d' ' -f1 | sort | uniq \
| xargs -I{} sudo iptables -A INPUT -s {} -j DROP
@ejain
ejain / build.g
Created November 15, 2013 06:03
Converts a directory of GPX files into a single KML file for import into Google Fusion Tables; includes some metadata based on the file name.
import groovy.xml.MarkupBuilder
new MarkupBuilder().kml(xmlns : 'http://www.opengis.net/kml/2.2') {
new File(args?.size() ? args[0] : '.').eachFileMatch(~/.*\.gpx/) { file ->
new XmlParser().parse(file).trk.each { trk ->
trk.trkseg.each { trkseg ->
def geo = ""
trkseg.trkpt.each { trkpt ->
geo += "${trkpt.'@lon'},${trkpt.'@lat'}\n"
}
@ejain
ejain / gist:5507571
Created May 3, 2013 06:45
Example request and (incorrect) response when using a script terms facet in elasticsearch 0.90.0 (+ lang-javascript 1.3.0).
{
"query" : {
"match_all" : { }
},
"facets" : {
"lt322cf7ts" : {
"terms" : {
"size" : 31,
"script" : "t=doc['timestamp'].date;t.addMillis(-28800000);v=t.getHourOfDay();v",
"lang" : "js"
@ejain
ejain / gist:5507570
Created May 3, 2013 06:43
Example request and (correct) response when using a script terms facet in elasticsearch 0.20.6 (+ lang-javascript 1.2.0).
{
"query" : {
"match_all" : { }
},
"facets" : {
"lt322cf7ts" : {
"terms" : {
"size" : 31,
"script" : "t=doc['timestamp'].date;t.addMillis(-28800000);v=t.getHourOfDay();v",
"lang" : "js"
@ejain
ejain / DateHistogramFacetTest.java
Created March 31, 2012 17:40
Unit test for using elasticsearch's DateHistogramFacet with time zones.
package search;
import java.util.Map;
import junit.framework.Assert;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.common.settings.ImmutableSettings;
import java.util.concurrent.TimeUnit;
import junit.framework.Assert;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
<!doctype html>
<html xmlns:ng="http://angularjs.org" ng:app>
<head>
<script src="http://docs-next.angularjs.org/angular-0.10.6.min.js"></script>
<script>
function MainCtrl() {
self = this;
this.name = 'Main';
this.filter = [ ]
this.result = { };
class GeoClusterer {
private final double maxDistance;
private final List<GeoCluster> clusters = Lists.newArrayList();
public GeoClusterer(double maxDistance, DistanceUnit unit) {
this.maxDistance = unit.convert(maxDistance, unit, DistanceUnit.KILOMETERS);
}
public GeoCluster add(GeoPoint point) {