Skip to content

Instantly share code, notes, and snippets.

View kirang89's full-sized avatar

Kiran Gangadharan kirang89

View GitHub Profile
@kirang89
kirang89 / pg_cheatsheet.md
Last active August 29, 2015 14:00
Postgres commands cheatsheet

##Postgres commands cheatsheet

#####Setup data directory for database

initdb -D /usr/local/pgsql/data

#####Reload Postgres config from command line:

select pg_reload_conf();

@kirang89
kirang89 / model_relation_ex.py
Created April 7, 2014 18:59
Example for many-to-many relationship with extra columns in SQLAlchemy
import sqlalchemy
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, String, ForeignKey
from sqlalchemy.orm import sessionmaker, relationship
engine = sqlalchemy.create_engine('sqlite:///:memory:')
Base = declarative_base()
@kirang89
kirang89 / models_json_serialization.py
Last active April 25, 2021 04:41
JSON Serialization of SQLAlchemy Models
import sqlalchemy
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, String
from sqlalchemy.orm import sessionmaker, relationship, backref
import uuid
import json
engine = sqlalchemy.create_engine('sqlite:///:memory:', echo=True)
Base = declarative_base()
@kirang89
kirang89 / bitshiftperf.txt
Created November 20, 2013 04:59
The advantage in speed when using bit shifting
[kiran@Kirans-MacBook-Pro:~]
% python -m timeit 'x = 1 << 100000'
10000000 loops, best of 3: 0.0278 usec per loop
[kiran@Kirans-MacBook-Pro:~]
% python -m timeit 'x = pow(2,100000)'
1000 loops, best of 3: 334 usec per loop
@kirang89
kirang89 / checklist.md
Created November 5, 2013 16:39
Code review checklist

General

  • Standards/Conventions: Make sure that code follows the appropriate standards/conventions (ex: PEP8 for Python).
  • Appropriate names: Make sure that variables, arguments, functions, modules and packages are named appropriately.
  • Valid arguments: Make sure that all method arguments are valid ones.
  • Single responsibility: Make sure that every function/method used has a single responsibility.
  • Disposable Resources: Make sure that temporary resources are terminated after their use (ex: opening a file to read content).
  • Security: Make sure no critical data or sensitive information is exposed in any way to the public. This involves both client-side as well as the server-side code (ex: storing a raw password to db)

.......

@kirang89
kirang89 / remote_db_connector.py
Last active November 29, 2024 13:28
Connect to a remote mysql database using Python and MySQLdb
#!/usr/bin/env python
# -*- coding: utf-8 -*-
############################################################
# #
# Simple script to connect to a remote mysql database #
# #
# #
# Install MySQLdb package by running: #
# #
@kirang89
kirang89 / animorphs-downloader.py
Last active January 5, 2024 14:15
Script to download single book or the entire series of Animorphs. Relive your childhood !
#!/usr/bin/env python
# -*- coding: utf-8 -*-
################################################
# #
# Script to download entire animorphs series #
# #
# Usage: python animorphs-downloader.py --help #
# #
#################################################
@kirang89
kirang89 / split_and_commit.md
Created October 2, 2013 18:35
Splitting a single commit into several others, for the sake of clarity.
git checkout fix
git reset HEAD^
git checkout -b fix-1
git add -p
git commit
git stash
git checkout -b fix-1
git stash pop
git commit -a