Skip to content

Instantly share code, notes, and snippets.

View juliocesar's full-sized avatar

Julio Cesar Ody juliocesar

View GitHub Profile
class Hash
def self.from_block &block
Hash[*BlockBuilder.build(&block)]
end
class BlockBuilder
@@collected = []
class << self
def build(&block)
instance_eval &block
@juliocesar
juliocesar / gist:371842
Created April 20, 2010 00:23
Simple object regex method router
# >> class MyClass; include RegexRouter; end
# => MyClass
# >> obj = MyClass.new
# => #<MyClass:0x101859100 @routes={}>
# >> obj[%r(/words/(\w+))] = lambda do |word| puts "Found: #{word}" end
# => #<Proc:0x000000010184bb40@(irb):3>
# >> obj.go '/words/boo'
# Found: boo
# => nil
require 'rubygems'
require 'pathname'
require 'rails/all'
class SmallNSexy < Rails::Application
config.session_store :cookie_store, :key => '_omg_session'
config.secret_token = '1319d8ccf1b9bfbdefcb6aa380a044ce'
# ^ because -> http://twitter.com/wycats/status/13898343700
class Page
# Useful matcher for matching proximity of numbers so you can do things like
# 4.should be_close_to(5).by(1)
# or with Rails
# something.created_at.should be_close_to(somethingelse.created_at).by(10.minutes)
# "by" is not mandatory, but desirable since proximity is highly contextual
module CustomMatchers
class BeCloseTo
def initialize expected
@expected = expected
// Could swear I shared this before, but here it goes again...
// $.ghost
// Oh, by the way, it works like this:
//
// $('myform :text:first').ghost('username');
//
// The above will make the first text element of a form display a
// slightly faded "username" text inside until focused.
$.ghost = function(element, label, options) {

Dear Xavier,

thanks for your prompt reply. I for one think that should dbiyf run out of databases to talk about - not that there's a risk of it happening these days - you can start ybiyf (your brain is your friend) with no fear of failure.

It's funny you should mention my attitude towards my partner sleeping around, as just last week she told me she had sex with a muscular surfer in the freezing waters of Bondi Beach, and that apparently wouldn't disturb him in the slightest. Which made me think less of myself on top of everything.

Your stance towards strippers is interesting. Though I don't think there's much baggage involved these days. They are, however, getting really greedy as of 5 years ago. Used to be that in order to get a lap dance, all you had to do is show up and be reasonably good looking (not a problem in my case). Nowadays you won't get anywhere for less than $100 nicely folded into their crack. I think that means this whole market is shifting towards the sugar daddies' advantage. Soon enough

function on() {
for (var i = 0, len = arguments.length - 1; i < len; i++) if (RegExp(arguments[i]).test(document.location.pathname)) {
arguments[len]()
break;
}
}
@juliocesar
juliocesar / testing_front_end_rspec_capybara.md
Created October 21, 2010 23:51
Testing front-end for a Sinatra app with RSpec and Capybara

Testing front-end for a Sinatra app with RSpec and Capybara

I've used Cucumber quite a bit on my last job. It's an excellent tool, and I believe readable tests are the way to the future. But I could never get around to write effective scenarios, or maintain the boatload of text that the suite becomes once you get to a point where you have decent coverage. On top of that, it didn't seem to take much for the suite to become really slow as tests were added.

A while ago I've seen a gist by Lachie Cox where he shows how to use RSpec and Capybara to do front-end tests. That sounded perfect for me. I love RSpec, I can write my own matchers when I need them with little code, and it reads damn nicely.

So for my Rails Rumble 2010 project, as usual, I rolled a Sinatra app and figured I should give the idea a shot. Below are my findings.

Gemfile

@juliocesar
juliocesar / gist:744259
Created December 17, 2010 00:14
closure-compiler compiling an empty method
>> require 'closure-compiler'
=> true
>> require 'benchmark'
=> true
>> puts Benchmark.measure { Closure::Compiler.new.compile 'function foo() {}' }
0.000000 0.010000 2.600000 ( 1.571835)
=> nil
>> puts Benchmark.measure { Closure::Compiler.new.compile 'function foo() {}' }
0.000000 0.000000 2.630000 ( 1.624686)
=> nil
module Invisibility
def self.included base
base.send :attr_reader, :visible
end
def activate
@visible = false
end