Skip to content

Instantly share code, notes, and snippets.

# extending Object by reopening the Object class:
class Object
def blank?
respond_to?(:empty?) ? empty? : !self
end
end
# it's not obvious, that Object was extended and you can't see
# who extended the Object class by inspecting its ancestors:
Object.ancestors # => [Object, Kernel]
@rubiii
rubiii / .vimrc
Created September 29, 2010 09:58
syntax on
set nocompatible " It's VIM
" Width and height
set lines=87
set columns=145
" Environment
set history=200 " Set history to 200
set undolevels=1000 " Set undos to 1000
describe "#expects" do
before { something.expects(:some_method) }
around do |example|
begin
example.run
rescue Mocha::ExpectationError => e
e.message.should include("expected exactly once, not yet invoked: SomeObject.some_method")
end
end
require.paths.unshift(__dirname + '/lib/node')
var
mongo = require('mongodb'),
express = require('express'),
app = express.createServer();
app.configure(function() {
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
MyApp::Application.routes.draw do
resource :contacts
end
# which creates the following routes:
#
# contacts POST /contacts(.:format) {:controller=>"contacts", :action=>"create"}
# new_contacts GET /contacts/new(.:format) {:controller=>"contacts", :action=>"new"}
# edit_contacts GET /contacts/edit(.:format) {:controller=>"contacts", :action=>"edit"}
# GET /contacts(.:format) {:controller=>"contacts", :action=>"show"}
class EsimValidator < ActiveModel::Validator
include ActiveModel::Validations
validates_presence_of :name, :voucher_type, :delivery_date, :expiration_date
validates_numericality_of :sales_partner_id, :greater_than => 1, :only_integer => true
attr_accessor :record
def errors
record.errors
@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>
@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
$ rails console
Loading development environment (Rails 3.0.3)
ruby-1.9.2-p136 :001 > client = Savon::Client.new do
ruby-1.9.2-p136 :002 > wsdl.document = "https://www.usacycling.org/xml/riderinfo.php?wsdl"
ruby-1.9.2-p136 :003?> end
=> #<Savon::Client:0x00000104f5b978 @original_self=main, @wsdl=#<Savon::WSDL::Document:0x00000104f5b6d0 @request=#<HTTPI::Request:0x00000104f5b680>, @document="https://www.usacycling.org/xml/riderinfo.php?wsdl">, @http=#<HTTPI::Request:0x00000104f5b680>>
ruby-1.9.2-p136 :004 > client.wsdl.soap_actions
Retrieving WSDL from: https://www.usacycling.org/xml/riderinfo.php?wsdl
HTTPI tried to use the httpclient adapter, but was unable to find the library in the LOAD_PATH. Falling back to using the net_http adapter now.
HTTPI executes HTTP GET using the net_http adapter
@rubiii
rubiii / interfax_example01.rb
Created April 4, 2011 16:21
Savon InterFAX example: How to send a fax
# more examples at:
# https://gist.github.com/903337
require "rubygems"
# $ gem install savon (works with v0.9.1 and higher)
require "savon"
# convert hash key symbols to camelcase
Gyoku.convert_symbols_to(:camelcase)