Category: Software Development

  • Why is Kubernetes also called k8s

    Kubernetes is abbreviated as “K8s” to shorten it’s length. There are 8 characters in “Kubernetes” between the first letter “K” and the last letter “s”.

    There are a few other places in the software industry where you might have noticed this style of abbreviation: I saw it first in “i18n” for “internationalization” (from where it seems to have started). There’s also l10n for “localization”.

    – n7n

  • PostgreSQL or Postgres?

    I usually use “Postgres” when speaking to other developers and PostgreSQL in documents when I can use the capitalised “SQL” for emphasis. Here’s how the PostgreSQL name came up:

    PostgreSQL evolved from the Ingres project at the University of California, Berkeley. In 1982, the leader of the Ingres team, Michael Stonebraker, left Berkeley to make a proprietary version of Ingres. He returned to Berkeley in 1985, and began a post-Ingres project to address the problems with contemporary database systems that had become increasingly clear during the early 1980s. At the time, POSTGRES used an Ingres-influenced POSTQUEL query language interpreter.

    In 1994, POSTQUEL query language interpreter was replaced with one for the SQL query language, creating Postgres95.

    In 1996, the project was renamed to PostgreSQL to reflect its support for SQL. The online presence at the website PostgreSQL.org began on October 22, 1996.

    After a review in 2007, the development team decided to keep the name PostgreSQL and the alias Postgres.

    – from Wikipedia

    Computer History is lovely!

  • Signal App’s awkward copy-paste gesture

    The “Copy message” button in the Signal App on iPhone doesn’t show up when you long press the text (on the pop-up ribbon like other messaging apps).

    The copy icon is placed in the bottom Tab Bar. That seems like an awkward UX error for such a mature app! Or is it just me wondering about this?

    Overriding the given operating system’s native gestures, for basic tasks like copying and pasting, is a really bad idea. If you’re a designer/developer: there are plenty of other ways to add character” to your apps, but just keep the look, feel, and gestures for regular tasks close to the native OS ways.

    I wish more people embrace Signal in coming days still: https://signal.org/install/

  • Reading and Writing Excel (xlsx) files with Python

    Jan 2021 Update

    For Writing: use xlsxwriter (don’t use xlwt, it doesn’t support xlsx format.)
    For Reading: use openpyxl (xlrd removed the support for xlsx in Dec 2020 due to security concerns.)

    (more…)
  • Why, When, and How to use Celery with Python

    “Celery is an asynchronous task queue based on distributed message passing.”

    Let’s break that down:

    (more…)
  • Setting up a Python Virtual Environment for Web Development

    Virtual Environments are helpful in keeping all the dependencies (packages), required for a Python project, in one place. So you can avoid issues with conflicting dependencies when working on different projects simultaneously. For instance, one major use case is when you want to run different Python versions like 2.7, 3.5, and 3.6 on the same system.

    You can use the following steps when setting up any Python project (including web development project using frameworks like Django, Flask etc.)

    1. Make a top-level Directory

    Create a directory named “virtualenvs” (a parent directory to keep all your virtual environments). All your Python projects will live inside this directory.
    mkdir virtualenvs

    2. Create the Python Virtual Environment

    cd virtualenvs
    python3 -m venv env

    You may use any name for the directory, other than “env”. If you’re curious about what goes inside the auto-generated “env” directory, you can check here:
    cd env
    cat pyvenv.cfg
    python —version
    pip —version

    3. Activate the virtual env

    On Mac: source bin/activate
    On Linux: ./bin/activate
    On Windows: .\Scripts\activate

    Important: You need to activate the virtual environment every time you want to build or run the code. You may edit the code files without activating the venv.
    Use deactivate to leave the virtual environment, or simply close the session/Terminal.

    4. Create the project directory

    mkdir your_proj_name

    Optionally, Initialise git inside your_proj_name directory (you don’t need to commit the other files of env directory into git.):

    git init
    OR if you have the project code already, git clone the code inside env:
    git clone [url]

    5 a. Install packages/dependencies using pip

    If you’ve a requirements.txt file:
    pip install -r requirements.txt

    or install the packages individually, for example for Django:
    pip install django or
    pip install django==2.1 # For a particular version

    5 b. You can also install packages from Source Code

    For example download Django pre-release code from their git repo, and unzip it into a directory named django, then:

    pip install -e django
    OR
    pip install --editable django

    Note that you may run pip from any of env‘s subdirectories: the installed code will always go into the env/lib and env/bin directories.

    6. Finish and Run

    You’re set to start working on the project now.
    If you’re satisfied with the setup, you most probably want to keep a list of dependencies you just installed.

    pip freeze > requirements.txt

    (Keep the requirements file in git if you’ve initialised the git repo.)

    7. Optimizing your daily workflow

    I made this small shell script to automate the task of entering and activating the venv every-time I start:

    #!/bin/bash
    cd virtualenvs/env/
    source bin/activate
    # Configure any other environment variables here -
    # for example, private API keys that you don't want to check in to git.
    cd your_proj_name/
    

    Paste the above code in a file name  start_your_project_name.sh. From now on, to get started, you just have to do this:

    source start_your_project_name.sh
    or ./start_your_project_name.sh
  • Django’s Request-Response Cycle

    Understanding the Request-Response Cycle is a crucial step in setting up for any WebServer.

    An example of the request-response cycle is when you “request” a web page by entering a URL in your browser and a web server sends a web page as ‘response’ to your browser. Of course, there’re usually several HTTP requests that happen when visiting a website; each is a separate Request-Response in itself.

    The request-response architecture of a web application is an important idea to grasp whether you’re working on Django, Symphony, Laravel, Flask, WordPress or any of the thousands of other web frameworks.

    When you call a Django server the flow typically is

    Request: Browser → Web Server → WSGI → WSGI callable function in Django

    Response: Django → WSGI → Web Server → Browser

    Here’s a diagram that explains the request-response flow very well.

    Django's Request-Response Call Cycle

  • Git — Getting Started

    Using Git is simple and so I’m keeping this very short.

    1. Github.com is not git

    2. You only need to learn these six commands to get started:

    • add
    • commit
    • push
    • pull
    • clone
    • status

    3. push is akin to uploading your files to the server (for safe-keeping). Before pushing you’ve to write a comment about what you want to push using the commit command. pull is akin to getting your files from the server.

    4. Learn these two commands after you’re conversant with the first six commands:

    • branch
    • checkout

    5. Graphical tools can help you visualise how and when changes happened. I like git-fork.com on Macs. Visual Studio Code and various code editors have git integration.