Skip to content

Instantly share code, notes, and snippets.

Linux forever

Maurizio De Santis mdesantis

Linux forever
  • Treatwell
  • Taranto, Italy
View GitHub Profile
View gist:214982b377e94020980347eaf21b8efc
> rails -v
Rails 5.1.0.rc1
> rails new rails_vue --webpack=vue
create Rakefile
create .gitignore
create Gemfile
run git init from "."
mdesantis / unique_constraint_handler.rb
Last active Aug 29, 2015
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

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 /
Created Sep 5, 2014
Bypass Heroku connection on 5000 port (useful for troubled networks, such as italian ISP Fastweb)
echo >> /etc/hosts
ssh -L remoteuser@remoteserver
mdesantis /
Last active Aug 29, 2015
web benchmark: appunti
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
mdesantis /
Last active Dec 16, 2015
Diff between package etc contents and current etc contents
# From this stackexchange question:
set -e
mkdir $package
cd $package
mdesantis / schedule.rb
Last active Jan 29, 2022
Schedule script for using Whenever toghether with rbenv
View schedule.rb
# Schedule script for using Whenever toghether with rbenv
# Whenever:
# rbenv:
set :env_path, '"$HOME/.rbenv/shims":"$HOME/.rbenv/bin"'
# doesn't need modifications
# job_type :command, ":task :output"
mdesantis /
Last active Jul 2, 2018
Delayed Job init script; it uses start-stop-daemon and supports every Ruby version manager (RVM, rbenv, chruby...)
# Provides: delayed_job
# Required-Start: $all
# Required-Stop: $local_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the delayed_job instances
# Description: starts the delayed_job server instances using start-stop-daemon