Skip to content

Instantly share code, notes, and snippets.

View nicolaracco's full-sized avatar

Nicola Racco nicolaracco

  • Calco, LC - Italy
View GitHub Profile
module Mongoid
module Localizable
class LocalizedValidator < ActiveModel::EachValidator
def validate_each record, attribute, value
if options[:mode] == :only_default
record.errors[:attribute] << (options[:message] || :blank) unless record.send("has_#{attribute}_translation?", I18n.default_locale)
end
end
end
end
class Model
include Mongoid::Document
include Mongoid::Timestamps
include Mongoid::Localizable
localized_field :name
validates_default_locale :name
end
#
@nicolaracco
nicolaracco / my_accessors.rb
Created November 16, 2010 08:43
Demo of ruby dynamic method/variable creation
require 'rubygems'
require 'active_support'
# Include this module to define additional helpers
module MyAccessors
extend ActiveSupport::Concern
module ClassMethods
# This helper creates accessors
def create_my_accessors *names
class Carta {
private static enum Seme { Oro, Bastoni, Coppe, Spade }
private int value;
private Seme seme;
public Carta(int value, Seme seme) { this.value = value; this.seme = seme; }
public int getValue() { return int; }
public Seme getSeme() { return seme; }
}
function testWithoutParentheses() {
var start = new Date();
var end;
var a = 0;
for (var i = 0; i < 1000000000; i++)
if (i % 2 == 0)
a++;
end = new Date();
return end-start;
}
@nicolaracco
nicolaracco / refactoring.coffee
Created October 21, 2011 13:27
bindEvents refactoring
Class Product
options: ['size', 'fitting', 'last']
constructor: (@availabilities) ->
@bindEvents()
bindEvents: ->
for option in @options
callback = _(@optionClickHandler).bind @, option
@container(option).find('a').click callback
#using excel
ExcelFile::Sheet.defile :game_of_thrones_episodes do
#dunno @ the moment
end
ExcelFile::Row.define :episode_row do
attribute :name
attribute :index
attribute :description
require 'mina/bundler'
require 'mina/rails'
require 'mina/git'
require 'mina/rvm'
set :domain, 'server.ovofarm.com'
set :user, 'user'
set :forward_agent, true
set :deploy_to, '/var/apps/studioinnovo'
set :repository, 'ssh://[email protected]/gawaine/studioinnovo.git'
# app.coffee
require 'express'
class Server
constructor: ->
@app = express()
@server = http.createServer(@app)
@io = SocketIO.listen @server, logger: @logger
@configure_app()
# app.coffee
require 'express'
class Server
constructor: ->
@app = express()
@server = http.createServer(@app)
@io = SocketIO.listen @server, logger: @logger
@configure_app()