Skip to content

Instantly share code, notes, and snippets.

View mdesantis's full-sized avatar
🐧
Linux forever

Maurizio De Santis mdesantis

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

Keybase proof

I hereby claim:

  • I am mdesantis on github.
  • I am mdesantis (https://keybase.io/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
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
# Usage example:
#
# class User < ActiveRecord::Base
# include UniqueConstraintHandler
# handle_unique_constraint_on :email
# end
#
# User.create email: 'test@example.com'
# user = User.create email: 'test@example.com'
# user.new_record? #=> true
@mdesantis
mdesantis / gems_list_without_versions.rb
Created September 14, 2011 21:03
Displaying installed gems without version numbers - in one line =)
#!/usr/bin/env ruby
puts `gem list`.split("\n").map{ |gem_with_version| gem_with_version[/^.*?(?= )/] }.join("\n")
@mdesantis
mdesantis / ligament.min.js
Created September 18, 2011 20:15
ligament.js - Minified version
/* Copyright (C) 2011 by Yehuda Katz | MIT */
M={},V={},C={};
@mdesantis
mdesantis / rails_3_template.rb
Created April 25, 2012 11:20
Rails 3 template (Postgres, RSpec, Capybara, Guard/Linux, Spork)
#!/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 https://raw.github.com/gist/2489048/rails_3_template.rb
# 1. Non-SSL source proposal (due to bundler bug)
if yes?("Do you want to use the non-SSL source of rubygems.org as gems source?")
# run %q(sed -i 's/https:\/\/rubygems.org/http:\/\/rubygems.org/' Gemfile)
@mdesantis
mdesantis / rock_paper_scissors.rb
Created July 23, 2012 16:19
Circular comparison in Ruby
class RockPaperScissors
ITEMS = %W(A P B N)
def self.compare(item, other_item)
new(item).compare other_item
end
def initialize(item)
@mdesantis
mdesantis / etc_deb_diff.sh
Last active December 16, 2015 08:19
Diff between package etc contents and current etc contents
#!/bin/bash
# From this stackexchange question: http://unix.stackexchange.com/questions/72746
set -e
package=php5-fpm
mkdir $package
cd $package
# 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).