Skip to content

Instantly share code, notes, and snippets.

View ianAndrewClark's full-sized avatar

Ian Clark ianAndrewClark

View GitHub Profile
@ppearcy
ppearcy / gist:1279879
Created October 12, 2011 00:26
ES synonym failure on 0.17.8
# Here are the contents of the synonym file that is located here: analysis/synonym_test.txt
test1, a+b
test2, b+c
test3, d/c
work, business
# Create the index
curl -XPOST localhost:9200/es-syntest -d '{
"settings" : {
"number_of_shards" : 1,
@robcowie
robcowie / memoise.py
Created November 11, 2011 11:30
Python memoisation decorator
from functools import wraps
def memoise(wrapped):
cache = {}
@wraps(wrapped)
def wrapper(*args, **kwargs):
key = (args, tuple(sorted(kwargs.items())))
if key not in cache:
@drlongnecker
drlongnecker / FindTODO.ps1
Created December 27, 2011 16:52
Finding TODOs and Reporting in PowerShell
#full details now available: http://tiredblogger.wordpress.com/2011/12/28/finding-todos-and-reporting-in-powershell/
param(
#this is appalling; there has to be a better way to get the raw name of "this" directory.
[string]$DirectoryMask = (get-location),
[array]$Include =
@("*.spark","*.cs","*.js","*.coffee","*.rb"),
[array]$Exclude =
@("fubu-content","packages","build","release"),
[switch]$Html,
curl -XPUT 'http://localhost:9200/_template/template_logstash/' -d '
{
"template": "logstash-*",
"mappings": {
"_default_": {
"_source": { "compress": "true" },
"_all" : {"enabled" : false}
}
}
}'
curl -XPUT localhost:9200/test -d '
{
"settings" : {
"index": {
"analysis": {
"analyzer": {
"manualindexanalyzer": {
"type": "custom",
"tokenizer": "whitespace",
"filter": [
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) {
@nherment
nherment / backup.sh
Created February 29, 2012 10:42
Backup and restore an Elastic search index (shamelessly copied from http://tech.superhappykittymeow.com/?p=296)
#!/bin/bash
# herein we backup our indexes! this script should run at like 6pm or something, after logstash
# rotates to a new ES index and theres no new data coming in to the old one. we grab metadatas,
# compress the data files, create a restore script, and push it all up to S3.
TODAY=`date +"%Y.%m.%d"`
INDEXNAME="logstash-$TODAY" # this had better match the index name in ES
INDEXDIR="/usr/local/elasticsearch/data/logstash/nodes/0/indices/"
BACKUPCMD="/usr/local/backupTools/s3cmd --config=/usr/local/backupTools/s3cfg put"
BACKUPDIR="/mnt/es-backups/"
YEARMONTH=`date +"%Y-%m"`
@jprante
jprante / BulkWrite.java
Created May 2, 2012 18:21
Performing multithreaded asynchronous bulk writes to Elasticsearch
/*
* Licensed to Jörg Prante and xbib under one or more contributor
* license agreements. See the NOTICE.txt file distributed with this work
* for additional information regarding copyright ownership.
*
* Copyright (C) 2012 Jörg Prante and xbib
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation; either version 3 of the License, or
@louischatriot
louischatriot / gist:2601571
Created May 5, 2012 11:02
d3 introduction: animated graph in 11 LOC
<!DOCTYPE html>
<html manifest="cache.manifest">
<head> <title>d3 example</title> </head>
<body>
<div id='d3TutoGraphContainer'></div>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="http://d3js.org/d3.v2.min.js"></script>
@zxcvbnm4709
zxcvbnm4709 / gist:2656197
Created May 10, 2012 22:06
include jQuery in Chrome Console
var script = document.createElement("script");
script.setAttribute("src", "http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js");
script.addEventListener('load', function() {
var script = document.createElement("script");
document.body.appendChild(script);
}, false);
document.body.appendChild(script);