Skip to content

Instantly share code, notes, and snippets.

@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
@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:917798
Created April 13, 2011 15:51
Register the clicked position of the page in a form
$(function(){
var page = $('#page')
page.prepend('<i id="position" />');
var position = $('#position')
position.hide();
$('.submit-hover').hide();
page.click( function(e){
$('#x').val(e.pageX);
$('#y').val(e.pageY);
position.css('top', e.pageY - 15);
@rnmp
rnmp / gist:917816
Created April 13, 2011 15:57
Sums the total time (float)
class Project < ActiveRecord::Base
belongs_to :company
has_many :logs
validates_presence_of :name
def total_hours
total_time = 0
logs.each do |l|
total_time += l.time.to_f
@rnmp
rnmp / gist:958164
Created May 5, 2011 23:09
:rsync Rakefile
require 'nanoc3/tasks'
user = "serveradmin@acualicio.us"
server = "acualicio.us"
path = "/nfs/c05/h01/mnt/70722/users/.home/domains/acualicio.us/"
# message = "changed on" + Time.now.localtime.strftime("%Y-%m-%d")
task :sync do
system "rsync -vru --exclude='.DS_Store' html #{user}@#{server}:#{path}"
end

Tabit

The God's easiest way to create tab-based interface.

Example

$(function(){
  $('#example').tabit();
});
@rnmp
rnmp / gist:985242
Created May 22, 2011 07:11
CSS3 gradients background clipping
h1 {
background: #eee -webkit-gradient(linear,
left 20, left 40,
color-stop(0, transparent),
color-stop(0.5, rgba(0, 0, 0, 0.33)),
color-stop(0.25, rgba(0, 0, 0, 0)),
color-stop(0.75, transparent));
-webkit-background-clip: text;
-webkit-text-fill-color: transparent; }
@rnmp
rnmp / gist:1002206
Created June 1, 2011 12:35
Perform an action when one or more checkboxes are checked
var runWhenClicked = function(){
var checked = $('#fave-restaurants').find(":checked");
checked.length > 0 ? $('#find-table-favorite').text('Buscar en los seleccionados') : $('#find-table-favorite').text('Buscar mesas'); }
$(':checkbox').click(runWhenClicked);
@rnmp
rnmp / gist:1002209
Created June 1, 2011 12:37
Zoom in CSS3 animation
@-webkit-keyframes roll-action {
0% {
-webkit-transform: scale(2);
opacity: 0; }
100% {
-webkit-transform: scale(1);
opacity: 1; } }
span.roll-result {
-webkit-animation: roll-action 0.25s; }
@rnmp
rnmp / README.md
Created July 4, 2011 17:52
Divit

Divit

A tiny grid-system designed to fit on almost any width of your container by providing percentage-based proportions.