Skip to content

Instantly share code, notes, and snippets.

Linux forever

Maurizio De Santis mdesantis

Linux forever
  • Treatwell
  • Taranto, Italy
View GitHub Profile
mdesantis /
Last active August 29, 2015 13:56
web benchmark: appunti
mdesantis /
Created September 24, 2014 09:41
Keybase proof

Keybase proof

I hereby claim:

  • I am mdesantis on github.
  • I am mdesantis ( on keybase.
  • I have a public key whose fingerprint is F5F7 7045 0619 72C4 1130 5FD1 477C 5D30 1F85 13A9

To claim this, I am signing this object:

mdesantis / unique_constraint_handler.rb
Last active August 29, 2015 14:11
PostgreSQL unique constraint handler: it sets the record as invalid if a PostgreSQL unique constraint error is raised on record saving
View unique_constraint_handler.rb
# Usage example:
# class User < ActiveRecord::Base
# include UniqueConstraintHandler
# handle_unique_constraint_on :email
# end
# User.create email: ''
# user = User.create email: ''
# user.new_record? #=> true
mdesantis / gems_list_without_versions.rb
Created September 14, 2011 21:03
Displaying installed gems without version numbers - in one line =)
View gems_list_without_versions.rb
#!/usr/bin/env ruby
puts `gem list`.split("\n").map{ |gem_with_version| gem_with_version[/^.*?(?= )/] }.join("\n")
mdesantis / ligament.min.js
Created September 18, 2011 20:15
ligament.js - Minified version
View ligament.min.js
/* Copyright (C) 2011 by Yehuda Katz | MIT */
mdesantis / rails_3_template.rb
Created April 25, 2012 11:20
Rails 3 template (Postgres, RSpec, Capybara, Guard/Linux, Spork)
View rails_3_template.rb
#!/usr/bin/env ruby -w
# Rails 3 template (Postgres, RSpec, Capybara, Guard/libnotify4Linux, Spork)
# This should be used in this way:
# rails new APP_NAME -d postgresql -T --skip-bundle -m
# 1. Non-SSL source proposal (due to bundler bug)
if yes?("Do you want to use the non-SSL source of as gems source?")
# run %q(sed -i 's/https:\/\/\/\/' Gemfile)
mdesantis / rock_paper_scissors.rb
Created July 23, 2012 16:19
Circular comparison in Ruby
View rock_paper_scissors.rb
class RockPaperScissors
def, other_item)
new(item).compare other_item
def initialize(item)
mdesantis /
Last active December 16, 2015 08:19
Diff between package etc contents and current etc contents
# From this stackexchange question:
set -e
mkdir $package
cd $package
View rails_json_session.rb
# Hack to change the Rails cookie serializer from Marshal to JSON and therefore allow the session
# to be shared between different languages but also avoid that someone knowing the
# cookie secret key could execute arbitrary code on the server by unmarshalling
# modified Ruby code added to the session/permanent cookie.
# Note that all users will beed to login again since both the remember me cookie and the session cookies
# won't be valid. Note also that the remember me cookie is tested multiple times per request even when it fails.
# for performance reasons you might want to delete it if these extra cycles are too costly for you.
# Rails 4 (not tested on Rails 3).
View rails_json_cookie_session_store.rb