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
columns_that_make_record_distinct = [:some_id, :another_name] | |
distinct_ids = Model.select("MIN(id) as id").group(columns_that_make_record_distinct).map(&:id) | |
duplicate_records = Model.where.not(id: distinct_ids) |
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
// Useful for when you've just installed a new version of Ruby and need to install your common/favourite gems | |
// | |
gem install bundler pry awesome_print foreman rails ferver london-bike-hire-cli benchmark-ips rubocop |
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
# a method that is a simple hash acting as a cache to remote service, db call, etc | |
# | |
def a_cache | |
@a_cache ||= Hash.new do |cache, reference| | |
cache[reference] = Service.fetch(reference) | |
end | |
end | |
# usage | |
# a_cache[reference] |
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
say_with_time "Doing an update" do | |
execute %q{UPDATE somethings SET a_col = 'foo' WHERE other_col IN ('bar', 'foobar')} | |
end | |
# or | |
execute <<-SQL | |
CREATE UNIQUE INDEX foobars_name_lower_idx ON foobars (LOWER(name)); | |
SQL |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
class Money | |
STANDARD_VAT_RATE = 0.2.freeze | |
attr_reader :amount | |
def self.in_pence(amount_in_pence) | |
new(amount_in_pence) | |
end | |
def initialize(amount) |
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
class UnionFind | |
attr_accessor :nodes, :sizes | |
def initialize(num) | |
self.nodes = [] | |
self.sizes = [] | |
num.times do |n| | |
self.nodes[n] = n |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
boot2docker start | |
export etc | |
docker images | |
docker build -t robmurray/name:tag . # build current | |
docker run -P --name foo robmurray/name:tag # test | |
docker kill # above | |
docker push robmurray/name:tag | |
# switch to docker-machine | |
eval "$(docker-machine env {machine})" | |
docker stop current # stop current container # downtime :( |
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
# app/models/blog_post.rb | |
class BlogPost < Post | |
has_many :comments | |
end |