Skip to content

Instantly share code, notes, and snippets.

View tinogomes's full-sized avatar
😀

Celestino Gomes tinogomes

😀
View GitHub Profile
require "rubygems"
require "benchmark"
params = {}
puts "with params = {}"
Benchmark.bm(16) do |x|
x.report("with if-inline: ") { 1_000_000.times { params[:page] ? params[:page].to_i : 1 } }
x.report("with max......: ") { 1_000_000.times { [params[:page].to_i, 1].max } }
x.report("with or.......: ") { 1_000_000.times { (params[:page] || 1).to_i } }
x.report("with fetch....: ") { 1_000_000.times { params.fetch(:page, 1).to_i } }
dns - http://freedns.ws
google apps - http://google.com/a
yola, pra criar o site - http://www.yola.com/
logonerds, logos por $50 - http://www.logonerds.com/
wuffo, forms builder - http://wufoo.com/
analytics, pra monitorar - http://www.google.com/analytics/
blog (tumblr)
twitter
adwords
@tinogomes
tinogomes / gist:385573
Created April 30, 2010 18:17
Benchmark: !!(value) or (value == expected)
# Benchmark: !!(value) or (value == expected)
require 'benchmark'
n = 5000000
value = :value
Benchmark.bm do |x|
x.report { p( !!(1 < 0 || 1 > 0) ) }
x.report { p( (1 < 0 || 1 > 0) == true ) }
x.report { p( !!(nil || value) ) }
<div style="width:400px;overflow:auto">
<h2>This comes from ajax request</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean non velit. Donec pharetra, felis ut tristique adipiscing, diam magna rhoncus neque, sit amet convallis nibh nibh vel libero. Nulla facilisi. In eleifend nisl quis lorem. Duis semper fringilla justo. Proin imperdiet sapien sed lectus. Integer quis nisl et est elementum tempor. Morbi quis tellus nec turpis suscipit molestie. Praesent sed pede. Pellentesque ac orci. Sed sit amet urna eget tellus hendrerit aliquet. Nulla consectetur, pede aliquam ornare placerat, nunc augue commodo leo, sit amet elementum dolor est eleifend magna.
</p>
</div>
@tinogomes
tinogomes / magic-cards.txt
Created July 5, 2010 17:51
lista de cartas disponíveis e script para pegar os preços no Universo Parelelo
1,Grixis Panorama,Land
1,Naya Panorama,Land
1,Bant Panorama,Land
1,Obelisk of Esper,3
1,Obelisk of Bant,3
1,Lush Growth,G
1,Elvish Visionary,1G
1,Elvish Visionary,1G
1,Cylian Elf,1G
1,Savage Hunger,2G
@tinogomes
tinogomes / geolocation.rb
Created July 15, 2010 20:02
Geolocation
#--
# Copyright (c) 2006 Andrew Turner <geolocation@highearthorbit.com>
#
# Based on Geocoder - Copyright (c) 2006 Paul Smith <paul@cnt.org>
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
$ whois ericfer.com
Whois Server Version 2.0
Domain names in the .com and .net domains can now be registered
with many different competing registrars. Go to http://www.internic.net
for detailed information.
Domain Name: ERICFER.COM
Registrar: ENOM, INC.
@tinogomes
tinogomes / Ruby Annotation for TextMate Language
Created November 24, 2010 21:47
Add this on Ruby language
{ name = 'keyword.other.annotation.ruby';
comment = ' everything being a method but having a special function is a..';
match = '^\s*\b(private|public|protected)\b.*?$\n';
},
@tinogomes
tinogomes / gist:749885
Created December 21, 2010 12:37
To downcase all keys and subkeys from a hash
class Hash
def downcase_all_keys
result = self.map do |k,v|
[
k.downcase,
case v.class.name
when "Hash" then v.downcase_all_keys
when "Array" then v.map {|i| i.downcase_all_keys }
else v
end
module Authentication
def logged_in?
current_user.is_a?(User)
end
def current_user
@current_user ||= User.find_by_id(session[:user_id]) || :false
end
def current_user=(new_user)