Skip to content

Instantly share code, notes, and snippets.

I may be slow to respond.

Pau Pérez Fabregat sauloperez

I may be slow to respond.
View GitHub Profile
peterc / get_sizes.sql
Last active Mar 5, 2019
Get the size of different tables and other relations in a PostgreSQL database
View get_sizes.sql
schema_name, rel_name, table_size,
pg_size_pretty(table_size) AS size
nspname AS schema_name,
relname AS rel_name,
pg_table_size(pg_class.oid) AS table_size
FROM pg_class, pg_namespace
WHERE pg_class.relnamespace = pg_namespace.oid
mkllnk / post-receive
Created Jul 11, 2018
OFN Aus deployment script
View post-receive
set -e
# Set up Rails app. Run this script immediately after cloning the codebase.
# Exit if any subcommand fails
set -e
# Copy over configs
if ! [ -f .env ]; then
cp .sample.env .env

Ruby: ivar vs readers

Spoiler alert: Readers win.

  1. You don't rely on the instance state.
  2. You've better protection againt typos. @ivar might not exist and nothing will fail ivar will complain.
  3. They're easier to mock in specs in case you need to.
  4. They properly wrap the state so that refactors are easier
  5. they can be aliased
  6. they can be alias_method_chained
PurpleBooth /
Last active Nov 20, 2020
A template to make good

Project Title

One Paragraph of project description goes here

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.


caarlos0 / eq.or.higher.than.9.2.sql
Created Jun 3, 2014
PostgreSQL query monitoring (deadlocks and shit)
View eq.or.higher.than.9.2.sql
SELECT AS blocked_pid,
a.usename AS blocked_user,
ka.query AS blocking_statement,
now() - ka.query_start AS blocking_duration, AS blocking_pid,
ka.usename AS blocking_user,
a.query AS blocked_statement,
now() - a.query_start AS blocked_duration
FROM pg_catalog.pg_locks bl
JOIN pg_catalog.pg_stat_activity a ON =
mikestone14 / gist:11198630
Created Apr 23, 2014
Getting a GoDaddy domain to point to a Heroku app.
View gist:11198630
wandernauta / sp
Last active Nov 23, 2020
sp is a command-line client for Spotify's dbus interface. Play, pause, skip and search tracks from the comfort of your command line.
View sp
#!/usr/bin/env bash
# This is sp, the command-line Spotify controller. It talks to a running
# instance of the Spotify Linux client over dbus, providing an interface not
# unlike mpc.
# Put differently, it allows you to control Spotify without leaving the comfort
# of your command line, and without a custom client or Premium subscription.
troyk / pg_stat_statements
Created Jan 5, 2013
enable postgres pg_stat_statements
View pg_stat_statements
1) see re: increasing shmmax
2) add to postgresql.conf:
shared_preload_libraries = 'pg_stat_statements' # (change requires restart)
136 pg_stat_statements.max = 1000
137 pg_stat_statements.track = all
3) restart postgres
4) check it out in psql
mildmojo / left_join_arel_example.rb
Last active Nov 19, 2020
LEFT JOIN in ARel for ActiveRecord in Ruby on Rails
View left_join_arel_example.rb
# Here's a contrived example of a LEFT JOIN using ARel. This is an example of
# the mechanics, not a real-world use case.
# NOTE: In the gist comments, @ozydingo linked their general-purpose ActiveRecord
# extension that works for any named association. That's what I really wanted!
# Go use that! Go:
# - A Taxi is a car for hire. A taxi has_many :passengers.
# - A Passenger records one person riding in one taxi one time. It belongs_to :taxi.
You can’t perform that action at this time.