This is a scratchpad of style guidelines for Ruby. When undefined, there are multiple ways that are acceptable and dependent on context.
- Never use explicit return when intent is clear
- Use as a short circuit guard statement
Gemfile.lock |
require 'net/http' | |
module Net | |
module DefaultProxy | |
# Defaults all requests through Net::HTTP through an http proxy. | |
# Example: | |
# require 'net/http' | |
# require 'net/http_extensions' | |
# Net::HTTP.set_http_proxy! | |
# |
very thin consistency, strong tomato flavor (maybe canned tomatos with juice?). chicken broth and tomato base.
Unit tests should pass when run in random order. But for an existing legacy
project, certain tests might depend on the execution order. One test might run
perfectly fine by itself, but fail miserably when run after another test.
Rather than running different combinations manually, RSpec 2.8 has the option
to run specs in random order with the --order random
flag. But even with
this, it can be hard to determine which specific test is causing the
dependency. For example:
class << self | |
# Define an attr_accessor, but the reader method will | |
# set the variable if there is a first argument | |
def dsl_accessor(*args) | |
args.each do |name| | |
class_eval <<-ACCESSORS | |
attr_writer :#{name} | |
def #{name}(*args) | |
send("#{name}=", args.first) if !args.empty? | |
@#{name} |
# http://danielmiessler.com/study/lsof/ | |
sudo lsof -c haproxy | |
sudo lsof -iTCP | grep LISTEN | |
# http://danielmiessler.com/study/tcpdump/ | |
# capture unlimited length, on loopback device, don't resolve hostname, absolute sequence numbers, tcp, src or dst port == 443 | |
sudo tcpdump -s 0 -i lo0 -n -S tcp port 443 |
Port http://guides.rubyonrails.org/performance_testing.html to RSpec. Add as another example group or add to existing controller example group
describe SomeController, :performance => true do
# someway to load seed data for these sets of tests
fixtures :production_dump
use_database :production
def commit_for(pathspec = "HEAD") | |
`git log -1 --format=%H #{pathspec}`.chomp | |
end | |
def oneline_for(pathspec = "HEAD") | |
`git log -1 --oneline #{args[:good]}`.chomp | |
end | |
# remember what HEAD is so we can jump back to it | |
START = commit_for('HEAD') |
require 'new_relic' | |
require 'faraday' | |
require 'active_support' | |
class InstrumentationMiddleware < Faraday::Middleware | |
extend NewRelic::Agent::MethodTracer | |
def call(env) | |
uri = env[:url] | |
method = env[:method] | |
metrics = ["External/#{uri.host}/Faraday/#{method}", "External/#{uri.host}/all"] |