馃憢 Welcome to my blog
- Academically a software developer who occasionally blabbers here
- My learnings just as a note to my future self. Maybe it helps someone else too.
馃憢 Welcome to my blog
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鈥檙e 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....
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....
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鈥檛 forget to revert to the latest state after this test ends. In this post, we will see who we can do this....
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鈥檛 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鈥檛 really customizing them....
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鈥檛 need to make any changes when I push my code into deployment....
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....
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....
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)....
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....
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....