Skip to content

Instantly share code, notes, and snippets.

View everm1nd's full-sized avatar

Nikita Simakov everm1nd

  • Berlin
View GitHub Profile
@everm1nd
everm1nd / uninstall.sh
Created March 12, 2012 14:10
uninstall all gems script
gem list | cut -d" " -f1 | xargs gem uninstall -aIx
@everm1nd
everm1nd / gist:2284750
Created April 2, 2012 16:22
Ruby: method_missing metaprogramming
# Let say we're defining method for #*_with_id here
def method_missing(name, *args)
super if name !~ /_with_id$/
define_method "#{name}_with_id" do
instance_variable_get(:id) + "-" + instance_variable_get(:name)
end
end
@everm1nd
everm1nd / gist:2321413
Created April 6, 2012 17:10
Ruby: Sort one array by another using +/-
order = [1,2,3,4,5]
params = [5,2,1,7,9]
sort = order - (order - params) + (params - order) # => [1,2,5,7,9]
@everm1nd
everm1nd / gist:2399113
Created April 16, 2012 14:20
Ruby: Working with options
options = { :allow_destroy => false, :update_only => false }
options.update(attr_names.extract_options!)
options.assert_valid_keys(:allow_destroy, :reject_if, :limit, :update_only)
options[:reject_if] = REJECT_ALL_BLANK_PROC if options[:reject_if] == :all_blank
@everm1nd
everm1nd / gist:3046624
Created July 4, 2012 10:29
MySQL: Create UTF-8 database
CREATE DATABASE `database` CHARACTER SET utf8 COLLATE utf8_general_ci;
@everm1nd
everm1nd / solr_cap.rb
Created August 8, 2012 14:45 — forked from doitian/solr_cap.rb
Capistrano: sunspot solr in capistrano
namespace :deploy do
task :setup_solr_data_dir do
run "mkdir -p #{shared_path}/solr/data"
end
end
namespace :solr do
desc "start solr"
task :start, :roles => :app, :except => { :no_release => true } do
run "cd #{current_path} && RAILS_ENV=#{rails_env} bundle exec sunspot-solr start --port=8983 --data-directory=#{shared_path}/solr/data --pid-dir=#{shared_path}/pids"
@everm1nd
everm1nd / gist:3296079
Created August 8, 2012 15:43
Capistrano: Solr
task :before_update_code do
#stop solr:
run "cd #{current_path} && rake sunspot:solr:stop RAILS_ENV=#{rails_env}"
end
after "deploy:update_crontab", "deploy:solr:symlink"
namespace :solr do
desc <<-DESC
Symlink in-progress deployment to a shared Solr index.
@everm1nd
everm1nd / dsl.rb
Created October 16, 2012 16:59
Simple DSL at Ruby
class DSL
def initialize &block
@params = {}
instance_eval &block
end
def param key, value
@params[key] = value
end
@everm1nd
everm1nd / clear_bucket.rb
Created October 17, 2012 11:41
Clear S3 Bucket
require 'aws'
require 'trollop'
opts = Trollop::options do
opt :config, "amazon.yml config file path", :type => :string, :required => true
opt :bucket, "bucket name", :type => :string, :required => true
end
AWS.config(YAML.load(File.read(opts[:config])))
def parse data
trips = get_trips data
end
def get_trips data
trips = get_trips_data data
trips.each do |trip|
flight_sets = get_flight_sets trip
end
end