Skip to content

Instantly share code, notes, and snippets.

View barnybug's full-sized avatar
🏠
Working from home

Barnaby Gray barnybug

🏠
Working from home
View GitHub Profile
SERVER='http://127.0.0.1:9200/'
curl -XDELETE "$SERVER/test/"
curl -XPUT "$SERVER/test/"
curl -XPUT "$SERVER/test/a/_mapping" -d '{"a": {"properties": {"field1": {"type": "integer"}}}}'
curl -XPUT "$SERVER/test/b/1" -d '{"field1": 1}'
sleep 1
curl -XGET 'http://localhost:9200/test/a/_search?size=0' -d '{"facets":{"f":{"terms":{"field":"field1"}}},"query":{"match_all":{}}}'
{"ok":true,"_index":"test","_type":"b","_id":"1","_version":1}{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 4,
"failed" : 1,
"failures" : [ {
"index" : "test",
"shard" : 2,
curl -XPOST 'http://127.0.0.1:9200/test/a/1?pretty=true' -d '{"b": {"i": [null]}}'
curl -XPOST 'http://127.0.0.1:9200/_all/_flush?pretty=true'
curl -XGET 'http://127.0.0.1:9200/test/a/_search?q=*&fields=b&pretty=true'
@barnybug
barnybug / gist:2006593
Created March 9, 2012 13:52
IOException when limiting by fields and returning nested arrays.
curl -XPOST 'http://127.0.0.1:9200/test/a/1?pretty=true' -d '{"b": [{"i": [1]}]}'
curl -XPOST 'http://127.0.0.1:9200/_all/_flush?pretty=true'
curl -XGET 'http://127.0.0.1:9200/test/a/_search?q=*&fields=b.i&pretty=true'
@barnybug
barnybug / ec2names.py
Created September 9, 2012 19:17
Script to name all ec2 instances after the node name allocated to the elasticsearch running on that instance.
#!/usr/bin/python
# Script to name all ec2 instances after the node name allocated to the
# elasticsearch running on that instance. This makes it easy to track back
# to the physical system from visualization tools like bigdesk and head.
#
# Run directly on any elasticsearch node or port forward 9200 to a node in the
# cluster. Simple run without arguments:
# ./ec2names.py
#
@barnybug
barnybug / jg
Last active December 12, 2015 01:18
jg - json document generator
Moved to: http://github.com/barnybug/jg
#!/usr/bin/env python
# Script to run dynamic dns for docker containers.
# DNS is served by dnsmasq running on the docker0 gateway ip, and dynamically
# updated at containers come and go.
#
# To use from docker, just provide the --dns option:
# docker run --dns <gateway> ...
# The gateway ip you need will be printed when this script is run.
// Bug demonstrating Release crash in swift code (XCode 6.2 / swift 1.1, Release builds only)
import UIKit
import XCTest
func dictSetValue(value: AnyObject, forKey key: String, inout #dictionary: [String : AnyObject]) {
dictSetValue(value, forKeyPathComponents: key.componentsSeparatedByString("."), dictionary: &dictionary)
}
func dictSetValue(value: AnyObject, forKeyPathComponents components: [String], inout #dictionary: [String : AnyObject]) {
% Prolog solution to:
% http://www.theguardian.com/science/alexs-adventures-in-numberland/2015/may/04/einsteins-election-riddle-are-you-in-the-two-per-cent-that-can-solve-it
left(X, Y, [X | [Y | _]]).
left(X, Y, [_ | List]) :- left(X, Y, List).
neighbour(X, Y, List) :- left(X, Y, List); left(Y, X, List).
% house(Person, Pattern, Pet, Drink, Transport)
solution(Answer) :- Z = [_, _, _, _, _],
% 1. Nicola lives in the tartan house.
def get_code(tree, feature_names, class_names):
left = tree.tree_.children_left
right = tree.tree_.children_right
threshold = tree.tree_.threshold
features = [feature_names[i] for i in tree.tree_.feature]
value = tree.tree_.value
def recurse(left, right, threshold, features, node, indent):
if threshold[node] != -2:
print "%sif %s <= %s:" % (indent, features[node], threshold[node])