Skip to content

Instantly share code, notes, and snippets.

@elle
elle / basic_authentication.rb
Last active December 8, 2017 01:57
Using Rack::Auth::Basic
# config/staging.rb
Rails.application.configure do
config.middleware.use "::Rack::Auth::Basic" do |u, p|
[u, p] == [ENV["BASIC_AUTH_USERNAME"], ENV["BASIC_AUTH_PASSWORD"]]
end
end
# .env
BASIC_AUTH_USERNAME = some_value
BASIC_AUTH_PASSWORD = some_password
# Ways to execute a shell script in Ruby
# Example Script - Joseph Pecoraro
cmd = "echo 'hi'" # Sample string that can be used
# 1. Kernel#` - commonly called backticks - `cmd`
# This is like many other languages, including bash, PHP, and Perl
# Returns the result of the shell command
# Docs: http://ruby-doc.org/core/classes/Kernel.html#M001111
@elle
elle / gol.rb
Last active February 27, 2022 23:24
Conway's game of life
class LiveCell
TRANSITION_RULES = {
2 => LiveCell.new,
3 => LiveCell.new,
}
def next_generation(living_neighbours_count)
TRANSITION_RULES.fetch(living_neighbours_count) { DeadCell.new }
end
end