Aug 1, 2018

Change password of a user in Django

Start by opening the Django shell from your terminal

> python shell

Then inside the Django shell, first get hold of that user object, then change the password and save.

Dec 21, 2016

Django query time using the connection module

The Django connection module keeps track of recent queries. To see the SQL code and time taken to run the queries, have a look at the connection.queries field.

from django.db import connec...
Nov 28, 2016

Django F expression for increment

Django F expressions can be used to manipulate object fields in the database without pulling them out to the application layer. An use case is when a field needs to be incremented. The less then ideal way to do so wou...

Aug 7, 2016

An Algorithm for Detecting Handedness of Fiddler Crabs

This came out of some experiments I did around 2011 on image processing.

Members of the genus Uca are generally known as Fiddler crabs for the overgrown claw of the males. The following algorithm detects a male fiddler crabs handedness from a photograph. The algorithm was implemented using ...

Jul 31, 2016

Custom styling of input placeholder with CSS

Styling of the input placeholder is done by setting appropriate color etc. values of a pseudo-element. The name of the pseudo-element varies from one browser family to another. Until this becomes part of the CSS specifications, we'll have to do it like the below code snippet.

// Firefox


Jul 1, 2016

Find large files in a given directory

A linux command called du is used to display disk usage statistics. By default it shows all the files and subdirectories (recursively) residing under the current directory. For example:

> du -h
4.0K    ./node_modules/.bin
256K    ./node_modules/nlp_compromise/client_side/basic_...
Mar 25, 2016

A code template for writing secure Meteor methods

Meteor methods provide secure means for database write. While allow-deny rules can also provide security, methods allow more fine grained control. This comes in handy when dealing with complex data models.

Here is a code template for writing secured methods in Meteor.



Jan 19, 2016

Calling C functions in Python scripts

Python is an extensible language. Code written in compiled languages like C can be invoked from Python with a little effort. This allows software developers to write simple human readable scripts in Python to make use of faster libraries written in compiled languages.

Say, we have the followin...

Jan 19, 2016

Static member in Python

For creating a static field of a class, write it inside the class outside of the scope of any member functions. To declare a variable belonging to instance, add self. prefix. To make a function static, add the @staticmethod decorator.

class Some_class(Name_of_super_class):

Oct 6, 2014

Debugging RE

One of Python's most useful feature is its Regular Expression support. However, it is easy to get a regular expression wrong and if you do, debugging it can be a painful as well. Fortunately, Python allows us to set a DEBUG flag during compilation of a regular expression.

import re
pat = re...
Sep 23, 2014

A word of caution on os.path.abspath

Due to the implementations of abspath in Python, it requires some careful consideration. The source code for os.path.abspath can be found in the file in your Python installation folder. Windows users open instead. Have a look at the abspath function (I'm quoting what I ...

Sep 4, 2014

Python object from dictionary

It is more convenient to access the fields of a class using the dot notation than accessing the entries in a dictionary. Python allows a quick conversion between simple dictionaries to python objects.

x = myObj.x
x = myDict['x']

A python object can be instantiated from the contents of a ...

Mar 4, 2014

Git Cheat-Sheet

Here is a git cheat-sheet of my frequently used commands.

Basic Usage

git init
initializes git in a local folder

git status
shows status of the pwd

git add filename
stages untracked items

`git commit -m "message"`` commits staged files to repo with a message


Mar 2, 2014


The xargs command breaks down the data from standard input into parts small enough to be fed into an unix command that takes input from the argument list only.

Some unix commands can take input from standard input, e.g., grep , and ls. Then there are other commands that take input from t...

Feb 24, 2014

Javascript Arithmetic Operation on Numeric Strings

In an statement involving the ‘+’ operator on a numeric string and an int, JavaScript converts the int into a string and perform string concatenation. For all other arithmetic operators, the numeric string is converted to a number. This is elaborated with the example bellow.

console.log ( "12...
Feb 8, 2014

String representation of Python objects

It is often necessary to provide string representation of objects. Application of this can be found in debugging, storing in a file, communication across the network, etc. Two builtin functions str() and repr() output string representation of Python objects. But how do they differ from each other...