Skip to content

Instantly share code, notes, and snippets.

@pcreux
pcreux / README.md
Last active October 10, 2020 18:44
Failsafe: degrade user experience and notify when something goes wrong.

Failsafe

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

Usage

Wrap non mission critical code:

@pcreux
pcreux / size.rb
Last active May 11, 2020 21:27
Sizes - Use ruby's comparable to compare clothe's sizes (XS, S, M, L, XL, etc)
class Size
include Comparable
def initialize(str)
unless ALL_STRS.include? str
raise ArgumentError, "#{str} is not a valid size"
end
@str = str
end
@pcreux
pcreux / 99bottles.rb
Last active January 16, 2020 21:12
99bottles in 15 minutes. Feeling a bit dizzy now... 🍻 `git clone --depth=1 --branch=exercise https://github.com/sandimetz/99bottles.git`
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")
@pcreux
pcreux / circleci-trace
Created November 21, 2019 19:42
Generate a trace of your circleci workflows
#!/usr/local/env ruby
#
# Generate html traces from CircleCI workflows
#
require 'json'
require 'http'
OWNER = 'githubowner'
REPO = 'githubrepo'
@pcreux
pcreux / sendgrid via curl
Created September 27, 2013 21:08
Send email via the command line with sendgrid. Get notified when a long running script is done on a remote server.
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"
@pcreux
pcreux / complete.sh
Created February 18, 2013 10:20
Github Commit Status API with Bamboo from Atlassian. Add those to your plan as Script.
# 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
@pcreux
pcreux / pipable.rb
Last active June 12, 2018 17:08
*nix has pipes, Elixir has pipes, Ruby deserves pipes.
# 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
#
@pcreux
pcreux / 000 Oh no conditionals!.png
Last active June 6, 2018 19:26
Turning imperative conditionals into declarative rules
000 Oh no conditionals!.png
@pcreux
pcreux / 000_robust_rails_apps.md
Last active May 14, 2018 04:38
Robust Rails Apps - VanRuby - March 29, 2017

Robust Rails Apps

Philippe Creux - @pcreux

#vanruby - March 29th, 2017

@pcreux
pcreux / Gemfile
Created April 19, 2018 16:53
Minimal setup to run a static site on Heroku.
# no ruby gems required