Skip to content

Instantly share code, notes, and snippets.

Avatar
🐧
Linux forever

Maurizio De Santis mdesantis

🐧
Linux forever
  • Treatwell
  • Taranto, Italy
View GitHub Profile
@mdesantis
mdesantis / ruby-2-3-install.sh
Created February 29, 2020 15:45
Install Ruby 2.3 on Ubuntu 19.10 using asdf (ruby-build)
View ruby-2-3-install.sh
#!/bin/bash
# It assumes [asdf](https://github.com/asdf-vm/asdf) to be installed
# and asdf plugin for Ruby to be added
set -exuo pipefail
sudo apt install libreadline-dev
wget https://www.openssl.org/source/old/1.0.2/openssl-1.0.2u.tar.gz
tar -xzf openssl-1.0.2u.tar.gz
@mdesantis
mdesantis / schedule.rb
Last active January 29, 2022 23:14
Schedule script for using Whenever toghether with rbenv
View schedule.rb
# Schedule script for using Whenever toghether with rbenv
#
# Whenever: https://github.com/javan/whenever
# rbenv: https://github.com/sstephenson/rbenv
set :env_path, '"$HOME/.rbenv/shims":"$HOME/.rbenv/bin"'
# doesn't need modifications
# job_type :command, ":task :output"
@mdesantis
mdesantis / upgrade-postgres-9.6-to-10.md
Last active October 11, 2021 08:11 — forked from delameko/upgrade-postgres-9.5-to-9.6.md
Upgrading PostgreSQL from 9.6 to 10 on Ubuntu 16.04
View upgrade-postgres-9.6-to-10.md

TL;DR

Install Postgres 10, and then:

sudo pg_dropcluster 10 main --stop
sudo pg_upgradecluster 9.6 main
sudo pg_dropcluster 9.6 main
@mdesantis
mdesantis / index.ts
Last active July 30, 2021 15:40
TypeScript: function that extends an object with a dynamic key
View index.ts
// TS Playground link: https://tsplay.dev/wRJl5w
interface Props {
baseKey: string
}
const withCustomKey = <K extends string>(customKey: K) => {
return <P>(props: P): P & { [k in K]: boolean } => {
return { ...props, [customKey]: true } as P & { [k in K]: boolean }
}
View steam-system-info.txt
Computer Information:
Manufacturer: Unknown
Model: Unknown
Form Factor: Desktop
No Touch Input Detected
Processor Information:
CPU Vendor: GenuineIntel
CPU Brand: Intel(R) Core(TM) i7-2600K CPU @ 3.40GHz
CPU Family: 0x6
@mdesantis
mdesantis / unicorn.rake
Last active January 9, 2021 20:03
Rails tasks for managing unicorn server instances
View unicorn.rake
# Tasks for managing Unicorn instances of a Rails application.
# Compatible with Ruby >= 1.9.2 and Rails >= 2 .
# Unicorn signals: http://unicorn.bogomips.org/SIGNALS.html
namespace :unicorn do
class UnicornPIDError < StandardError; end
def rails_env
Rails.env
@mdesantis
mdesantis / .Xmodmap
Created November 26, 2011 17:58
Solving swapped keys ( <> key is wapped with \| key ) of the italian Apple Keyboard on Ubuntu (from the thread http://forum.ubuntu-it.org/index.php/topic,383892.msg3872344.html )
View .Xmodmap
! Direttive per mappare correttamente la tastiera Apple italiana su Ubuntu,
! cioè, correggere lo scambio dei tasti maggiore/minore con quello di backslash/pipe
!
! 49: codice del tasto maggiore/minore ( <> ) (situato a destra del tasto L-SHIFT)
! 94: codice del tasto backslash/pipe ( \| ) (collocato a sinistra del tasto `uno/punto esclamativo` ( 1! ) )
!
!
! I comandi scritti sotto, eseguiti da terminale sono:
! xmodmap -e "keycode 49 = less greater guillemotleft guillemotright guillemotleft guillemotright" && \
! xmodmap -e "keycode 94 = backslash bar notsign brokenbar notsign brokenbar"
@mdesantis
mdesantis / heroku-bypass-5000.sh
Created September 5, 2014 14:53
Bypass Heroku connection on 5000 port (useful for troubled networks, such as italian ISP Fastweb)
View heroku-bypass-5000.sh
#!/bin/bash
echo 127.0.0.1 rendezvous-eu-west-1-a.runtime.heroku.com >> /etc/hosts
ssh -L 5000:rendezvous-eu-west-1-a.runtime.heroku.com:5000 remoteuser@remoteserver
@mdesantis
mdesantis / postgresql_like_index.rb
Last active July 23, 2020 09:31
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)
SQL
@mdesantis
mdesantis / sidekiq-reset.rb
Created April 24, 2020 15:37
Sidekiq reset one-liner
View sidekiq-reset.rb
require 'sidekiq/api'; [Sidekiq::RetrySet.new, Sidekiq::ScheduledSet.new, Sidekiq::DeadSet.new, Sidekiq::Stats.new.queues].each(&:clear); Sidekiq::Stats.new.reset