View All

Git Basics


Change User Information

One of the first things to do when setting up Git is to set your name and email. This information is included in each commit and is important when working on your own open source project, or contributing to another, so others can contact you if there are any issues.

To set your name and email for all repositories:

git config --global "Enter your name here"
git config --global "Enter your email here"

To set your name and email only for the current repository (overrides global settings):

git config "Enter your name here"
git config "Enter your email here"

Change Editor

The default editor for writing commit messages varies by oper...

Read more

List Comprehensions and Generator Expressions In Python


List Comprehensions

List comprehensions are a common idiom in Python for creating a new list. The elements of the new list are the result of an operation applied to each element in another sequence or iterable. An overview can be found in the official Python documentation here.

List Comprehension v.s. For Loop

The basic form of a list comprehension looks like this:

>>> numbers = [i for i in range(10)]
>>> print(numbers)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

This can be thought of as shorthand for the code below, which creates an empty list, iterates over the range of numbers, and appends each number to the list:

>>> numbers = []
>>> for i in range(10):
>>>     numbers.append(i)
>>> print(...

Read more

Managing SQLite Connections In Android


It can be difficult to correctly manage SQLite database connections in Android. Memory leak issues can occur when opening more database connections than have been closed. Also, some database writes may fail when creating and using more than one SQLiteOpenHelper object in your project.

There are a couple solutions to this problem. One is to wrap the SQLiteDatabase in a ContentProvider. I don't have much experience with this so I'm not sure if it's a good option or not, but it's worth looking into. The other option is to use the singleton pattern for your SQLiteOpenHelper class.

The singleton pattern is a design pattern that restricts the instantiation of a class to one object. Doing this ensures safe access to the database as all database...

Read more

Switching To PostgreSQL For Your Django Project


The default database option for Django is SQLite, which is a great option to get up and running quickly but it may not scale well beyond a certain point. A good alternative is PostgreSQL and, although it's overkill for my purposes, it's what I'm using for this website.

Follow the steps below to start using PostgreSQL for your Django project. If you are working with an existing project you will need to backup the data in your current database beforehand and restore it in PostgreSQL afterwards.

Install Required Packages

Open the terminal and run the commands below to install the necessary packages.

libpq allows client programs to communicate with a PostgreSQL database.

sudo apt-get install libpq-dev

python3-dev is required to build psy...

Read more

Refactoring Microsoft Access Databases With Python


Working with an inherited legacy application can feel like an insurmountable task. I found myself in this position at work where there is a sizable amount of code in legacy Microsoft Access databases. Access in particular can be difficult to work with as it doesn't make implementing software development best practices easy. In the wrong hands an Access database can quickly turn into a mess.

The way I've approached refactoring Access database is to first export all of the database objects (tables, queries, forms, reports, macros, and modules) to text files. I then use Python to search the exported files for object references. This makes the task of determining which objects can be safely removed or changed much more manageable.

Exporting ...

Read more