Skip to content

Instantly share code, notes, and snippets.

View 8823-demo.sh
#!/bin/bash
pkill -f 'elasticsearch.*cluster.name=8823'
rm -rf data/8823
bin/elasticsearch -Des.node.master=true -Des.cluster.name=8823 -Des.node.name=master 2>&1 >/dev/null &
sleep 1
bin/elasticsearch -Des.node.master=false -Des.cluster.name=8823 -Des.node.name=data1 2>&1 >/dev/null &
sleep 1
@grantr
grantr / elasticsearch_query_parser.rb
Created Feb 19, 2015
Elasticsearch query parser experiments
View elasticsearch_query_parser.rb
module Elastomer
module Query
class ElasticsearchQueryParser < LuceneQueryParser
rule(:unbounded_range) { gte | lte | gt | lt }
#TODO range groups e.g. age:(>=10 AND < 20) age:(+>=10 +<20)
#TODO eliminate duplication
rule(:field) { word.as(:field) >> str(':') >> (((group | regexp | inclusive_range.as(:inclusive_range) | exclusive_range.as(:exclusive_range)) >> boost.maybe) | ((phrase | term) >> (distance | boost).maybe)) }
end
View chef_bootstrap.sh
#!/bin/bash
# chef install
sudo apt-get -q -y install ruby ruby1.8-dev libopenssl-ruby1.8 rdoc ri irb build-essential wget >> /tmp/chef_bootstrap.log
cd /tmp
wget http://rubyforge.org/frs/download.php/55066/rubygems-1.3.2.tgz
tar zxvf rubygems-1.3.2.tgz >> /tmp/chef_bootstrap.log
cd rubygems-1.3.2
sudo ruby setup.rb --no-ri --no-rdoc >> /tmp/chef_bootstrap.log
View retry_with.rb
# Runs a block multiple times, each time with a different alternative
# Intended for connection failover
# Inspired by http://github.com/carlo/retryable
module RetryWith
def retry_with(alternatives, options={}, &block)
opts = {:tries => alternatives.size, :on => Exception}.merge(options)
return if opts[:tries] == 0
View gist:203544
template "/etc/motd" do
source "motd.erb"
end
motd.erb:
Runlist: <%= @node[:run_list] %>
View gist:366418
# try to attach any of the available volumes
aws_ebs_volume "#{datanode_dir}_#{node[:hadoop][:cluster_name]}" do
aws_access_key aws['aws_access_key_id']
aws_secret_access_key aws['aws_secret_access_key']
size node[:hadoop][:datanode][:ebs_vol_size]
device ebs_vol_dev
volume_ids available_volumes.collect { |v| v['volume_id'] }
action :attach_first
provider "aws_ebs_volume"
end
View gist:416080
require 'rubygems'
require 'avro'
count = ARGV[0] ? ARGV[0].to_i : 10000
puts "writing #{count} records"
SCHEMA = <<-JSON
{ "type": "record",
"name": "User",
"fields" : [
View gist:450487
# riddle/lib/riddle/client/response.rb
# Return the next integer value from the stream
def next_int
int = next_int_fast(@str, @marker)
@marker += 4
int
end
View gist:561421
Date: Sat, 28 Aug 2010 08:00:03 +0000 (UTC)
From: Cron Daemon <root@ip-10-204-107-97.ec2.internal>
To: root@ip-10-204-107-97.ec2.internal
Subject: Cron <root@ip-10-204-107-97> chef-solo -j /etc/chef/chef-solo-database-snapshot.json -c /etc/chef/chef-solo-database-snapshot.rb
[Sat, 28 Aug 2010 08:00:03 +0000] INFO: Setting the run_list to ["recipe[database::snapshot]"] from JSON
[Sat, 28 Aug 2010 08:00:03 +0000] INFO: Starting Chef Run (Version 0.9.8)
[Sat, 28 Aug 2010 08:00:03 +0000] INFO: Overriding duplicate definition pear_module, new found in /var/chef/cache/cookbooks/php/definitions/pear.rb
[Sat, 28 Aug 2010 08:00:03 +0000] INFO: Overriding duplicate definition pear_channel, new found in /var/chef/cache/cookbooks/php/definitions/pear_channel.rb
[Sat, 28 Aug 2010 08:00:03 +0000] INFO: mysql_database: flushing tables with read lock
View backup_databags.rb
#!/usr/bin/ruby
require 'rubygems'
require 'fileutils'
require 'chef'
pwd = File.dirname(__FILE__)
Chef::Config.from_file("/etc/chef/client.rb")
Chef::Config[:node_name] = ENV['OPSCODE_USER']