Skip to content

Instantly share code, notes, and snippets.

I18n.backend.class.send(:include, I18n::Backend::Fallbacks)
I18n.default_locale = :au
I18n.fallbacks[:au] = [:au, :en]
I18n.fallbacks[:gb] = [:gb, :au, :en]
Time.zone_default = Time.send(:get_zone, 'Sydney')
["2011-10-20 23:23:59 +1000", "2011-10-20 23:23:59 -1000", "2010-08-14 05:17:01 +1000", "2011-11-18 11:29:30 +1100", "2011-09-25 16:17:44 +1000"].sort # => ["2010-08-14 05:17:01 +1000", "2011-09-25 16:17:44 +1000", "2011-10-20 23:23:59 +1000", "2011-10-20 23:23:59 -1000", "2011-11-18 11:29:30 +1100"]
attr_accessor :cat, :dog
attr_accessor :banana, :apple
attr_encrypted :cat, :dog
attr_encrypted :banana
@tatey
tatey / gist:1479210
Created December 15, 2011 00:09
Everyday Hero JavaScript API Wrapper
var api = new EverydayHero({event: '3284'});
api.top_ten('individual', callback);
api.top_ten('team', callback);
api.total(callback);
(function($) {
var ItemView = function(fundraiser) {
this.fundraiser = fundraiser;
this.template = _.template(document.getElementById('widget-item').innerHTML);
this.render = function() {
return this.template(this.fundraiser);
}
return this;
@tatey
tatey / curl.sh
Created January 23, 2012 01:08
Temando Test API
curl -H 'Content-Type: application/soap+xml;charset=UTF-8;' -d '<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header>
<wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/04/secext">
<wsse:UsernameToken>
<wsse:Username>temandotest</wsse:Username>
<wsse:Password>password</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header> <soapenv:Body>
@tatey
tatey / mocha_vs_simple_delegator.rb
Created February 6, 2012 22:30
Mocha VS SimpleDelegate
user system total real
mocha: 0.000000 0.000000 0.000000 (0.000277)
simple_delegator: 0.000000 0.000000 0.000000 (0.000024)
class OrdersController < ApplicationController
respond_to :json
attr_accessor :order, :model
helper_method :order
protected :order
def create
@order = model.create params[:order]
respond_with @order
@tatey
tatey / gist:1768472
Created February 8, 2012 11:48
SimpleMock
# Inspired by "Mocking with MiniTest::Mock and SimpleDelegator" it would be
# great to have a library with no dependancies that gives you the behaviour
# talked about in the blog post without learning a new API.
# http://tatey.com/2012/02/07/mocking-with-minitest-mock-and-simple-delegator/
# Without an argument, SimpleMock behaves identically to MiniTest::Mock.new
mock = SimpleMock.new
mock.expect :valid?, false
mock.valid? # => false
mock.save # => NoMethodError
@tatey
tatey / benchmark.rb
Created February 20, 2012 22:11
Mocha VS MiniTest::Mock and SimpleDelegate VS SimpleMock
require 'benchmark'
require 'delegate'
require 'mocha'
require 'simple_mock'
Benchmark.bm(10000) do |x|
x.report :mocha do
array = [1]
array.expects(:push).with(2).returns([1, 2])
array.push(2)