Skip to content

Instantly share code, notes, and snippets.

@rjdp
rjdp / a.py
Created December 7, 2015 11:54
test
print("hello")
@rjdp
rjdp / tenant_schemas.diff
Created January 6, 2017 22:15
incase using tenant_schemas 1.5.2 with django1.5.x use this diff to patch to tenant_schemas
diff --git a/postgresql_backend/introspection.py b/postgresql_backend/introspection.py
index a856d26..d030edb 100644
--- a/postgresql_backend/introspection.py
+++ b/postgresql_backend/introspection.py
@@ -11,4 +11,5 @@ class DatabaseSchemaIntrospection(DatabaseIntrospection):
WHERE c.relkind IN ('r', 'v', '')
AND n.nspname = '%s'
AND pg_catalog.pg_table_is_visible(c.oid)""" % self.connection.schema_name)
- return [row[0] for row in cursor.fetchall() if row[0] not in self.ignored_tables]
+ #return [row[0] for row in cursor.fetchall() if row[0] not in self.ignored_tables]
@rjdp
rjdp / backup.sh
Created January 14, 2017 07:30
dump each db postgres
#!/bin/bash
echo "PostgreSQL"
export PGPASSWORD="postgre password here"
DBLIST=`psql -U postgres -d postgres -q -t -c 'SELECT datname from pg_database'`
for d in $DBLIST
do
echo "Dumping $d";
pg_dump -U postgres $d > /path/to/dump/directory/$d.postgres.sql
done
#! /home/blackmonk15/.virtualenv/bm/bin/python
import os, sys, re
from os import listdir
import time
import subprocess
from datetime import datetime
from optparse import OptionParser
BCKP_DIR = "/home/blackmonk15/alldbbckp"
@rjdp
rjdp / AWS - EC2 - Change PEM Key
Created January 29, 2017 10:54
AWS - EC2 - Change PEM Key
1. From the AWS EC2 Console go to "Key Pairs" and generate a new key pair (eg: NewKey.pem); Download the generated pem key, and chmod it to 0666
2. Use the new pem key to generate a public key
$ ssh-keygen -y
When prompted, enter the path to NewKey.pem. This will generate NewKey.pub
Tip: Edit NewKey.pub and append the key's name so you can identify it easier in the next steps.
Just append a single space, then a tag/name for the key
# dump specific postgres schemas from database `mydb`
pg_dump -U postgres -nschema1 -npublic -npg_catalog -npg_toast -ninformation_schema -Fc mydb > mydb.dump
# after restoring above data move the table from the original schema to public schema
DO
$$
DECLARE
row record;
BEGIN
@rjdp
rjdp / rofi issue
Created August 25, 2017 01:01
Rofi Issue
rofi usage:
rofi [-options ...]
Command line only options:
-no-config Do not load configuration, use default values.
-v,-version Print the version number and exit.
-dmenu Start in dmenu mode.
-display [string] X server to contact.
${DISPLAY}
-h,-help This help message.
@rjdp
rjdp / s3.vcl
Created October 27, 2017 10:35 — forked from rezan/s3.vcl
Varnish AWS S3 Gateway VCL
#
# Varnish AWS S3 Gateway VCL
#
# Allows global read (GET, HEAD) and ACL protected writes (POST, PUT, DELETE).
# When writing, pass in Content-Type and Content-MD5, both are optional.
#
# Params:
#
# %BUCKET% - S3 bucket name, S3 host may be regional
# %ACCESS_ID% - IAM access ID for bucket
@rjdp
rjdp / irc.md
Created November 7, 2017 08:50 — forked from xero/irc.md
irc cheat sheet

#IRC Reference

Not intended as a guide for newbies, more like a "cheat sheet" for the somewhat experienced IRC user, especially one who wields some power over a channel.

##The Basics

  • /join #channel
    • Joins the specified channel.
  • /part #channel
    • Leaves the specified channel.
@rjdp
rjdp / update_schemas.sql
Created April 18, 2018 13:42
Loop over schemas in a Postgresql database and execute arbitrary DDL example
DO
$$
DECLARE
schemaname name;
BEGIN
FOR schemaname IN SELECT nspname FROM pg_namespace WHERE nspname LIKE 'schema_%' AND nspname <> 'information_schema' LOOP
RAISE NOTICE 'Running Alter on Schema : %', schemaname;
EXECUTE format('ALTER TABLE %I.common_commonconfigure ADD COLUMN google_secret_key varchar(150);', schemaname);
END LOOP;
END;