MultiLevelMenu

Oct 17, 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.

Purpose Command
Delete a Remote Tag git push --delete origin <tagname>
Filenames diff between two commits git diff commit commit2 --stat
List all tags, sorted by name, in reversegit tag -l --sort="-v:refname"

Oct 14, 2016

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_chars-1)]
    return random_string

It does produce a random string of the required length.

However, I found out a better way:

$ openssl rand -base64 48

This generates a random string of length 48 characters.

Not only is the latter more succinct (though it requires OpenSSL to be installed), I would think the generated string it's more random than one based in python random library.

Oct 13, 2016

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.