Skip to content

Instantly share code, notes, and snippets.

Linux forever

Maurizio De Santis mdesantis

Linux forever
View GitHub Profile
mdesantis / sidekiq-reset.rb
Created Apr 24, 2020
Sidekiq reset one-liner
View sidekiq-reset.rb
require 'sidekiq/api'; [,,,].each(&:clear);
mdesantis / postgresql_like_index.rb
Last active Jul 23, 2020
Rails migration adding PostgreSQL index for LIKE when the pattern is both left-anchored and right-anchored
View postgresql_like_index.rb
# It supports queries like:
# ModelName.where(ModelName.arel_table[:columnname].lower.matches 'searchterm')
class PostgresqlLikeIIndex < ActiveRecord::Migration
def up
enable_extension 'pg_trgm'
execute <<~SQL
CREATE INDEX index_tablename_on_columnname_lower
ON tablename USING gin (lower(columnname) gin_trgm_ops)
mdesantis /
Created Feb 29, 2020
Install Ruby 2.3 on Ubuntu 19.10 using asdf (ruby-build)
# It assumes [asdf]( to be installed
# and asdf plugin for Ruby to be added
set -exuo pipefail
sudo apt install libreadline-dev
tar -xzf openssl-1.0.2u.tar.gz
mdesantis /
Last active Sep 26, 2018
GNU Guix v0.15.0 installer, non interactive version (suitable for Docker; modified from
# GNU Guix --- Functional package management for GNU
# Copyright © 2017 sharlatan <>
# Copyright © 2018 Ricardo Wurmus <>
# Copyright © 2018 Efraim Flashner <>
# This file is part of GNU Guix.
# GNU Guix is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
View tsung.xml
<?xml version="1.0"?>
<!DOCTYPE tsung SYSTEM "/usr/share/tsung/tsung-1.0.dtd" [] >
<tsung loglevel="info">
<client host="localhost" use_controller_vm="true" maxusers="60000"/>
<server host="localhost" port="3334" type="tcp"></server>
mdesantis /
Created Dec 21, 2017
Sir Trevor initializer for Rails
$(document).on 'ready turbolinks:load', ->
SirTrevor.config.language = 'it'
language: 'it'
focusOnInit: false
blockTypes: ['Text', 'Image', 'List', 'Heading', 'Quote', 'Video']
defaultType: 'Text'
iconUrl: "<%= asset_path('sir-trevor/build/sir-trevor-icons.svg') %>"
uploadUrl: "/admin/uploads/images"
mdesantis /
Last active Aug 17, 2020 — forked from delameko/
Upgrading PostgreSQL from 9.6 to 10 on Ubuntu 16.04


Install Postgres 10, and then:

sudo pg_dropcluster 10 main --stop
sudo pg_upgradecluster 9.6 main
sudo pg_dropcluster 9.6 main
View asd.rb
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
gemfile(true) do
source ""
# Activate the gem you are reporting the issue against.
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