Skip to content

Instantly share code, notes, and snippets.

View jeremy's full-sized avatar

Jeremy Daer jeremy

View GitHub Profile
@jeremy
jeremy / UAX29URLEmailTokenizerImpl31.getNextToken
Created June 13, 2012 19:26
elasticsearch index thread hung on UAX29URLEmailTokenizer
3572 zzForAction: {
3573 while (true) {
3574
3575 if (zzCurrentPosL < zzEndReadL)
3576 zzInput = zzBufferL[zzCurrentPosL++];
3577 else if (zzAtEOF) {
3578 zzInput = YYEOF;
3579 break zzForAction;
3580 }
3581 else {
@jeremy
jeremy / gist:1383337
Created November 21, 2011 17:39
Using Rails log for RestClient.log
require 'restclient'
# RestClient logs using << which isn't supported by the Rails logger,
# so wrap it up with a little proxy object.
RestClient.log =
Object.new.tap do |proxy|
def proxy.<<(message)
Rails.logger.info message
end
end
@jeremy
jeremy / gist:1371416
Created November 16, 2011 21:11
ElasticSearch caching response?
$ curl http://10.11.0.6:9200/migrations/_settings
{"migrations":{"settings":{"index.number_of_shards":"1","index.auto_expand_replicas":"1-all","index.number_of_replicas":"2"}}}
$ curl http://10.11.0.6:9200/migrations/_settings?pretty=true
{
"migrations" : {
"settings" : {
"index.number_of_shards" : "1",
"index.auto_expand_replicas" : "0-all",
"index.number_of_replicas" : "0"
@jeremy
jeremy / required_routing_on_unmapped_field_issue.sh
Created September 23, 2011 04:02
elasticsearch required _routing must have an explicit field mapping for non-string fields
#!/usr/bin/env bash
# https://github.com/elasticsearch/elasticsearch/issues/1357
set -o verbose
curl -s -XGET http://localhost:9200/ |grep -B 1 number
curl -XDELETE http://localhost:9200/foo
curl -XPUT http://localhost:9200/foo -d '{
"mappings": {
@jeremy
jeremy / schema.xml
Created April 2, 2011 00:53
Basecamp Solr schema
<?xml version="1.0" encoding="UTF-8" ?>
<schema name="basecamp" version="1.3">
<types>
<!-- indexed/stored verbatim -->
<fieldType name="string" class="solr.StrField" sortMissingLast="true" omitNorms="true" omitTermFreqAndPositions="true"/>
<!-- "true" or "false" -->
<fieldType name="boolean" class="solr.BoolField" sortMissingLast="true" omitNorms="true" omitTermFreqAndPositions="true"/>
<!-- binary data, base64 -->
# Dependencies: ruby, git, rubygems
sudo gem install bundler
git clone git://github.com/rails/rails.git
cd rails && gem bundle
ruby -rvendor/gems/environment railties/bin/rails ../new_app
cd ../new_app
# edit Gemfile to use:
@jeremy
jeremy / NewRelic custom dashboard
Created August 7, 2009 05:35
Track object allocations in NewRelic
<table width="100%">
<tr><td width="50%">
{% compare_with_last_week_chart metric:'Custom/Objects/Allocated' title:'Object Allocations' value:total_value %}
</td><td width="50%">
{% compare_with_last_week_chart metric:'Custom/Objects/Live' title:'Live Objects' value:average_value %}
</td></tr>
</table>
# Configure generators to use sequel, haml, and shoulda.
config.generators do |g|
g.orm :sequel
g.template_engine :haml
g.test_framework :shoulda, :fixtures => true
end
# Round expiry to encourage HTTP caching.
# 5-minute expiry at 6:03 would round up from 6:08 to 6:10.
module QuantizedExpiry
def url_for(name, options = {})
unless options[:expires]
t = (options.delete(:expires_in) || 5.minutes).to_i
options[:expires] = t * (2 + (Time.now.to_i / t))
end
super
end
# Including a module included in a superclass is ignored
>> module Foo; end
=> nil
>> class Numeric; include Foo; end
=> Numeric
>> Float.ancestors
=> [Float, Precision, Numeric, Foo, Comparable, Object, Kernel]
>> class Float; include Foo; end
=> Float
>> Float.ancestors