Friday, November 12, 2021

How to redirect http requests to https?


Add the following lines to the /etc/apache2/sites-enabled/000-default.conf file in side <VirtualHost *:80> </VirtualHost> block (In debian based linux)

RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

Tuesday, August 24, 2021

How to attach and detach your drive files to google colab?

To attach execute the following

from google.colab import drive
drive.mount('/content/drive') 
   

To Detach execute the following,

from google.colab import drive
drive.flush_and_unmount()

Tuesday, March 12, 2019

How to make Brother HL 2040 printer working under Linux?


Go to this link -> https://www.openprinting.org/printer/Brother/Brother-HL-2040

Click on the link "directly download PPD" which is underlined in green colour
PPD for Brother-HL-2040


Now in your linux machine (Debian based)
goto printer settings -> Select the "provide PPD" option -> Browse to the downloaded PPD file and "apply"

Check with the test print.

Friday, March 1, 2019

how to do math operations inside Django template?

1. Install "django-mathfilters" package using pip
   pip install django-mathfilters

2. Open settings.py file of your Django project and add  'mathfilters' in INSTALLED_APPS section.
   After this your settings.py file's INSTALLED_APPS section will look as follows
   INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'mathfilters',
   ]

3. Now you can do the basic math operations like add, sub, mul, div etc., like as follows
    add - {{ 8|add:4 }}
    mul - {{ your_var|mul:2 }}

For more details please refer -> https://pypi.org/project/django-mathfilters/

Thursday, February 28, 2019

How to import csv data into mongodb?

How to import large amount of csv data to mongodb
mongoimport -d <dbname> -c <collection_name> --type csv --file </path/to/actual/file.csv> --headerline

<blah> - Replace with your respective values

-d <dbname> - Tells to your mongo server into which database you want to import
-c <collection_name> - Tells to your mongo server in <dbname> into which collection you want to import
--type csv - Says it is a csv file
--file <path> - Give full path to your csv file
--headerline - if given, uses the first line as field names.