Skip to content

Instantly share code, notes, and snippets.

@hanvari
hanvari / python-virtual-environment.md
Last active February 27, 2022 06:06
Python Virtual Environments

Python Virtual Environments

Using virtualenv

$ pip install virtualenv
$ virtualenv --version
# Creating env
$ virtualenv [--no-site-packages] [--python=/usr/bin/python2.7] env-name  
$ lsvirtualenv
@hanvari
hanvari / checkout-latest-commit-before-deadline.md
Created January 20, 2022 21:44
Checkout the latest commit before a given date/deadline

Checkout Latest Commit Before a given Date/Deadline

If you need to checkout the latest commit before a given date or deadline in a git repository:

First, save the desired deadline (yymmddhhmm) an environment variable:

export DEADLINE="2111081100" #yymmddhhmm

Second, run this command to checkout the lates commit before the defined deadline:

@hanvari
hanvari / cpanel-cronjob.md
Last active February 12, 2021 07:02
Creating Cronjob in cPanel

Cron-Job creation in cPanel

Command for Automated MySQL DB Backup

mysqldump --triggers --routines --events --tz-utc \
          -u<user> -p<pass> <db-name> | \ 
          gzip -9 > /full/path/to/backup/folder/`date +"\%Y-\%m-\%d-\%H\%M"`_my_db.sql.gz
  • The date format parameters must be escaped as %
@hanvari
hanvari / macos-dns-service.md
Created December 6, 2020 05:07
DNS Service in macOS

Configuring DNS Service (dnsmasq) for macOS

1. Installing dnsmasq

$ brew update && brew upgrade
$ brew install dnsmasq
# defaults to: /usr/local/etc
$ mkdir -pv $(brew --prefix)/etc/
$ sudo mkdir -v /etc/resolver
@hanvari
hanvari / rsync-cheatsheet.md
Last active July 3, 2021 13:55
rsync cheatsheet

RSync Commands CheatSheet

$ rsync --zaP src/ dst
$ rsync --zaP -e 'ssh -p <port-number>' src/ dst
$ rsync --anv src/ dst
$ rsync --delete
$ rsync --exclude=pattern
$ rsync --exclude=p --include=p
@hanvari
hanvari / mysqldump-tips.md
Last active February 12, 2021 07:03
mysqldump helpful tips for export/import

mysqldump Tips

CLI command format

$ mysqldump <mysqldump options> [<dbname1> <dbname2> ...] [> outputfile.sql]

CLI Options

  • --all-databases
@hanvari
hanvari / vim-tricks.md
Last active June 8, 2020 18:50
VI / VIM Editor Commands, Configuration, Tricks
@hanvari
hanvari / macos-iso-bootable.md
Created June 1, 2018 09:10
Create Bootable USB from ISO file in MacOS

Create Bootable USB stick form ISO in MacOS

Convert ISO to UDRW format

$ hdiutil convert -format UDRW -o destination_file.img source_file.iso

Prepare USB stick

  1. Find usb stick device file
$ diskutil list
@hanvari
hanvari / python-string-formatting.md
Last active June 9, 2020 05:55
String Formatting & Substitution in Python

String Formatting & Substitution in Python

Method-1

data = {'unit': 'celsius', 'value':20}
"The temperature in %(unit)s is %(value)f degrees" % data

Method-2

@hanvari
hanvari / python-histogram.md
Last active March 13, 2022 20:06
Plotting Histogram In Python

Plotting Histograms in Python

Using MatPlotLib API

Example 1:

s = np.random.uniform(-1,0,1000)
import matplotlib.pyplot as plt
count, bins, ignored = plt.hist(s, 15, normed=True)
plt.plot(bins, np.ones_like(bins), linewidth=2, color='r')