Skip to content

Instantly share code, notes, and snippets.

@pfigue
pfigue / psycopg2_cheatsheet.md
Last active October 12, 2023 00:43
psycopg2 Cheatsheet

Connect and Select

connect()

The shortest connect:

from psycopg2 import connect
psql_conn = connect("dbname=XXX user=XXX password=XXX host=localhost sslmode=require")
psql_conn.close()
@pfigue
pfigue / ubuntu_ppa_cheatsheet.md
Created February 9, 2015 14:39
Ubuntu PPA cheatsheet

Ubuntu PPA cheatsheet

Installing a new PPA

With this command:

sudo add-apt-repository ppa:<ppa_name>

which needs an extra software package:

  • On Ubuntu >=14.04: sudo apt-get install software-properties-common
@pfigue
pfigue / psql_cheatsheet.md
Last active August 29, 2015 14:15
PostgreSQL cheatsheet

Show active and idle connections grouped by state and client address for all the databases in the server:

SELECT count(datid), state, client_addr FROM pg_stat_activity group by state, client_addr;
@pfigue
pfigue / Dockerfile
Created January 27, 2015 15:50
Gitrob Docker Container
FROM phusion/baseimage:0.9.16
RUN apt-get update
RUN apt-get install -y ruby1.9.3 ruby-dev postgresql-9.3 postgresql-server-dev-9.3 make g++
RUN gem install bundler gitrob
RUN bash -c 'service postgresql start; sleep 5;' && sudo -u postgres psql -c "CREATE USER gitrob WITH PASSWORD 'gitrob';"
RUN bash -c 'service postgresql start; sleep 5;' && sudo -u postgres psql -c "CREATE DATABASE gitrob WITH OWNER gitrob;"
ADD gitrobrc.yml /root/.gitrobrc
EXPOSE 9393
CMD service postgresql start
@pfigue
pfigue / gist:fdc2064f7ca0f1342eef
Created October 1, 2014 11:11
Monitor PostgreSQL
psql -c "SELECT pg_is_in_recovery();" # true for standby, false for master
psql -c "SELECT txid_current_snapshot();"
psql -c "select pg_last_xlog_receive_location()" # from standby
psql -c "select pg_last_xlog_replay_location()" # from standby
psql -c "SELECT pg_current_xlog_location()" # from master
@pfigue
pfigue / rabbitmqctl_use_cases.md
Last active August 29, 2015 14:05
rabbitmqctl use cases

Show virtual hosts:

sudo rabbitmqctl list_vhosts

Show who is connected where:

sudo rabbitmqctl -n rabbit@node list_connections user vhost peer_host

Check credentials (requires management plugin enabled):

@pfigue
pfigue / parse_redis_info.py
Created August 14, 2014 16:17
Python script to parse the output Redis INFO command and convert it into a JSON dictionary.
#!/usr/bin env python
#coding: utf-8
import re
from json import dumps
from sys import (stdin, exit)
DEBUG_LEVEL = 0x0
PARSER = 0x01
# Installing fpm in Ubuntu 14.04
sudo apt-get install ruby-dev gcc build-essential # build-essential is for make
sudo gem install fpm
@pfigue
pfigue / gist:13c8e1c3dbd7256cb562
Last active August 29, 2015 14:05
Packaging Redis 3.0.0beta8 (Redis Cluster) via fpm
# Build requirements: wget, gcc, make, fpm, tcl (>=8.5)
SOURCE=https://github.com/antirez/redis/archive/3.0.0-beta8.tar.gz
VERSION=3.0.0beta8
ARCH=amd64
BUILD_DIR=/home/ubuntu/builder/
cd $BUILD_DIR
rm -rf redis-$VERSION
wget $SOURCE -O redis-$VERSION.tar.gz
@pfigue
pfigue / Puppetfile
Created July 10, 2014 21:26
Puppet Manifest - Install Oracle's Java 8.
forge "https://forgeapi.puppetlabs.com"
mod 'puppetlabs/apt', '1.5.1'