Skip to content

Instantly share code, notes, and snippets.

@mcrmfc
mcrmfc / zendlog
Created January 11, 2012 16:19
zend logging (when not in Micro)
// Place this in your bootstrap file before dispatching your front controller
$writer = new Zend_Log_Writer_Firebug();
$logger = new Zend_Log($writer);
// Use this in your model, view and controller files
$logger->log('This is a log message!', Zend_Log::INFO);
@mcrmfc
mcrmfc / ruby_rand.rb
Created November 4, 2011 13:10
ruby random string
rand(36**length).to_s(36)
@mcrmfc
mcrmfc / ruby_plain_ssl.rb
Created October 19, 2011 10:37
ruby ssl
require "net/https"
require "uri"
uri = URI.parse('https://repo.dev.bbc.co.uk')
pem = File.read("../../keys/combine.pem")
#http = Net::HTTP::Proxy('www-cache.reith.bbc.co.uk', 80).new(uri.host, uri.port)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.cert = OpenSSL::X509::Certificate.new(pem)
http.key = OpenSSL::PKey::RSA.new(pem)
@mcrmfc
mcrmfc / ruby_singleton.rb
Created October 6, 2011 20:35
ruby singleton examples
require 'singleton'
class MySingleton
include Singleton
attr_accessor :myvar
def initialize
puts 'output from initialize in a singleton!'
end
end
@mcrmfc
mcrmfc / .gitconfig
Created May 23, 2011 14:36
.gitconfig
[core]
editor = "mvim -f -c 'au VimLeave * !open -a Terminal'"
[merge]
tool = vimdiff
guitool = mvim
[diff]
tool = vimdiff
guitool = mvim
[mergetool "mvim"]
cmd = mvim -f -d "$LOCAL" "$MERGED" "$REMOTE"
@mcrmfc
mcrmfc / ruby-debug cheat sheet
Created May 9, 2011 12:52
ruby-debug cheat sheet
To end the debugging session and return control to the app:
quit
To find out where you are:
where
Note, this will print out a stack trace only if you’ve added the Debugger.start as specified above. If you haven’t, where will only print out the line number and file name of where execution has reached.
To see where you are in context (current line with a few lines before and after):
list
@mcrmfc
mcrmfc / Cucumber Cheat Sheet
Created May 4, 2011 11:15
Cucumber Cheat Sheet
#Access Scenario Metadata
Before do |scenario|
p scenario.source_tag_names
end
@mcrmfc
mcrmfc / gist:938864
Created April 23, 2011 18:47 — forked from leshill/gist:870866
Cucumber/Capybara JS alert handling
# Add this to more_web_steps.rb
# Selenium docs: http://code.google.com/p/selenium/wiki/RubyBindings#Javascript_Alert/Confirm today!
When /^I (accept|dismiss) the "([^"]*)" alert$/ do |action, text|
alert = page.driver.browser.switch_to.alert
alert.text.should eq(text)
alert.send(action)
end
@mcrmfc
mcrmfc / Bundler Cheat Sheet
Created March 22, 2011 15:46
Bundler Cheat Sheet
To use a local packaged gem file:
1. Manually create vendor/cache
2. Add your .gem file to this directory
3. ALWAYS run bundle install with --no-cache option....all other gems will then be obtained from remote source
Note: when using :path, this can only be to a directory containing a .gemspec file
@mcrmfc
mcrmfc / Capybara-Mechanize
Created March 22, 2011 09:22
Set custom headers using Capybara-Mechanize
When /^I go to google$/ do
p page.driver.agent.request_headers = {'Accept-Language' => 'en-gb'}
visit('http://localhost:7001')
end
Then /^I should see the title google$/ do
find('title').text.should == 'RubyGems Documentation Index'
end