Skip to content

Instantly share code, notes, and snippets.

View rodrigoflores's full-sized avatar

Rodrigo Flores rodrigoflores

View GitHub Profile
#outer {
width: 500px;
}
#outer:hover #text {
-webkit-transition: left linear .5s;
position: absolute;
left: 100px;
}
p {
background-color: red;
}
# do .. end when we're only interested on the side effect
array.each do |item|
puts item
end
# { } when we want the result of the evaluation
array.map { |item|
item + 1
@rodrigoflores
rodrigoflores / gist:2372462
Created April 13, 2012 00:57
Has many association
irb(main):013:0> blog = Blog.new
=> #<Blog id: nil, title: nil, created_at: nil, updated_at: nil>
irb(main):014:0> blog.save
(0.2ms) BEGIN
SQL (0.4ms) INSERT INTO `blogs` (`created_at`, `title`, `updated_at`) VALUES ('2012-04-13 00:56:01', NULL, '2012-04-13 00:56:01')
(19.5ms) COMMIT
=> true
irb(main):015:0> post = blog.posts.new
=> #<Post id: nil, blog_id: 2, created_at: nil, updated_at: nil>
irb(main):016:0> post.save
class Password < ActiveRecord::Base
belongs_to :user
scope :current, where(:changed_at => nil)
end
class Password < ActiveRecord::Base
belongs_to :user
scope :current, where(:changed_at => nil)
end
flores in /Users/flores/Code/sum/sum/mdown-erlang with 1.9.3-p125 on (master *)
% erl
Erlang R15B (erts-5.9) [source] [64-bit] [smp:2:2] [async-threads:0] [hipe] [kernel-poll:false]
Eshell V5.9 (abort with ^G)
1> c(markdown).
{ok,markdown}
2> markdown:to_html(<<"# OK #">>).
"<h1>OK</h1>\n"
3> markdown:to_html(<<"# OK #\n * OK">>).
@rodrigoflores
rodrigoflores / casa.rb
Created August 25, 2011 12:59
Case where with classes
case my_var
when String then puts "It is a string"
when Integer then puts "It is an integer"
else puts "It is another thing"
end
#instead of
case my_var.class
when String then puts "It is a string"
when Integer then puts "It is an integer"
require 'rubygems'
require 'nokogiri'
# Nokogiri 1.4.4
object = <<-EOF
<object width="425" height="349"><param name="movie" value="http://www.youtube.com/v/dQw4w9WgXcQ?version=3&amp;hl=en_US&amp;rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/dQw4w9WgXcQ?version=3&amp;hl=en_US&amp;rel=0" type="application/x-shockwave-flash" width="425" height="349" allowscriptaccess="always" allowfullscreen="true"></embed></object>
EOF
puts Nokogiri::HTML.fragment(object).to_html
require 'sixarm_ruby_email_address_validation'
include EmailAddressValidation
email = 'email@invalid'
EMAIL_ADDRESS_EXACT_PATTERN =~ email # => 0