Skip to content

Instantly share code, notes, and snippets.

View jasongilman's full-sized avatar

Jason Gilman jasongilman

View GitHub Profile
@jasongilman
jasongilman / es_upgrade_issue
Created December 23, 2011 19:24
Reproducing elasticsearch upgrade problem
#!/bin/sh
# Run this on an empty elastic search of 0.17.6
# After running it shutdown elastic and start 0.18.6.
# Then execute this query
# curl -XPOST "http://localhost:9200/echo/dataset/_search" -d '{"query":{"filtered":{"query":{"match_all":{}},"filter":{"and":[{"and":[{"nested":{"path":"minimum_bounding_rectangles","query":{"constant_score":{"filter":{"and":[{"and":[{"range":{"north":{"from":-7.711,"to":90.0}}},{"range":{"south":{"from":-90.0,"to":38.273}}}]},{"or":[{"and":[{"or":[{"range":{"west":{"from":-180.0,"to":-3.164}}},{"range":{"east":{"from":-60.117,"to":180.0}}}]},{"term":{"antimeridian":true}}]},{"and":[{"range":{"west":{"from":-180.0,"to":-3.164}}},{"range":{"east":{"from":-60.117,"to":180.0}}}]}]}]}}}}}]},{"term":{"permitted_group_ids":"guest"}}]}}},"fields":["echo_collection_id"],"sort":["echo_collection_id"],"from":0,"size":2100}'
# Create echo index
curl -XPUT "http://localhost:9200/echo/" -d '
{ "settings" : { "index" : { "number_of_shards" : 3 } } }
@jasongilman
jasongilman / gist:1528898
Created December 28, 2011 17:59
Elastic Search Nested Query Problem
#!/bin/sh
# Create main index
curl -XPUT "http://localhost:9200/main/" -d '
{ "settings" : { "index" : { "number_of_shards" : 3 } } }
'
# Set alpha mapping
curl -XPUT "http://localhost:9200/main/alpha/_mapping" -d '
{"alpha": {
@jasongilman
jasongilman / Results
Created April 16, 2012 12:42
JRuby Concurrency Bug in ShellLauncher
JRUBY_VERSION: 1.6.7
JRUBY_OPTS: --1.9
Starting to modify env
Sleeping 0
Done sleeping 0
Sleeping 1
Exception in thread "RubyThread-1: jruby_bug.rb:4" java.lang.ArrayIndexOutOfBoundsException: 8495
at org.jruby.util.ShellLauncher.getCurrentEnv(ShellLauncher.java:231)
at org.jruby.util.ShellLauncher.popenShared(ShellLauncher.java:712)
at org.jruby.util.ShellLauncher.popenShared(ShellLauncher.java:689)
@jasongilman
jasongilman / jruby_long_line_parse.rb
Created August 28, 2012 13:13
Demonstrates a JRuby parsing bug with long lines
list = [{"string0"=>"value0"}, {"string1"=>"value1"}, {"string2"=>"value2"}, {"string3"=>"value3"}, {"string4"=>"value4"}, {"string5"=>"value5"}, {"string6"=>"value6"}, {"string7"=>"value7"}, {"string8"=>"value8"}, {"string9"=>"value9"}, {"string10"=>"value10"}, {"string11"=>"value11"}, {"string12"=>"value12"}, {"string13"=>"value13"}, {"string14"=>"value14"}, {"string15"=>"value15"}, {"string16"=>"value16"}, {"string17"=>"value17"}, {"string18"=>"value18"}, {"string19"=>"value19"}, {"string20"=>"value20"}, {"string21"=>"value21"}, {"string22"=>"value22"}, {"string23"=>"value23"}, {"string24"=>"value24"}, {"string25"=>"value25"}, {"string26"=>"value26"}, {"string27"=>"value27"}, {"string28"=>"value28"}, {"string29"=>"value29"}, {"string30"=>"value30"}, {"string31"=>"value31"}, {"string32"=>"value32"}, {"string33"=>"value33"}, {"string34"=>"value34"}, {"string35"=>"value35"}, {"string36"=>"value36"}, {"string37"=>"value37"}, {"string38"=>"value38"}, {"string39"=>"value39"}, {"string40"=>"value40"}, {"string41"
@jasongilman
jasongilman / clojure_example.clj
Created September 8, 2012 01:24
Clojure example
(def users [{:first-name "William" :last-name "Hudson"}
{:first-name "Ellen" :last-name "Ripley"}
{:first-name "Dwayne" :last-name "Hicks"}
{:first-name "Carter" :last-name "Burke"}])
(def user {:first-name "William" :last-name "Hudson"})
(get :first-name user)
(:first-name user)
@jasongilman
jasongilman / incanter_example.clj
Created September 9, 2012 14:52
incanter from jruby
(ns clojure_helpers.incanter_helper
(:use (incanter core stats charts)))
(defn view-histogram [values]
(view (histogram values)))
@jasongilman
jasongilman / multiplier.clj
Created September 9, 2012 23:56
high order function example
(defn multiplier [n]
(fn [x] (* x n)))
(def doubler (multiplier 2))
(doubler 7)
14
require 'uri'
# There's a bug in jboss or torquebox where encoded backslashes in URLs are incorrectly converted into forward slashes.
# This is rack middleware that detects when the original request included a backslash and will correct the env variable
# before forwarding it to the other middleware
# See https://issues.jboss.org/browse/TORQUE-955
class TorqueboxBackslashFixMiddleware
ENCODED_BACKSLASH = "%5C"
@jasongilman
jasongilman / transparent_functions.clj
Last active January 16, 2017 22:40
Transparent Functions
;; Transparent Functions
;; I was experimenting with transducers and wanted a way to understand how they worked. Transducer
;; code uses many nested functions in various locations with other nested functions defined as local
;; variables in scope. Typically after an anonymous Clojure function is defined you have no visibility
;; into the locals that were in scope when the function was defined, where the function came from,
;; or the code in the function. I defined a macro, tfn, that creates a transparent function. It's
;; a normal Clojure function with additional metadata including the function code and local
;; variable names and values.
# Note (clue): Exact queue size triggering the problem will depend on your available RAM
# Clean, compile, run C program:
rm a.out; cc -O3 -Wpedantic gc.c; time ./a.out 100000
# Clean, compile, run Java program:
rm *.class; javac GC.java; time java GC 100000
# Clean, compile, run Java program with verbose GC:
rm *.class; javac GC.java; time java -verbose:gc -XX:+PrintGCDetails GC 100000