This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "crack" | |
require "nokogiri" | |
module NokogiriParser | |
class Document < Nokogiri::XML::SAX::Document | |
def stack | |
@stack ||= [] | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |