Skip to content

Instantly share code, notes, and snippets.

# Para salvar a altura e largura das imagens enviadas pelo plugin paperclip, utilize o callback abaixo
#
# class Document < ActiveRecord::Base
#
# has_attached_file :document, :styles => { :medium => "300x300>" }
#
# before_save :save_dimensions
#
# def save_dimensions
# if document.image?
var Interval = function( fn, delay ) {
this.id = null;
this.fn = fn;
this.delay = delay;
};
Interval.prototype = {
start: function() {
if (this.id === null) this.id = setInterval(this.fn, this.delay);
@felipeelias
felipeelias / tests.watchr.rb
Created April 28, 2010 01:21 — forked from boxedup/tests.watchr
Watchr autotest file
ENV["WATCHR"] = "1"
system 'clear'
def growl(message)
growlnotify = `which growlnotify`.chomp
title = "Watchr Test Results"
message.gsub! /\[[0-9]+?m/, ''
image = message.include?('0 failures, 0 errors') ? "~/.watchr_images/pass.png" : "~/.watchr_images/fail.png"
options = "-w -n Watchr --image '#{File.expand_path(image)}' -m '#{message}' '#{title}'"
system %(#{growlnotify} #{options} &)
@felipeelias
felipeelias / replace-class.jquery.js
Created June 8, 2010 13:28
replaceClass plugin for jQuery
jQuery.fn.extend({
replaceClass: function(original, replace) {
return this.each(function() {
jQuery(this).removeClass(original);
jQuery(this).addClass(replace);
});
}
});
(1..100).each{|n|f=n%3==0?"Fizz":nil;b=n%5==0?"Buzz":nil;p f||b ?"#{f}#{b}":n}
/*
* This file is part of the Spludo Framework.
* Copyright (c) 2009-2010 DracoBlue, http://dracoblue.net/
*
* Licensed under the terms of MIT License. For the full copyright and license
* information, please see the LICENSE file in the root folder.
*/
var child_process = require('child_process');
var fs = require("fs");
@felipeelias
felipeelias / rspec_should_change_bug.rb
Created November 15, 2010 20:50
This example should not fail with rspec, but...
require 'rubygems'
require 'rspec'
class TestBug
attr_reader :array
def initialize
@array = []
end
@felipeelias
felipeelias / ultra_simple_counter.rb
Created April 11, 2011 14:06
Prints 1 to 10 clearing the screen (like a progress bar)
(1..10).each do |i|
print "\r"
print "#{i}"
sleep 0.1
end
@felipeelias
felipeelias / highline_gem_use_case.rb
Created April 11, 2011 14:15
Ask for username and password
require 'highline'
prompt = HighLine.new
prompt.say("Hello!")
username = prompt.ask("Tell me your username: ")
password = prompt.ask("And now your password: ") { |options| options.echo = false }
prompt.say("Thanks #{username}! bye")
module AuthenticationMatcher
class RequireAuthentication
def initialize(method, action, params, context)
@method = method
@action = action
@params = params
@context = context
end
def matches?(controller)