Skip to content

Instantly share code, notes, and snippets.

[Time, Date].each do |clazz|
eval "#{clazz}::MONTHNAMES = [nil] + %w(January February March April May June July August September October November December)"
eval "#{clazz}::DAYNAMES = %w(Sunday Monday Tuesday Wednesday Thursday Friday Saturday)"
eval "#{clazz}::ABBR_MONTHNAMES = [nil] + %w(Jan Fev Mar Abr May Jun Jul Ago Set Out Nov Dez)"
eval "#{clazz}::ABBR_DAYNAMES = %w(Sun Mon Tue Wed Thu Fri Sat)"
end
class Time
class << self
@rrmartins
rrmartins / Ability.rb
Created May 25, 2012 16:23
:manage Cancan
permissions = Permission.find_all_by_group_id(<id_do_grupo_do_usuario>)
cannot :manage, :all
actions = ""
models = ""
# dps vai verificando as permissoes do usuario, e permitindo. tipo:
permissions.each do |permission|
@rrmartins
rrmartins / noticia.rb
Created May 29, 2012 16:01
Validacao
class Noticia << ....
validate :texto_inicio_igual
def texto_inicio_igual
noticias = Noticia.all
i = 0
noticias.each do |noticia|
if noticia.texto.split(" ")[0] === self.texto.split("")[0]
i += 1
end
class Week
attr_accessor :segunda_feira, :terca_feira, :quarta_feira, :quinta_feira, :sexta_feira
def initialize(segunda_feira,terca_feira,quarta_feira,quinta_feira,sexta_feira)
@segunda_feira = segunda_feira
@terca_feira = terca_feira
@quarta_feira = quarta_feira
@quinta_feira = quinta_feira
@sexta_feira = sexta_feira
@rrmartins
rrmartins / Error_Terminal
Created August 3, 2012 01:58
Error Devise with RSpec and Rails 3
.../spec/spec_helper.rb:27:in `block (2 levels) in <top (required)>': uninitialized constant ControllerMacros (NameError)
@rrmartins
rrmartins / gist:3488273
Created August 27, 2012 13:07
Sublime Text 2 - Useful Shortcuts

Sublime Text 2 – Useful Shortcuts (Mac OS X)

General

⌘T go to file
⌘⌃P go to project
⌘R go to methods
⌃G go to line
⌘KB toggle side bar
⌘⇧P command prompt
@rrmartins
rrmartins / rspec
Created October 18, 2012 19:23
Teste doidao... kkkk
assigns(:qty_sites_without_bp).should_not be_nil
@rrmartins
rrmartins / gist:4196385
Created December 3, 2012 17:06
Games API
[{"id"=>"491",
"name"=>{"us"=>"Gex 3: Deep Cover Gecko", "uk"=>"Gex 3: Deep Cover Gecko"},
"description"=>
"<p>There was a time where nearly any cute-ish animal could get his own trilogy of video games, costarring with real-life buxom blondes and saving the world from despicable evils. That time, sadly, has passed.</p>\n",
"platform"=>{"id"=>"6", "name"=>"PSP"},
"updated_date"=>"2009-11-02T12:25:40.00+0000",
"url"=>"http://www.gamesradar.com/psp/gex-3-deep-cover-gecko",
"images"=>
{"thumbnail"=>"http://static.gamesradar.com/images/empty_01_logo.jpg"}},
{"id"=>"4612",
---
http_interactions:
- request:
method: get
uri: http://api.gamesradar.com
body:
encoding: UTF-8
string: ! '<?xml version="1.0" ?><methodCall><methodName>listBatchSubscribe</methodName><params><param><value><string>284455d5b40a2451f127067cf7b5d39c-us4</string></value></param><param><value><string>95ab60ca50</string></value></param><param><value><array><data><value><struct><member><name>EMAIL</name><value><string>user@estoujogando.com.br</string></value></member><member><name>CREATED_AT</name><value><dateTime.iso8601>20121124T00:00:00</dateTime.iso8601></value></member><member><name>USERNAME</name><value><string>yogodoshi1</string></value></member><member><name>NAME</name><value><string>Usuário
1</string></value></member><member><name>BIRTH</name><value><string></string></value></member></struct></value><value><struct><member><name>EMAIL</name><value><string>user2@estoujogando.com.br</string></value></member><member><name>CREATED_AT</name><value><dateTime.iso8601>20121124T00:0
---
http_interactions:
- request:
method: get
uri: http://api.gamesradar.com/games?platform=psp&genre=all&page_num=1&page_size=10&sort=newest&api_key=0b6e6ede9f26471fadc548f7b04e7c54
body:
encoding: US-ASCII
string: ''
headers:
accept: