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 Bottles | |
def verse(current) | |
<<-VERSE | |
#{bottles(current).capitalize} of beer on the wall, #{bottles(current)} of beer. | |
#{take_one_down(current)}, #{bottles((current - 1) % 100)} of beer on the wall. | |
VERSE | |
end | |
def verses(start, finish) | |
(finish..start).to_a.reverse.map { |number| verse(number) }.join("\n") |
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 'json' | |
# 1. Generate new access key | |
new_access_key_json = `aws iam create-access-key` | |
new_access_key_attributes = JSON.parse(new_access_key_json).fetch("AccessKey") | |
new_access_key_id = new_access_key_attributes.fetch("AccessKeyId") |
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
CREATE INDEX "index_patrons_on_amount_raised_in_cents" ON "patrons" ("amount_raised_in_cents" DESC) |
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
require 'time' | |
require 'virtus' | |
require 'benchmark/ips' | |
PARAMS = { | |
id: "123", | |
title: "Hello", | |
content: "Lorem ipsum" * 100, | |
created_at: Time.now.to_s, | |
updated_at: Time.now.to_s |
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 | |
DESC = " | |
Generate spec file | |
Example: mkspec app/services/user/create.rb will generate spec/services/user/create_spec.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
#!/usr/bin/env ruby | |
# | |
# Generate a graph of dependencies for your stylesheets. | |
# | |
# Requires graphviz | |
# | |
# Run `ruby dependencies.rb | fdp -Tpng > out.png; open out.png` | |
PATH = "app/assets/stylesheets/" |
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
--- | |
layout: post | |
title: "This week in Rails: 4.2.0 Final, autoload explained, deep_munge and more!" | |
categories: news | |
author: chancancode | |
published: true | |
date: 2015-01-09 14:04:54 -0800 | |
--- | |
Welcome to _This week in Rails_, your weekly inside scoop of interesting commits, pull requests and more from [Rails](https://github.com/rails/rails). |
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 | |
# | |
# Rename rails services, models etc as well as their test or spec files! | |
# | |
# Example: railsmv app/services/create_user.rb app/services/user/create.rb | |
# | |
require 'optparse' | |
dry_run = false |
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 Size | |
include Comparable | |
def initialize(str) | |
unless ALL_STRS.include? str | |
raise ArgumentError, "#{str} is not a valid size" | |
end | |
@str = str | |
end |
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
# Elixir has pipes `|>`. Let's try to implement those in Ruby. | |
# | |
# I want to write this: | |
# | |
# email.body | RemoveSignature | HighlightMentions | :html_safe | |
# | |
# instead of: | |
# | |
# HighlightMentions.call(RemoveSignature.call(email.body)).html_safe | |
# |