Vim - Delete Lines with Regex

Global The ex command :g -global command, is very useful for acting on lines that match a pattern. Usually it works like this: :[range]g/pattern/cmd Delete contains To delete all lines that contain “price” you can use: :g/price/d If you want to use multiple pattern you can use ‘or’ |: :g/price|customer|secret/d Delete not contains To delete lines that does NOT contain “price” you can use: :g!/price/d ~Some extras Delete all empty lines :g/^$/d Or deleting all lines that are empty or that contain only whitespace:
Read more →

Git Diff of Current and Previous Version of a File

We will use vim and git wrapper plugin for this. Installation First make sure you installed Tim Pope’s vim-figitive plugin before started. In the repo there is clear instruction but for vim-plug, add below line to your .vimrc and source it: " Plugins will be downloaded under the specified directory. " Change it to direct to yours call plug#begin(’~/.local/share/nvim/plugged’) " Add this Plug ‘tpope/vim-fugitive’ call plug#end() Then run :PlugInstall.
Read more →

How to Upgrade to Python 3.7 on Ubuntu 18.04/18.10

In this article, we upgrade to python 3.7 from python 3.6 and configure it as the default version of python. I was just trying to upgrade my python and I find it a little bit hard to do. Python 3.6 is the default version that comes with Ubuntu 18.04/18.10 But the latest version is Python 3.8. So it would be better to upgrade one major version. So lets start:
Read more →

Django - DB bulk_create()

bulk_create() From Django doc: This method inserts the provided list of objects into the database in an efficient manner (generally only 1 query, no matter how many objects there are): So instead of inserting data into db one by one in an inefficient manner it is better to use this method. Method api detail: bulk_create(objs, batch_size=None, ignore_conflicts=False) Example: >>> MyModel.objects.bulk_create([ … MyModel(title=‘This is a test’), … MyModel(title=‘This is only an another test’), .
Read more →

Django UserContextMixin

If you want to get the currently logged-in user and use it—e.g at the top of every template, in class-based view it could be hard to achive. However there is an easy and pythonic/djangoic way to accomplish that: just use a Mixin. Actually Django framework consists of very wide range of Mixins such as SingleObjectMixin or TemplateResponseMixin. For more detail: Django Class-based Mixins. So now we can write our very own Mixin to do the job:
Read more →