How to activate a virtual environment via Bash

Create a file named anything.sh and make it executable Paste following code in file Run ./path-to-file.sh cd path/to/env/dir && source bin/activate

November 11, 2021 · 1 min · 21 words · Saqib Razzaq

How to Import All CSV Files in Directory in MySQL via Bash

Create a file import.sh and make it executable Paste following code in file mysqluser='root' mysqlpass='password' mysqldb='database_name' tablename='mysql_table_name' DIRECTORY='input_directory' for csv in $DIRECTORY/*.csv; do echo "Loading $csv" mysql -u $mysqluser --password=$mysqlpass -D $mysqldb -e "LOAD DATA INFILE '$csv' IGNORE INTO TABLE $tablename FIELDS TERMINATED BY '\t' ENCLOSED BY '\"' LINES TERMINATED BY '\n' IGNORE 1 LINES;" done

November 11, 2021 · 1 min · 56 words · Saqib Razzaq

How to quickly login to MySQL using Bash

I know this method isn’t the most secure way. But when I’m working on personal projects, it gets annoying having to enter credentials every time. Hence, I put together this little script to quickly log me in. I create file mysql.sh with following contents mysql -u username --password='password_here'

November 11, 2021 · 1 min · 48 words · Saqib Razzaq

How to run a script if it is not already running in Linux

Let’s say you have a script called crawl.py and you never want two instances of it running at the same time. The following script can do the job RUNNING="$(ps aux|grep crawl|grep -v grep|wc -l)" if [ $RUNNING -eq 0 ] then python crawl.py else echo "Already running : skipping"; fi

November 11, 2021 · 1 min · 50 words · Saqib Razzaq

How to ZIP all files in directory and send to another server

First install zip if not already install Ubuntu apt-get install zip Centos yum install zip Then create a file.sh and paste following code OUTFILE=outputfile.zip INPUTDIR=inputdir zip -R $OUTFILE $INPUTDIR scp $OUTFILE usrename@outserver:/path/of/ $OUTFILE -i key.pem

November 11, 2021 · 1 min · 35 words · Saqib Razzaq

Sublime Cheatsheet

Go to file Ctrl + P Toggle Sidebar Ctrl + K B Select line Ctrl + L Select word Ctrl + D Select content into brackets Ctrl + Shift + M Insert line before Ctrl + Shift + Enter Insert line after Ctrl + Enter Delete line Ctrl + Shift + K Duplicate lines Ctrl + Shift + D Join lines Ctrl + Shift + J Jump to matching bracket Ctrl + M ...

September 21, 2021 · 1 min · 73 words · Saqib Razzaq

Unlimited terminal history in Ubuntu

Add this to your .bashrc (Linux) or .bash_profile (MacOS): export HISTFILESIZE=-1 export HISTSIZE=-1

January 1, 2021 · 1 min · 13 words · Saqib Razzaq

Bash - ZIP all files in directory and send to another server

First install zip if not already install Ubuntu apt-get install zip Centos yum install zip Then create a file.sh and paste following code OUTFILE=outputfile.zip INPUTDIR=inputdir zip -R $OUTFILE $INPUTDIR scp $OUTFILE usrename@outserver:/path/of/ $OUTFILE -i key.pem

December 29, 2020 · 1 min · 35 words · Saqib Razzaq

Terminal Cheatsheet

A list of common terminal shortcuts + most common cli programs in Linux terminal ctrl + a move to start of a line ctrl + e move to end of a line Alt-f Move the cursor forward by one word Alt-b Move the cursor backward by one word ctrl + u Delete an entire line ctrl + k Delete everything after cursor Ctrl + Shift + F Find any text clear or ctrl + l to clear terminal reset clear everything and remove scroll cal show calendar command; command2 for running multiple commands regardless of output command && command2 for running commands only when first is successful ...

December 11, 2020 · 2 min · 242 words · Saqib Razzaq

How to install Docker on Ubuntu

sudo apt update sudo apt install apt-transport-https ca-certificates curl software-properties-common curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable" sudo apt update sudo apt install docker-ce sudo systemctl status docker docker --version

September 24, 2020 · 1 min · 38 words · Saqib Razzaq

How to dynamically create table in Twig

<table class="table table-bordered"> <thead> <tr> {% for range, dets in rents %} <th scope="col">{{range}}</th> {% endfor %} </tr> </thead> <tbody> <tr> {% for range, details in rents %} <td scope="row">{{details.item}}</td> {% endfor %} </tr> </tbody> </table>

July 13, 2019 · 1 min · 36 words · Saqib Razzaq

Apache - Download password protected file

wget --password=pass_here --user=user_name_here file_to_download

March 11, 2019 · 1 min · 4 words · Saqib Razzaq

How to run commands X number of times in Linux

for i in {1..number_of_loops}; do commandsSeparatedBySemicolon; done;

March 11, 2019 · 1 min · 7 words · Saqib Razzaq

Markdown Syntax Guide

This article offers a sample of basic Markdown syntax that can be used in Hugo content files, also it shows whether basic HTML elements are decorated with CSS in a Hugo theme. ...

March 11, 2019 · 3 min · 446 words · Hugo Authors