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
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])
@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'
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'
{"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,
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":{}}}'
% 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.
// 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]) {