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
# build: | |
# $ docker build -t rails_cred . | |
# | |
# usage: | |
# $ docker run -it --rm \ | |
# -e RAILS_MASTER_KEY=$RAILS_MASTER_KEY \ | |
# -v `pwd`/config/credentials.yml.enc:/app/config/credentials.yml.enc \ | |
# -v `pwd`/config/credentials:/app/config/credentials \ | |
# rails_cred |
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
# bad | |
class A | |
def cool_calc(b) | |
b.foo + b.bar * 2 | |
end | |
end | |
# good | |
class B | |
def cool_value |
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
enum = Enum.new(:a, :b, :c) | |
status = :b | |
# pattern 1 | |
enum.case status do | |
_when(:a) do | |
p :a | |
end | |
_when :b do |
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
module CaseMatch | |
class Error < StandardError; end | |
class Case | |
EMPTY_BLOCK = -> {} | |
def initialize(obj, cases) | |
@obj = obj | |
@cases = cases | |
@values = [] |
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 'binding_of_caller' | |
module EnumeratorPipeline | |
class Builder | |
def initialize(name) | |
@callbacks = [] | |
@callbacks << binding.of_caller(1).method(name) | |
end | |
def >>(name) |
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
use std::io::{self, Empty, BufRead, Write, Cursor}; | |
fn read_input<R, W>(source: Option<R>, mut writer: W) -> String | |
where R: BufRead, W: Write | |
{ | |
write!(&mut writer, "input: ").unwrap(); | |
writer.flush().unwrap(); | |
let mut input = String::new(); | |
match source { |
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
# app/models/article.rb | |
class Article < ApplicationRecord | |
has_many :article_publications | |
scope :draft, -> { left_joins(:article_publications).where(article_publications: { id: nil }) } | |
scope :published, -> { joins(:article_publications) } | |
end | |
# app/models/article_publication.rb | |
class ArticlePublication < ApplicationRecord |
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
# frozen_string_literal: true | |
require "bundler/inline" | |
gemfile(true) do | |
source "https://rubygems.org" | |
git_source(:github) { |repo| "https://github.com/#{repo}.git" } | |
gem "rails", github: "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
<% A.foo(@user) do |f| %> | |
<%= f.label :name %> | |
<%= f.text_field :name %> | |
<% 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
resource "aws_db_instance" "db" { | |
count = "${terraform.workspace == "default" ? 1 : 0}" | |
} | |
resource "aws_rds_cluster" "db" { | |
count = "${terraform.workspace == "default" ? 0 : 1}" | |
} | |
locals { | |
db_endpoint = "${terraform.workspace == "default" ? aws_db_instance.db.endpoint : aws_rds_cluster.db.endpoint}" |