Automatically format python code in the current file after saving the file in Vim.
Python: Search and Replace in File
Searching and Replacing the text in a File
Using simple python semantics, we can perform search and replace in a file. Firstly, we will define the file name, along with the words to search and replace. After defining the sets of variables, we will open the file in r+ mode i.e. we can perform read as well as write operations in the file.
We will store the entire file contents using the read function, the contents of file are now stored in the form of a string. We further can set the position of the cursor or the current position in the file using the seek function. The seek function takes in a optional parameter as the position to set for reading/writing of file. Using the truncate function, we can clear all the contents of the file.
Feedparser: Python package for reading RSS feeds
Introduction
Feedparser is a simple but powerful python package that can be used to extract information about a specific webpage or a publication with its RSS feed(not only RSS). By providing the RSS feed link, we can get structured information in the form of python lists and dictionaries. It can be basically used in a pythonic way to read RSS feeds, it is really simple to use and it even normalizes different types of feeds.
Pipx: A python package consumption tool for CLI packages
Introduction
Previously, I explored the pipenv as a python package management tool and this week it is time for exploring a python CLI package isolation tool called pipx. It is a really simple and powerful tool for running commands as an executable from an isolated environment. Those commands should be associated with a python package that has CLI. In pipx, we install the package once and we can use the package anywhere on our system isolated from other virtual environments.
Pipenv: Python’s Official Package Management tool
Introduction
Pipenv is Python’s officially recommended Package management tool, as the name suggests it combines the power of pip and virtualenv. It is really powerful and gives control of package management for a python project. It also has support for adding dev packages, python versions, smartly recognizing main and derived package installation/uninstallation, and so on. It is the official package management tool for Python.
It is quite similar to npm for Nodejs in Javascript, or bundle for Ruby, cargo for Rust, and so on. It really simple and easy to use as it manages the overhead for package management for us and hence it is also a high-level package management tool as opposed to pip, which is not as powerful as Pipenv. So, in this article, we’ll explore Pipenv package manager for Python and how you can use it in your next python project. Let’s get started.
Vim: Get the Text from Visual Selection
Using Registers
We can get the selected text in a variable in Vim Script using registers.
normal gv"xy
let context = getreg("x")
Lets break down the command
normal mode -> gv -> (y)ank text -> to the "x" register
| |
| Copy the contents into x register(or any register you like)
|
Select the previously selected text
Here, we are entering normal mode and selecting text which was previously selected and yank the contents into a register in this case we are using (x) register, it can be any register.
Now to get the contents of that register we can use the function getreg("register_name") or use "xp" to paste the contents of the x register or more generally for any register("<register-name>p).
Dockerize a Django project
Dockerize a Django project
We can run our Django projects in a Docker Container by creating a Docker image for our project. It is really easy and intuitive to create a Dockerfile for any given application as it really is a matter of writing commands in a file and basically running it is a isolated environment. To create a Docker image, we first need a Dockerfile. A Dockerfile is simply a Blueprint to create a image in Docker. In this file we specify the instructions/commands/environment variables to create a image for our app to run.
Docker Port Forwarding
Docker Port Forwarding
Port forwarding is a process to redirect the communication of one address to other.
It is also known as Port Binding.
We can use -p command to use port forwarding in our local Docker environment.
docker run -p 8000:8000 django-app
The first port number is the local machine port and followed by a : is the container port number.
SO, the request from the container port are forwarded to the local/outside world in the docker environment.
Crossposter
crosspost your articles to devto, codenewbie, medium and hashnode
Podevcast
Developer podcast at a single place