This file contains hidden or 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
items = [%{id: 1, deleted: false}, %{id: 2, deleted: true}, %{id: 3, deleted: false}] | |
for item <- items do | |
IO.puts Map.fetch!(item, :id) | |
end | |
# 1 | |
# 2 | |
# 3 | |
# [:ok, :ok, :ok] |
This file contains hidden or 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
// provided `onEdit` trigger cannot use `UrlFetchApp.fetch`. | |
// create a custom-named function, then add it as a new trigger in "Edit" > "Current Project Triggers" | |
// with events "From spreadsheet" > "On edit" | |
function customOnEdit(e) { | |
const range = e.range; | |
const row = range.getRow(); | |
const sheet = e.source.getActiveSheet(); | |
const data = { | |
vendor: sheet.getRange(row, 1).getValue(), |
This file contains hidden or 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
# macOS | |
for f in `ag -l <target> [path]`; do sed -i '' -e 's/<target>/<replacement>/' $f; done | |
# Linux | |
for f in `ag -l <target> [path]`; do sed -i'' -e 's/<target>/<replacement>/' $f; done |
This file contains hidden or 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
from h in Webhook, where: fragment("?->>? = ?", h.body, "title", ^"some title") # note `=` NOT `==` | |
from h in Webhook, where: fragment("?->>? = ?::text", h.body, "title", ^"some title") # can specify type if needed | |
from h in Webhook, where: fragment("?->>'title' ILIKE ?", h.body, ^"some title") |
This file contains hidden or 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
# Ruby's `=` can be a part of a method name, but is not a method on its own. Consider: | |
class MyClass | |
def initialize(value) | |
@a = value | |
end | |
def a=(new_value) # `=` is part of a method name | |
@a = new_value # `=` is an operator | |
end | |
This file contains hidden or 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
# from http://youtu.be/fGFM_UrSp70 | |
def slow(&block) | |
block.call | |
end | |
def fast | |
yield # 5x faster than passing a block as an argument | |
end |
This file contains hidden or 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
#TODO Remove this brittle spec after it proves that the migration works | |
require 'rails_helper' | |
migration_file_name = '20150307173710_add_father_deceased_to_orphans.rb' | |
migration_file_path = Rails.root.join 'db', 'migrate', migration_file_name | |
version = migration_file_name.split('_').first | |
require migration_file_path |
This file contains hidden or 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
#TODO Remove this brittle spec after it proves that the migration works | |
require 'rails_helper' | |
migration_file_name = '20150226095809_add_status_enums_to_orphan.rb' | |
migration_file_path = Rails.root.join 'db', 'migrate', migration_file_name | |
version = migration_file_name.split('_').first | |
require migration_file_path |
This file contains hidden or 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
# no indentation | |
def send_mail(source) | |
Mailer.deliver(to: '[email protected]', from: '[email protected]', subject: 'Important message', body: source.text) | |
end | |
# single indent | |
def send_mail(source) | |
Mailer.deliver( | |
to: '[email protected]', | |
from: '[email protected]', |
This file contains hidden or 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
# Solution 1 | |
class Partner < ActiveRecord::Base | |
belongs_to :province | |
has_many :orphan_lists | |
delegate :code, to: :province, prefix: true | |
end | |
class Orphan < ActiveRecord::Base |
NewerOlder