Skip to content

Instantly share code, notes, and snippets.

View fnando's full-sized avatar

Nando Vieira fnando

View GitHub Profile
@fnando
fnando / allow.rb
Created July 4, 2011 22:35
Allow matcher
RSpec::Matchers.define :allow do |*values|
match do |record|
values.collect {|value|
record.send("#{@attribute}=", value)
record.valid?
record.errors[@attribute].empty?
}.all?
end
chain :as do |attribute|
@fnando
fnando / allow.rb
Created July 14, 2011 02:00
RSpec matcher
RSpec::Matchers.define :allow do |*values|
match do |record|
values.collect {|value|
record.send("#{@attribute}=", value)
record.valid?
record.errors[@attribute].empty?
}.all?
end
chain :as do |attribute|
@fnando
fnando / dev.conf
Created July 23, 2011 09:00
Nginx configuration for SSH tunnel
upstream tunnel {
server 127.0.0.1:3000;
}
server {
listen 80;
server_name dev.codeplane.com br.dev.codeplane.com;
location / {
proxy_set_header X-Real-IP $remote_addr;
# execute o bloco no contexto da variável number, passando a
# variável other_number como parâmetro para o bloco.
# o output deve exibir `true`
block = proc {|n|
puts n == self
}
number = 1
other_number = 1
@fnando
fnando / jquery.html
Created September 26, 2011 11:17
Conditionally include jQuery from different sources.
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script type="text/javascript">
if (typeof jQuery === "undefined") {
document.write(unescape("%3Cscript src='#{local_path}' type='text/javascript'%3E%3C/script%3E"));
};
</script>
class Foo
end
#=> funciona antes do 1.9.3
#=> exceção no 1.9.3
Foo.new(1,2,3,4,5,6,7)
@fnando
fnando / gist:1383103
Created November 21, 2011 16:16
Set some CSS classes based on browser's UA
;(function(document){
var ua = navigator.userAgent
, meta = ["non-ie"]
, version
;
if (ua.match(/firefox/i)) {
meta.push("firefox");
} else if (ua.match(/chrome/i)) {
meta = meta.concat(["chrome", "webkit"]);
@fnando
fnando / gist:1390587
Created November 24, 2011 03:48
Close duplicated tabs on Safari
tell application "Safari"
set theTabs to tabs of the first window
set theUrls to {}
repeat with theIndex from (count of theTabs) to 1 by -1
try
set theTab to item theIndex of theTabs
set theUrl to URL of theTab
if theUrl is not in theUrls then
class Thing
def name
puts "thing"
end
end
thing = Thing.new
def thing.name
super
@fnando
fnando / sample.rb
Created December 27, 2011 00:24
Set vs YAML
require "set"
require "yaml"
s = Set.new
s << 4
s << 5
s << 4
s = YAML.load(s.to_yaml)
p s.entries