This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'sequel' | |
require 'logger' | |
require 'awesome_print' | |
DB = Sequel.sqlite | |
DB.create_table :people do | |
primary_key :id | |
String :name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 0. Create a bunch of id => vector results for every definition | |
WITH unnested_keys_as_vector AS ( | |
SELECT id as term_id, to_tsvector((each(definitions)).value) as term | |
FROM glossary_terms | |
WHERE glossary_id = 10 | |
) | |
-- 2. Select the rank so we can sort by it (default order is order of terms in table) | |
SELECT *, ts_rank_cd(term, to_tsquery('I | like | bananas')) as rank | |
FROM glossary_terms | |
-- 1. Join the result of the tsvector search on the terms |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/initializers/instrumentation.rb | |
# Subscribe to grape request and log with Rails.logger | |
ActiveSupport::Notifications.subscribe('grape.request') do |name, starts, ends, notification_id, payload| | |
Rails.logger.info '[API] %s %s (%.3f ms) -> %s %s%s' % [ | |
payload[:request_method], | |
payload[:request_path], | |
(ends-starts)*1000, | |
(payload[:response_status] || "error"), | |
payload[:x_organization] ? "| X-Org: #{payload[:x_organization]}" : "", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set :path_to_repo, "/path_to_repo/" | |
set :running_app_user, "appusername" | |
namespace :webscale do | |
desc "Cache a signed out version of the path. Usage: cap webscale:signed_out_cache_page -s path_to_cache=/films/on_netflix" | |
task :signed_out_cache, roles: :app do | |
cache_base_path = "#{path_to_repo}/public/signed_out" | |
cached_destination_path = "#{cache_base_path}#{path_to_cache}.html" | |
working_path = "#{cached_destination_path}.tmp" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This is an example how to perform multi-select faceting in ElasticSearch. | |
Selecting multiple values from the same facet will result in an OR filter between each of the values: | |
(facet1.value1 OR facet1.value2) | |
Faceting on more than one facet will result in an AND filter between each facet: | |
(facet1.value1 OR facet1.value2) AND (facet2.value1) | |
I have chosen to update the counts for each facet the selected value DOES NOT belong to since we are performing an AND between each facet. I have included an example that shows how to keep the counts if you don't want to do this (filter0.sh). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RSpec.configure do |config| | |
config.before(:suite) do | |
ActiveRecord::Base.establish_connection database['one'] | |
DatabaseCleaner.strategy = :deletion | |
ActiveRecord::Base.establish_connection config.database['two'] | |
DatabaseCleaner.strategy = :deletion | |
end | |
config.before(:each) do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bash -c ' | |
if [ ! -f /usr/local/bin/chef-client ]; then | |
apt-get update | |
apt-get -y upgrade | |
apt-get install -y build-essential wget zlib1g-dev libssl-dev libffi-dev | |
cd /usr/src | |
wget ftp://ftp.ruby-lang.org//pub/ruby/1.9/ruby-1.9.2-p180.tar.bz2 | |
tar xjf ruby-1.9.2-p180.tar.bz2 | |
cd ruby-1.9.2-p180 | |
./configure |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=begin | |
Need to install gems heroku, newrelic_rpm | |
$ gem install heroku newrelic_rpm | |
Set your apps setting | |
app_name : heroku's app_name of auto scaling | |
license_key : NewRelic api key. You can get heroku's NewRelic admin console. "App setting" and "Agent configuration" | |
execute with cron every minutes | |
$ ruby ./adjust_dynos_with_newrelic.rb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Enable upload_progress module for easy cross browser progress bar support | |
# using only javascript client side | |
upload_progress foobar_uploads 1m; | |
server { | |
# We only need one server block to deal with HTTP and HTTPS | |
# avoids duplication | |
listen 80; | |
listen 443 default ssl; | |