Skip to content

Instantly share code, notes, and snippets.

View sandro's full-sized avatar
☀️
Sharing Goodness

Sandro Turriate sandro

☀️
Sharing Goodness
View GitHub Profile
@sandro
sandro / gist:16721
Created October 14, 2008 14:48
change error message name for fields
class User
validates_presence_of :terms_accepted, :message => 'must be accepted'
protected
HUMANIZED_ATTRIBUTES = {
:terms_accepted => 'Terms and Conditions'
}
def self.human_attribute_name(attr)
@sandro
sandro / .vimrc
Created November 17, 2008 15:27
my vimrc with some help from the aedit plugin and tpope
set ai ts=2 sts=2 et sw=2
set autoread
set background=light
set complete-=i " Searching includes can be slow
set dictionary+=/usr/share/dict/words
set display=lastline
set ff=unix
set hidden
set listchars=tab:>\ ,trail:-
set listchars+=extends:>,precedes:<
@sandro
sandro / load jquery from google.js
Created December 31, 2008 20:55
load jquery from google
(function(){s=document.createElement('script');s.type='text/javascript';s.src='http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js';document.body.appendChild(s);})();
// remember to run jQuery.noConflict() as necessary.
class C
def self.hi
puts 'hi'
end
end
class A
def self.inherited(sub)
eval("::#{sub} = Class.new(C)")
end
require 'rubygems'
require 'httparty'
module HttpConfig
def self.included(base)
base.send :include, HTTParty
base.base_uri 'http://192.168.3.218:8888/bridge/JSONControllerServlet.do'
base.format :json
end
class A
def self.say(msg)
puts "Hello from A #{msg}"
end
end
class B < A
def self.say(msg)
if msg.empty?
super
@sandro
sandro / capture_parent_method.rb
Created January 26, 2009 22:32
capture inherited method before redefining it
class A
def self.hi
'hi from A'
end
end
class B < A
class << self
alias_method :b, :hi
end
@sandro
sandro / load_jquery_with_callback.js
Created January 29, 2009 04:51
load jquery with callback
function load_jquery(){
var s=document.createElement('script');
s.type='text/javascript';
s.src='http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js';
var head = document.getElementsByTagName("head")[0];
var done = false;
s.onload = s.onreadystatechange = function(){
if ( !done && (!this.readyState ||
this.readyState == "loaded" || this.readyState == "complete") ) {
@sandro
sandro / bookmarklet_template.js
Created January 29, 2009 05:01
bookmarklet template
// TODO: remove spaces and newlines
javascript:(function(){
s=document.createElement('script');
s.type='text/javascript';
s.src='http://example.com/bookmarklet.js';
document.body.appendChild(s);
})();
// TODO: bookmarklet code needs to be in an anchor tag
// <a href="javascript:(function(){s=document.createElement('script');s.type='text/javascript';s.src='http://example.com/bookmarklet.js';document.body.appendChild(s);})();">My Bookmarklet</a>
Factory.define :administrator_base, :class => Administrator do |a|
a.password 'abc123'
a.password_confirmation 'abc123'
a.security_question_id 1
a.security_question_answer 'xxxxxx'
a.activated_at Time.now
a.state 'active'
end
Factory.define :administrator do |a|