Skip to content

Instantly share code, notes, and snippets.

@marzdrel
marzdrel / rails_helper.rb
Last active November 12, 2021 11:31
Make sure CI fails if any of the spec examples are tagged with :focus
# spec/rails_helper.rb
RSpec.configure do |config|
if ENV["CI"]
config.before(:example, :focus) { raise "Should not commit focused specs" }
else
config.filter_run focus: true
config.run_all_when_everything_filtered = true
end
require "test/unit"
class CountryMatcherTest < Test::Unit::TestCase
def test_valid_case
result = CountryMatcher.call("DE") do |match|
match.us { "US" }
match.de { "DE" }
match.gb { "GB" }
end
@marzdrel
marzdrel / func.rb
Last active January 22, 2017 13:55
# Little functional quirk to replace a CASE statement, when you first query an object
# and call a method to command an action. You can pass a block at the end for an ELSE
# statement.
#
# Usage:
#
# Func.switch order,
# available?: -> { order.submit },
# returned?: -> { order.cancel }
#
@marzdrel
marzdrel / gist:6139710
Last active December 20, 2015 13:29
Sleep Sort
#!/bin/bash
function f() {
sleep "$1"
echo "$1"
}
while [ -n "$1" ]
do
f "$1" &
shift
done