Skip to content

Instantly share code, notes, and snippets.

@rnmp
rnmp / gist:916793
Created April 13, 2011 01:25
Remove '#' or '0x' from hexadecimal color codes
def create
color = params[:color]
color[:color].gsub!(/^(#|0x)/, '')
@color = Color.new(color)
@color.user = current_user
if @color.save
redirect_to(root_url)
end
end
@rnmp
rnmp / gist:916788
Created April 13, 2011 01:21
Dice roller
def create
@roll = Roll.new(params[:roll])
@rolls = Roll.all(:order => "created_at DESC", :limit => 5)
# Creating a random id & name in case is empty
@number = (rand(900000)+100001)
@roll.id = @number
if @roll.name.empty?
@roll.name = "Roll #" + @number.to_s
end