Skip to content

Instantly share code, notes, and snippets.

View thesp0nge's full-sized avatar
🏡
Working from home

Paolo Perego thesp0nge

🏡
Working from home
View GitHub Profile
if current_user != nil
@wishes = Wish.where(:user_id => current_user.id)
#snip...
end
@thesp0nge
thesp0nge / gist:633958
Created October 19, 2010 10:08
authentication#create method for pernataleiovorrei.com (buggy version)
def create
omniauth = request.env["omniauth.auth"]
authentication = Authentication.find_by_provider_and_uid(omniauth['provider'], omniauth['uid'])
if authentication
sign_in_and_redirect(:user, authentication.user)
else
current_user.authentications.create(:provider=>omniauth['provider'], :uid=>omniauth['uid'])
flash[:notice] = "You rock man"
redirect_to authentications_url
end
@thesp0nge
thesp0nge / gist:640153
Created October 22, 2010 08:14
Hello world
puts "Hello world!"
@thesp0nge
thesp0nge / gist:640297
Created October 22, 2010 10:20
A java retouch
public int metodo() {
return (i<3)? 4 : 5;
}
@thesp0nge
thesp0nge / gist:667680
Created November 8, 2010 13:15
Bugged Velocity
#if ($toOpenReworked.equalsIgnoreCase($toCheck) ||
($toCheck.containsIgnoreCase($toOpenReworked)) ||
($toOpenReworked.containsIgnoreCase($toCheck)))
#set($class="class ='active'")
#end
module Owasp
module Esapi
module Ruby
module Validator
class DateValidator < Owasp::Esapi::Ruby::Validator::PlainValidator
...
def validate(string)
# return true if this is a real timestamp or false otherwise
end
end
@thesp0nge
thesp0nge / gist:968656
Created May 12, 2011 14:51
welcome_spec.rb
require 'spec_helper'
context "A user reach the welcome page" do
it "must find a 'Register Now' button" do
visit root_path
page.should have_link('Register Now')
end
it "must be redirected to user registration when clicking the 'Register Now' link" do
@thesp0nge
thesp0nge / gist:968754
Created May 12, 2011 15:31
A_just_for_fun_spec.rb
require 'spec_helper.rb'
context 'A user is coming to user page' do
it 'be happy' do
true
end
end
@thesp0nge
thesp0nge / README.md
Created May 19, 2011 08:31
date_normalizer.rb

DateNormalizer

DateNormalizer is a very simple class coded in almost 5 minutes to solve the problem to convert a string like '12-ott-2321' in a ruby Time object.

Please note that no sanity checks are perfomed over the string and the month names allowed are in Italian only and in the short 3 letters format.

License

Consider this code as new BSD licensed.

@thesp0nge
thesp0nge / ct.rb
Created March 1, 2012 10:18
Content-Type enumerator
require 'net/http'
require 'rainbow'
url_list = File.open(ARGV[0], 'r').readlines
if url_list.nil?
puts "aiee: missing url list".color(:red)
end
url_list.each do |url|