Synchronize panes in tmux

So, you want to run the same command over different terminals? By the end of this blog, hopefully you will know about this neat trick/hack to solve this problem. Hopefully, you’re familiar with tmux. If not, basically it is a tool that is used as terminal multiplexer. You can create, access, control multiple terminals from a single screen(and many more things). So, we will be using it to run the same command in different terminals....

May 9, 2021 · 2 min

Speeding up your django tests

Running tests can become troublesome, if your tests take too long to execute. Ideally, you want an instant feedback from them. Lets us discuss some ways through which we can speed up the run time for our tests. Move data creation to setUpTestData setUpTestData is pretty much like setUpClass in unittest. This method is run once before the test class runs. One of the main reasons, tests can be slow is if data creation in done in setUp method or inside individual tests....

March 1, 2021 · 4 min

Writing unit tests for migrations in django

Writing tests for migration can be a bit tricky because all of your migrations are generally run before any of your test. In case you want to test your code for a particular migration, you will have to revert the database to that particular state. Make sure you don’t forget to revert to the latest state after this test ends. In this post, we will see who we can do this....

March 1, 2021 · 3 min

Add tests to verify registry of models to django admin

In the last post, we learned how to automate registration of models to the django-admin. In this post, we will try to see how we can add tests to verify that all our models have been registered. Why do we need it? Even though the admin.py module is run internally when running the tests, it doesn’t actually verify whether all models have been registered or not. It is a very common thing to forget registering your model to the admin, especially when you aren’t really customizing them....

July 1, 2021 · 2 min

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