Learning Django - 2

This is the second post among a series of posts about my django learning experience.

I'll start clean and set things up for the whole development process. I'll be using, Ubuntu, Python 3 (https://www.python.org/downloads), virtualenv (https://virtualenv.pypa.io) so that I don't have any dependency conflicts with my other projects, pip for installing these tools and obviously django. Considering that I have the latest python 3 installed (pip comes packaged by default), I ran the following command ($ denotes a terminal session):

$ # Use the sudo command if necessary (only applicable for *nix systems, n/a for windows)
$ [sudo] pip install virtualenv
$ virtualenv virtual_folder
$ cd virtual_folder
$ source bin/activate

This installed virtualenv (short for Virtual Environment) and created a directory named virtual_folder for holding the new virtual environment. cd-ed into it and activated the virtual environment. Deactivating is easy, just run deactivate and it'll deactivate itself. Next, I'll install django with this command:

$ [sudo] pip install django

After django is installed, a terminal restart was needed to load in the new binary. Then I created a project named website with this:

$ django-admin startproject website

A new directory named website is created in the current directory. This contains all the necessary backbone for running a simple django server. cd (change the terminal's directory to point to it) into it. Now, the initial configuration is done and its time for a test run! Run this command:

$ python manage.py runserver

And it should start a server in the localhost at port 8000 or whichever is printed in your terminal. Visit: http://127.0.0.1:8000/ to view the new django server up and running! I'll be explaining in short, what each file is and why its necessary in my next post.

This is it for the initial setups.

Learning Django - 1

I'll be writing a series of posts as I continue my journey to learning django from scratch (note, I already know to some extent and use django but I felt like I had a gap somewhere in the middle). So, this is the first post of the a series of posts I'm going to write about django as I continue my journey learning it!

First, what is Django anyway? Django is a web (application) development framework for the Python programming language. It's available at https://www.djangoproject.com
As of writing this, the latest available version is 1.11.3 which I'll be using over the course of my learning path. Some of the prominent features of django include security right from the start, scalability (Instagram runs on Django, although there are other technologies in their stack for managing different parts of the whole infrastructure), built in ORM for database access, built in template system, etc. Django's philosophy towards development is the MVC (Model View Controller) pattern as described here in detail: https://docs.djangoproject.com/en/1.11/faq/general/#django-appears-to-be-a-mvc-framework-but-you-call-the-controller-the-view-and-the-view-the-template-how-come-you-don-t-use-the-standard-names

That's all for the first post!

UI design

Screenshots of the UI I'm designing and working on, for one of my current projects.





Shortcut: String to number in JS

Put a + (plus) operator in front of a string to convert it into a number.

+'12' (string) => 12 (number)
let x = '40'; (string)
+x => 40 (number)
There are three types of people.

  1. People who complain about the flow
  2. People who do nothing and go with the flow
  3. People who go with the flow and change the flow themselves

Now, you choose which one you want to be, do nothing, complain or change?

Structures in C

An introduction to structures (struct) in C.



Reactive Extensions (Rx) Programming

Reactive extensions (Rx) is a set of tools/API available for almost any popular languages/platforms out there, which aids in a new way of asynchronous programming (well, not completely new :p).

Most of the time, the way we write programs, we query data from a data source and wait for that data set to be ready. Once the data from the source is ready, only then we can perform different kinds of operation on it. This waiting process is blocking or synchronous i.e it blocks the program execution and waits for the data to be loaded. What if there was a mechanism that allowed the data source to push data to us and we could perform various kinds of operations on the data as it comes? Welcome to Reactive Extensions (Rx). Rx allows us to do exactly this. It exposes a set of types (Observables  & Observers) and operators (operations we can perform on those types) to aid us in asynchronous programming. This way, we don't need to wait for the data by blocking the program execution. Besides, we can perform operations on the data as it comes rather than wait for the whole data set to be ready. Its quite similar to event driven programming where you subscribe to an event by passing a callback and the system will execute the callback whenever an event happens. Although, Rx is much more powerful than just ordinary event driven mechanism.

Power function

In C/C++ (and also other languages), we have the built in power function to raise a number to a given power. What if we need to calculate ...