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
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>Label</key> | |
<string>notes.upload</string> | |
<key>RunAtLoad</key> | |
<true/> | |
<key>WorkingDirectory</key> | |
<string>[your directory]</string> |
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
#!/bin/bash | |
msg=${*:-'regular upload'} | |
git add . | |
git commit -m "$msg" | |
git push | |
exit 0 |
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
def missing_arguments(block) | |
block.call('arg1', 'arg2') | |
end | |
a_proc = Proc.new { |a, b, c| "a_proc outputs #{a} & #{b} & #{c}" } | |
a_lambda = lambda { |a, b, c| "a_lambda output #{a} & #{b} & #{c}" } | |
puts missing_arguments(a_proc) | |
puts missing_arguments(a_lambda) |
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
def proc_return | |
Proc.new { return 'return from inside Proc' }.call | |
return 'return from proc function' | |
end | |
def lambda_return | |
lambda { return 'return from inside lambda' }.call | |
return 'return from lambda function' | |
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
# set up instances | |
# Since blocks cannot be stored in a variable, we create a method to inspect it. | |
def dummy_method(&a_block) | |
puts "A block is a #{a_block.class}" | |
puts "A block instance: #{a_block.inspect}" | |
end | |
a_proc = Proc.new { 'This is a proc' } | |
a_lambda = lambda { 'This is a lamnda' } | |
# test begins |
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
# method definition | |
def run_variations(variation_options = {}, &block) | |
keys = variation_options.keys | |
values = variation_options.fetch_values(*keys) | |
variant_klass = Struct.new(*keys) | |
values.first | |
.product(*values[1..-1]) | |
.each do |variation| | |
block.call(variant_klass.new(*variation)) |
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
def send_money(amount) | |
puts "Sending $#{amount}" | |
sleep 1 # Simulate network call sending of money | |
end | |
lock = Mutex.new | |
threads = [] | |
money_is_sent = false | |
2.times 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
require 'thwait' | |
require 'pg' | |
start = Time.now | |
first_sleep = Thread.new do | |
puts 'Starting sleep 1' | |
conn = PG::Connection.open(dbname: 'test') | |
conn.exec('SELECT pg_sleep(1);') | |
puts 'Finished sleep 1' |
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 'benchmark/ips' | |
def test | |
Benchmark.ips do |bm| | |
bm.report('#preload ') do | |
Speaker.preload(:talks).to_a | |
end | |
bm.report('#eager_load') do | |
Speaker.eager_load(:talks).to_a |
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
# Speaker -> Talks | |
# CORRECT USAGE | |
# Select speakers that have one or more talks and returns all attributes (columns) plus talk's title. | |
Speaker.joins(:talks).select('distinct speakers.*, talks.title as talks_title').to_a | |
# SELECT distinct speakers.*, talks.title as talks_title FROM `speakers` INNER JOIN `talks` ON `talks`.`speaker_id` = `speakers`.`id` | |
# Select speaker whose associated talk(s) is at status 5. | |
Speaker.joins(:talks).where(talks: {status: 5}) | |
# SELECT `speakers`.* FROM `speakers` INNER JOIN `talks` ON `talks`.`speaker_id` = `speakers`.`id` WHERE `talks`.`status` = 5 |