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 / nodejs-latest-lts-version.sh
Last active December 2, 2023 15:58
Get Node.js latest LTS version via CLI
#!/usr/bin/env bash
set -o errexit
set -o pipefail
set -o nounset
# Requirememnts:
# - curl
# - jq
# - cut
@mdesantis
mdesantis / index.ts
Last active July 30, 2021 15:40
TypeScript: function that extends an object with a dynamic key
// 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 }
}
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 / sidekiq-reset.rb
Created April 24, 2020 15:37
Sidekiq reset one-liner
require 'sidekiq/api'; [Sidekiq::RetrySet.new, Sidekiq::ScheduledSet.new, Sidekiq::DeadSet.new, Sidekiq::Stats.new.queues].each(&:clear); Sidekiq::Stats.new.reset
@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
# 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 / ruby-2-3-install.sh
Created February 29, 2020 15:45
Install Ruby 2.3 on Ubuntu 19.10 using asdf (ruby-build)
#!/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 / guix-install.sh
Last active September 26, 2018 17:06
GNU Guix v0.15.0 installer, non interactive version (suitable for Docker; modified from https://git.savannah.gnu.org/cgit/guix.git/plain/etc/guix-install.sh?h=v0.15.0)
#!/bin/bash
# GNU Guix --- Functional package management for GNU
# Copyright © 2017 sharlatan <sharlatanus@gmail.com>
# Copyright © 2018 Ricardo Wurmus <rekado@elephly.net>
# Copyright © 2018 Efraim Flashner <efraim@flashner.co.il>
#
# 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
<?xml version="1.0"?>
<!DOCTYPE tsung SYSTEM "/usr/share/tsung/tsung-1.0.dtd" [] >
<tsung loglevel="info">
<clients>
<client host="localhost" use_controller_vm="true" maxusers="60000"/>
</clients>
<servers>
<server host="localhost" port="3334" type="tcp"></server>
</servers>
@mdesantis
mdesantis / sir-trevor.coffee.erb
Created December 21, 2017 13:35
Sir Trevor initializer for Rails
$(document).on 'ready turbolinks:load', ->
SirTrevor.config.language = 'it'
SirTrevor.setDefaults(
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
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

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