Skip to content

Instantly share code, notes, and snippets.

View sravi4701's full-sized avatar
🏠
Working from home

Ravi Shankar sravi4701

🏠
Working from home
  • Bengaluru
View GitHub Profile
import sys
from fabric import Connection, task
from invoke import Responder
from fabric.config import Config
PROJECT_NAME = "project_name"
PROJECT_PATH = "~/{}".format(PROJECT_NAME)
REPO_URL = "remote_repo_url"
def get_connection(ctx):

Postgres Cheatsheet

This is a collection of the most common commands I run while administering Postgres databases. The variables shown between the open and closed tags, "<" and ">", should be replaced with a name you choose. Postgres has multiple shortcut functions, starting with a forward slash, "". Any SQL command that is not a shortcut, must end with a semicolon, ";". You can use the keyboard UP and DOWN keys to scroll the history of previous commands you've run.

Setup

installation, Ubuntu

http://www.postgresql.org/download/linux/ubuntu/ https://help.ubuntu.com/community/PostgreSQL

@sravi4701
sravi4701 / postgres-cheatsheet.md
Created March 27, 2018 21:30 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)
@sravi4701
sravi4701 / unpacking_arbitrary.py
Created February 23, 2018 23:46
Unpacking elements from iterables of arbitrary length
grades = [5, 6, 7, 8, 9]
first, *middle, last = grades
print(first) # 5
print(last) # 9
print(middle) # [6, 7, 8]
# The variable associated with * will always be a list
# We also can't use two * expression like:
@sravi4701
sravi4701 / unpacking_sequence.py
Created February 23, 2018 23:21
Unpacking a sequence into separate variables
# comma_separated_variables = sequence
# given a data in the form of list
data = ['Ravi', 21, (1996, 12, 5)]
# extract name, age, dob from data
name, age, dob = data
print(name) # Ravi
print(age) # 21