Skip to content

Instantly share code, notes, and snippets.

View decioferreira's full-sized avatar

Décio Ferreira decioferreira

View GitHub Profile
@decioferreira
decioferreira / rails console help
Created November 14, 2011 15:22
reload rails console
$ rails console -h
Usage: console [environment] [options]
-s, --sandbox Rollback database modifications on exit.
--debugger Enable ruby-debugging for the console.
--irb DEPRECATED: Invoke `/your/choice/of/ruby script/rails console` instead
@decioferreira
decioferreira / mysql
Created November 14, 2011 16:32
Shell script and MySQL
#!/bin/bash
# MySQL connection
user_name="your_user_name"
db_name="your_db_name"
# Return the result of the query to a variable
result=$(mysql -u $user_name $db_name -sN -e "SELECT 1")
# print message on screen
@decioferreira
decioferreira / center.css
Created November 14, 2011 17:38
CSS center div with unknown width
.container {
clear: both;
float: left;
width: 100%;
overflow: hidden;
}
#menu {
padding: 0;
list-style-type: none;
@decioferreira
decioferreira / index.html.erb
Created November 15, 2011 12:02
Rails cycle helper
# Alternate CSS classes for even and odd numbers...
@items = [1,2,3,4]
<table>
<% @items.each do |item| %>
<tr class="<%= cycle("odd", "even") -%>">
<td>item</td>
</tr>
<% end %>
</table>
@decioferreira
decioferreira / _post.html.erb
Created June 5, 2012 18:04
Rendering Collections
<h2>#<%= post_counter + 1 %> <%= post.title %></h2>
@decioferreira
decioferreira / index.html.erb
Created June 5, 2012 18:19
Spacer Templates
<%= render :partial => @posts, :spacer_template => "post_ruler" %>
@decioferreira
decioferreira / tar.sh
Created June 5, 2012 18:44
Linux tar command
tar cvf images.tar *.jpg
@decioferreira
decioferreira / console_underscore
Created June 5, 2012 18:54
Rails console underscore variable
ruby > 1
=> 1
ruby > _ + 1
=> 2
ruby > _ + 1
=> 3
@decioferreira
decioferreira / rails_production_migrate
Created June 5, 2012 19:01
Rails production rake
RAILS_ENV=production rake db:migrate
@decioferreira
decioferreira / comment.rb
Created June 6, 2012 21:48
Multi-line comments
=begin
Anything between these two tokens
is ignored by the Ruby interpreter.
=end