Skip to main content

Posts

Showing posts from 2016

Useful, but rarely used git commands

Some useful, but rarely used and hence easy to forget git commands. Recording these here as a note to myself.

PurposeCommandDelete a Remote Taggit push --delete origin <tagname>Filenames diff between two commitsgit diff commit commit2 --statList all tags, sorted by name, in reversegit tag -l --sort="-v:refname"

How to Create a Random String

Random strings are used everywhere in computing -- mostly as keys for cryptographic signing sensitive data. So how does one go about creating one?

My first thinking was to use Python code and its random library. I came up with this

import string import random def gen_random_string(length=32, charset=string.printable): ''' A function to generate a string of specified length composed of random characters. The characters with which the string is composed can be customized thru the second parameter. Parameters: length - int, length of the string. Defaults to 32. charset - array of characters from which the letters to compose the string are randomly chosen. Defaults to string.printable Returns: string Raises: None ''' num_chars = len(charset) random_string = '' random.seed() for i in range(0, length): random_string += charset[random.randint(0, num_char…

Script to Create Secure Django Site Deployment Environment

My first production level shell script is out. Yes, after two decades spent in the depths of code, I have finally published a shell script that is worthy of being called 'code'.

It's something that started as a few lines hack to update a Linux box with a series of packages that needed to be installed to deploy a Django web app that eventually grew to 300+ lines of madness (I can't find anything else to describe shell scripting language) that I have used to create consistent configuration across a few servers.

Without much ado, here it is: https://github.com/harikvpy/deploy-django.git.

Script to Create Secure Django Site Deployment Environment

My first production level shell script is out. Yes, after two decades spent in the depths of code, I have finally published a shell script that is worthy of being called 'code'.

It's something that started as a few lines hack to update a Linux box with a series of packages that needed to be installed to deploy a Django web app that eventually grew to 300+ lines of madness (I can't find anything else to describe shell scripting language) that I have since used to create consistent configuration across a few servers and apps.

Without much ado, here it is: https://github.com/harikvpy/deploy-django.git.

Token Based Authentication in a Cordova App

Any web based service that provides a mobile client requires some form of authentication before the user can access their permitted resources. The simplest approach is to require the user to enter their username and password for every session (or after the session expires). Simple to implement, but not the most friendly approach. User’s are notorious for forgetting their login credentials more so now than ever as more and more services require login ids and their own passwords.

A better approach is to use token based authentication whereby user is issued a signed token that they can then use to access their data from the online service. This introduces its own security challenges but this can be mitigated quite nicely with proper server side measures such as serving your entire site in HTTPS only. Of course, token based approach requires that your back-end implements an API that is suitably protected and accessible only through authenticated clients. But that’s a given and I’m not go…

How to setup PostgreSQL on Linux for Django

First step is to install PostgreSQL on Ubuntu. In its default installation, Ubuntu does not included PostgreSQL. So uou have to install it separately.
sudo apt-get install postgresql Now install the python module for accessing PostgreSQL -- psycopg2. You have two choices here -- either install this from the OS package manager or manually using pip. Which approach to choose depends on your python development environment.

i. If you're using the system python as development environment, you may install psycopg2 from the OS package manager. You can do this by
$ sudo apt-get install python-psycopg2
ii. However, if your python development environment is based on a virtual environment, the above approach will not work. This is because the above installs psycopg2 on the system python dist-packages, which does not copied into the virtual environment when it's created. This is the behavior even if the package is installed before the virtual environment is created. So in this case you nee…