Skip to content

Instantly share code, notes, and snippets.

View tcocca's full-sized avatar

Tom Cocca tcocca

  • Boston Logic Technology Partners, Inc.
  • Boston, MA
View GitHub Profile
@nherment
nherment / backup.sh
Created February 29, 2012 10:42
Backup and restore an Elastic search index (shamelessly copied from http://tech.superhappykittymeow.com/?p=296)
#!/bin/bash
# herein we backup our indexes! this script should run at like 6pm or something, after logstash
# rotates to a new ES index and theres no new data coming in to the old one. we grab metadatas,
# compress the data files, create a restore script, and push it all up to S3.
TODAY=`date +"%Y.%m.%d"`
INDEXNAME="logstash-$TODAY" # this had better match the index name in ES
INDEXDIR="/usr/local/elasticsearch/data/logstash/nodes/0/indices/"
BACKUPCMD="/usr/local/backupTools/s3cmd --config=/usr/local/backupTools/s3cfg put"
BACKUPDIR="/mnt/es-backups/"
YEARMONTH=`date +"%Y-%m"`
$:.unshift(File.expand_path('../../lib', __FILE__))
require 'babysitter/puzzle'
@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
@bcardarella
bcardarella / GivenWhenThen.rb
Created September 14, 2011 01:00
Given When Then for Capybara DSL
# Throw this into your spec/support directory
# Usage:
#
# feature 'Dashboard' do
# scenario 'all' do
# Given 'I am an authenticated user' do
# authenticate_user
# end
# And 'there are assignments' do
# create(:assignment)
@lucasfais
lucasfais / gist:1207002
Created September 9, 2011 18:46
Sublime Text 2 - Useful Shortcuts

Sublime Text 2 – Useful Shortcuts (Mac OS X)

General

⌘T go to file
⌘⌃P go to project
⌘R go to methods
⌃G go to line
⌘KB toggle side bar
⌘⇧P command prompt
@karmi
karmi / tire_http_clients_benchmark.rb
Created September 8, 2011 18:15
Benchmark Tire gem with RestClient and Curb HTTP Clients
#
# A basic, synthetic benchmark of the impact HTTP client has
# on the speed of talking to ElasticSearch in the Tire gem.
#
# In general, Curb seems to be more then two times faster the RestClient, in some cases it's three
# to five times faster. I wonder if keep-alive has anything to do with it, but it probably does.
#
# Run me with:
# $ git clone git://github.com/karmi/tire.git
# $ cd tire
@karussell
karussell / backup.sh
Created July 10, 2011 20:05
Backup ElasticSearch with rsync
# TO_FOLDER=/something
# FROM=/your-es-installation
DATE=`date +%Y-%m-%d_%H-%M`
TO=$TO_FOLDER/$DATE/
echo "rsync from $FROM to $TO"
# the first times rsync can take a bit long - do not disable flusing
rsync -a $FROM $TO
# now disable flushing and do one manual flushing
@karmi
karmi / geo_distance_filter_in_tire.rb
Created June 28, 2011 14:13
Geo Distance Filter Support in Tire/ElasticSearch
require 'tire'
require 'active_support/core_ext/numeric'
require 'active_support/core_ext/time/zones'
# Tire.configure { logger STDERR, level: 'debug' }
class Time; DATE_FORMATS.update lucene: "%Y-%m-%dT%H:%M"; end
Tire.index 'venues' do
@Aryk
Aryk / gist:1024359
Created June 14, 2011 05:05
Nested has_many :through support
module NestedHasManyThrough
module Reflection # :nodoc:
def self.included(base)
base.send :alias_method_chain, :check_validity!, :nested_has_many_through
end
def check_validity_with_nested_has_many_through!
check_validity_without_nested_has_many_through!
rescue ActiveRecord::HasManyThroughSourceAssociationMacroError => e
# now we permit has many through to a :though source
@dhh
dhh / gist:1014971
Created June 8, 2011 18:09
Use concerns to keep your models manageable
# autoload concerns
module YourApp
class Application < Rails::Application
config.autoload_paths += %W(
#{config.root}/app/controllers/concerns
#{config.root}/app/models/concerns
)
end
end