Separate development and production settings for a django project

When I first started working on Django, I used to edit the settings file every time I had to push the code to deployment. Change the value of DEBUG, read the values for SECURITY_KEY from a config file and many other settings. It used to be a really painful experience and I would curse myself every time I had to do that. Then, one fine day I decided that I have had enough and thought of finding ways through which I don’t need to make any changes when I push my code into deployment....

February 1, 2021 · 4 min

Using watch to monitor output change for a command

This is one of the things I wish I knew earlier. There have been a lot of times, where I needed to constantly monitor the output of a command and all I would do is use the up(arrow) and enter key to constantly run the previous command. If you, too, have been in this situation, I hope you do what is required in a more optimized manner after reading this post....

August 21, 2021 · 2 min

Caching expensive operations in python

Problem You have a function that takes a lot of time to execute. You need to call that function frequently, at different points in your code with the same arguments. This expensive function seems to be the bottleneck. Hopefully, after reading this post you will be able to deal with this situation and make your code work faster. Caching the output You can cache the output of the expensive function using lru_cache....

August 15, 2021 · 3 min

Find your files using the locate command on Linux

If you love doing things using the command-line interface(CLI) or automating stuff, you would love to know about the usage of the locate command. It helps to find files by their names. You may use different kinds of options as per your need. Here we are going to list some of the possible use cases. Basic use locate foo This will try to match the name foo against the whole name of the file(this includes the path from the current directory)....

July 26, 2021 · 2 min

The best of ls command

The ls command lists the files in the current directory in alphabetical order, if no directory is specified. This command is extremely useful in gathering information about the details of the files present in a directory. Many other useful information can be displayed using this command. In this article, we would learn about the different options available alongside the ls command. Simple Listing ls This displays the files inside the directory in an alphabetically sorted order in a column format....

July 6, 2021 · 4 min

Search through files using the grep command in linux

The grep command is one of the most powerful commands in Linux. It is used for searching a pattern inside files. The pattern can range from a simple alphabet to a complex regular expression. There are various scenarios where grep can be useful. I will try to list some of them in this post. List all the lines in a file that contain the word grep -i 'hello world' main.txt The -i option is used to ignore case distinctions i....

June 1, 2021 · 3 min

Debugging Python code

Much of a programmer’s time is spent debugging code than writing one. While I agree that it’s not a great thing, we can’t do much about it. But what we can do is maybe make this process more efficient and fun. In this post, we will try to discuss some techniques that can be useful for debugging. The order goes from a beginner level to a more advanced one. Using print Caution: This is not one of the recommended ways to debug things....

May 1, 2021 · 6 min

Use named tuples to stop yourself from remembering order of tuples

Let’s consider an example where you’re returning some info about a Person object from a function in the form of a tuple. def info(): ... return name, address, age Now, in this scenario the receiving function needs to know the sequence in which the values are being returned. Although, this might not seem to be much of an issue for a one-time use case, let me try to explain some possible issues with this....

April 15, 2021 · 3 min

An awesome django filter for displaying numbers

Displaying large numbers like 1234, 1243423, etc. in their raw form can be less intuitive for viewers. Such large numbers make it difficult to calculate the actual value of the number. Hence I thought of making a filter inside my Django application(you may call it app), for displaying numbers in a more informative format(and awesome too, I guess). The file structure and format might be specific to Django, but the logic can be used in any other framework or language....

April 1, 2021 · 4 min

Automating registry of django models to the admin

Registering models to django-admin(in general) is not much of a task, but is mostly boring. Many times it might feel like doing a chore. In this post, we’ll try to see how we can automate this process. Registering models Normally, models are registered inside the admin.py module of the apps. To automatically register all of our models, we can directly add these lines of code to this file. from django.contrib import admin from django....

April 1, 2021 · 2 min