Skip to content

Instantly share code, notes, and snippets.

@mcrmfc
mcrmfc / htmlunit proxy bypass fix
Created March 17, 2011 15:52
HTMLUnit fix for proxy bypass
private static void setProxy(final HttpClient httpClient, final WebRequest webRequest) {
if (webRequest.getProxyHost() != null) {
final String proxyHost = webRequest.getProxyHost();
final int proxyPort = webRequest.getProxyPort();
final HttpHost proxy = new HttpHost(proxyHost, proxyPort);
if (webRequest.isSocksProxy()) {
final SocksSocketFactory factory = (SocksSocketFactory)
httpClient.getConnectionManager().getSchemeRegistry().getScheme("http").getSocketFactory();
factory.setSocksProxy(proxy);
}
@mcrmfc
mcrmfc / VIM - Vertical Buffer Split
Last active September 25, 2015 06:38
VIM - My cheat sheet
search and replace
-------------------
s/foo/bar/g changes each 'foo' to 'bar' in the current line.
:%s/foo/bar/g changes each 'foo' to 'bar' in all lines.
:5,12s/foo/bar/g changes each 'foo' to 'bar' for all lines between line 5 and line 12.
:'a,'bs/foo/bar/g changes each 'foo' to 'bar' for all lines between marks a and b.
:.,$s/foo/bar/g changes each 'foo' to 'bar' for all lines between the current line (.) and the last line ($).
:.,+2s/foo/bar/g changes each 'foo' to 'bar' for the current line (.) and the two next lines (+2).
:%s is equivalent to :1,$s
@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
@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 / 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 / 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 / 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 / .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_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 / 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)