Skip to content

Instantly share code, notes, and snippets.

View inouire's full-sized avatar
⛑️
Deploying every day

Edouard inouire

⛑️
Deploying every day
View GitHub Profile
@inouire
inouire / gist:ba850551fd352238579d
Created December 9, 2014 08:57
CSV dataset provider, draft
<?php
namespace MetarDecoder\Service;
use MetarDecoder\Exception\DatasetLoadingException;
class DatasetProvider
{
private $base_dir;
@inouire
inouire / i18n.rb
Last active May 20, 2019 10:44
Simple i18n setup in my Hanami 1.3 app
# config/initializers/i18n.rb
require 'i18n'
# Configure it as you want
I18n.load_path = Dir["config/locales/**.yml"]
I18n.enforce_available_locales = true
I18n.default_locale = "en"
I18n.backend.load_translations

Ruby heap size rules of thumb

GC.stat[:heap_live_slots]
  • <1 million = don't sweat it
  • 1mil->3mil = Pretty average
  • 3mil->5mil = Typical of Big Chonker Monoliths
  • 5mil->10mil = Something probably wrong, fix to reduce RSS usage + speed up your GCs

List all tables referencing a target table using a foreign key

SELECT tc.table_schema, tc.constraint_name, tc.table_name, kcu.column_name, ccu.table_name
AS foreign_table_name, ccu.column_name AS foreign_column_name
FROM information_schema.table_constraints tc
JOIN information_schema.key_column_usage kcu ON tc.constraint_name = kcu.constraint_name
JOIN information_schema.constraint_column_usage ccu ON ccu.constraint_name = tc.constraint_name
WHERE constraint_type = 'FOREIGN KEY'
AND ccu.table_name='name_of_your_target_table_here'

Limit disk space used by Git

Short on disk space ? Using Git?

$ git fetch --all --prune
$ du -sh .git && git gc --aggressive && du -sh .git
13M     .git
Enumerating […]
6.5M .git
@inouire
inouire / kill_long_running_queries.sql
Created October 20, 2022 14:16
Postgres find and kill long running queries
SELECT
pid,
now() - pg_stat_activity.query_start AS duration,
query,
state
FROM pg_stat_activity
WHERE (now() - pg_stat_activity.query_start) > interval '5 minutes';
SELECT pg_cancel_backend(__pid__);
@inouire
inouire / locate_gem_source_code.sh
Last active April 21, 2023 07:54
Locate where gem source code is stored
$ bundle show nokogiri
/home/edouard/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/nokogiri-1.13.8-x86_64-linux
@inouire
inouire / git_go_back_in_time.md
Last active April 21, 2023 08:13
Go back in time with git

Pick a date, pick a branch, here you go

git checkout `git rev-list -n 1 --first-parent --before="2019-07-27 13:37" master`
@inouire
inouire / investigate_ruby_requires.rb
Last active July 20, 2023 10:28
A simple way to have a rough idea of where the time is spent for Ruby require
$requires_index = {}
if true
# Override the require method to track load times
def custom_require(file)
starting = Process.clock_gettime(Process::CLOCK_MONOTONIC)
result = original_require(file)
ending = Process.clock_gettime(Process::CLOCK_MONOTONIC)
@inouire
inouire / gist:e94128151c8a4c541237a1ad3b85184d
Created August 8, 2023 11:53
Disable trackpoint on Toshiba portégé
xinput # to list devices
alias trackpadoff="xinput disable \"AlpsPS/2 ALPS DualPoint Stick\""
alias trackpadon="xinput enable \"AlpsPS/2 ALPS DualPoint Stick\""