Skip to content

Instantly share code, notes, and snippets.

View nicolaracco's full-sized avatar

Nicola Racco nicolaracco

  • Calco, LC - Italy
View GitHub Profile
@nicolaracco
nicolaracco / god
Created February 14, 2014 15:35
GOD init script for RHEL
#!/bin/bash
#
# God under multi-user RVM
#
# http://god.rubyforge.org
# http://beginrescueend.com/integration/god/
#
# chkconfig: - 85 15
# description: Control the God gem. Expects the gem to \
# to be installed under a multi-user RVM \

Keybase proof

I hereby claim:

  • I am nicolaracco on github.
  • I am gawaine (https://keybase.io/gawaine) on keybase.
  • I have a public key whose fingerprint is 393F 9DE5 851F E42B F7EC D433 FBF3 A259 E8B8 532B

To claim this, I am signing this object:

diff --git a/akamai_api.gemspec b/akamai_api.gemspec
index 36d81ee..b5eea39 100644
--- a/akamai_api.gemspec
+++ b/akamai_api.gemspec
@@ -18,7 +18,6 @@ Gem::Specification.new do |gem|
gem.required_ruby_version = Gem::Requirement.new(">= 1.9.2")
gem.add_dependency 'httparty', '~> 0.13.1'
- gem.add_dependency 'activesupport', '>= 2.3.9', '< 5.0'
gem.add_dependency 'thor', '>= 0.14.0', '< 2.0'
# Original code: https://github.com/baxter/csterrain/blob/master/src/generate_terrain.coffee
#
#
# Generate realistic looking terrain using the [diamond square algorithm](http://en.wikipedia.org/wiki/Diamond-square_algorithm).
#
#### Generating a height map
# The height map is basically an array of numbers, each element represents
# a point on a map and each number represents the height of that grid.
class @HeightMap
@nicolaracco
nicolaracco / Vagrantfile
Created January 14, 2015 10:36
Vagrantfile for boot2docker setup
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
cwd = File.expand_path '../', __FILE__
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
#config.vm.define "#{ENV['VAGRANT_DEFAULT_PROVIDER']}_boot2docker"
config.vm.box = "yungsang/boot2docker"
@nicolaracco
nicolaracco / model.rb
Created March 4, 2015 10:47
has_one through setter
class User < ActiveRecord::Base
has_many :memberships, inverse_of: :user
end
# ha anche il flag owner
class Membership < ActiveRecord::Base
belongs_to :user, inverse_of: :memberships
belongs_to :group, inverse_of: :memberships
end
@nicolaracco
nicolaracco / parser.rb
Created April 15, 2015 09:41
example of a tokenizer and a parser (very basic, even operator precedence is absent)
class Parser
def parse expression
tokenizer = Tokenizer.new expression
first_value = read_next_number tokenizer
while tokenizer.look_next_token
operator = read_next_operator tokenizer
second_value = read_next_number tokenizer
first_value = operate(first_value, operator, second_value)
end
first_value
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