Skip to content

Instantly share code, notes, and snippets.

@rubiii
rubiii / betfair_sample_request_created_by_soapui.xml
Created December 22, 2010 16:43
using savon to talk to the betfair soap api
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:bfex="http://www.betfair.com/publicapi/v5/BFExchangeService/"
xmlns:v5="http://www.betfair.com/publicapi/types/exchange/v5/">
<soapenv:Header/>
<soapenv:Body>
<bfex:getAllMarkets>
<bfex:request>
<header>
<clientStamp>stamp</clientStamp>

Hi,

I would love to hear your opinion on the idea of “combining RDoc and RSpec to create testable documentation”. Let me explain:

Given you have several RDoc files like this one:

= Examples

Some example code snippets.
SOAP request:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="http://v1_0.validation.ws.chief.blau.de/">
<soapenv:Header/>
<soapenv:Body>
<v1:validateName>
<validationRequest>
<names>
<firstName>David</firstName>
<lastName>Hasselhoff</lastName>
@rubiii
rubiii / decimal_validator.rb
Last active April 11, 2018 17:29
Rails validator for Postgres decimal type with custom precision and scale
class DecimalValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
precision = options[:precision]
scale = options[:scale]
if !precision || !scale
raise ArgumentError, "#{self.class.name} expects :precision and :scale option"
end
@rubiii
rubiii / application_controller.rb
Last active April 11, 2018 17:26
Rails: Redirect users to the last page they were trying to access after login
class ApplicationController < ActionController::Base
before_action :set_return_to
def set_return_to
if !request.xhr? && request.format.html? && request.get?
session[:return_to] = request.url
end
end
end
# rubygems.org/gems/savon by examples
# overview of examples at: http://gist.github.com/gists/427837
require "savon"
# HTTP basic authentication
client = Savon::Client.new do
wsdl.location = "http://users.example.com?wsdl"
request.basic_auth "username", "password"
end
@rubiii
rubiii / savon_instantiation.rb
Created June 6, 2010 19:47
Savon - Instantiating a Savon::Client
# rubygems.org/gems/savon by examples
# overview of examples at: http://gist.github.com/gists/427837
require "savon"
# = Instantiation without a WSDL
#
# Retrieving and parsing the WSDL is a pretty slow operation. And even though it's cached after the first time,
# it's still a pretty slow operation.
#
# When working without a WSDL you have to set the SOAP namespace and endpoint manually. Also Savon does not know
@rubiii
rubiii / crack_on_speed.rb
Created December 22, 2010 20:48
Crack with a Nokogiri SAX parser
require "crack"
require "nokogiri"
module NokogiriParser
class Document < Nokogiri::XML::SAX::Document
def stack
@stack ||= []
end
// Takes a screenshot from a given Tweet.
// Usage: phantomjs twitter_screenshot.js https://twitter.com/Snowden/status/777557723118440448
var system = require("system"),
args = system.args;
var url = args[1];
if (!url) {
console.log("Please provide the URL to a Tweet.");
@rubiii
rubiii / how_it_works.md
Created December 2, 2012 11:14
MacVim-Formatter for RSpec
$ rspec --format MacVimFormatter --color spec