When something goes wrong I want to degrade the user experience (instead of returning a 500 - Server Error) And I want to be notified about the failure
Wrap non mission critical code:
class Size | |
include Comparable | |
def initialize(str) | |
unless ALL_STRS.include? str | |
raise ArgumentError, "#{str} is not a valid size" | |
end | |
@str = str | |
end |
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") |
#!/usr/local/env ruby | |
# | |
# Generate html traces from CircleCI workflows | |
# | |
require 'json' | |
require 'http' | |
OWNER = 'githubowner' | |
REPO = 'githubrepo' |
curl "https://sendgrid.com/api/mail.send.json?api_user=YOUR_USER&api_key=YOUR_API_KEY&to=recipient@example.com&from=sender@example.com&subject=Import+done&text=Done" |
# specs and cukes results are stored in JUnit format under test-reports | |
if (grep 'failures="[^0]"' test-reports/* || grep 'errors="[^0]"' test-reports/*); then | |
curl -H "Authorization: token MY_TOKEN" --request POST --data '{"state": "failure", "description": "Failed!", "target_url": "${bamboo.buildResultsUrl}"}' https://api.github.com/repos/USER/REPO/statuses/${bamboo.repository.revision.number} > /dev/null | |
else | |
curl -H "Authorization: token MY_TOKEN" --request POST --data '{"state": "success", "description": "Success!", "target_url": "${bamboo.buildResultsUrl}"}' https://api.github.com/repos/USER/REPO/statuses/${bamboo.repository.revision.number} > /dev/null | |
fi |
# 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 | |
# |
# no ruby gems required |