Skip to content

Instantly share code, notes, and snippets.

View openrijal's full-sized avatar
🇳🇵
<code />

Nitesh Rijal openrijal

🇳🇵
<code />
View GitHub Profile
# bash command to uninstall all pip installed packages
sudo pip uninstall -y $(pip freeze | sed 's;==.*;;g' | tr '\n' ' ')
# bash command to list top 5 large files/directories
du -a / | sort -n -r | head -n 5
@openrijal
openrijal / circular_deaths.py
Created May 25, 2017 12:16
circular deaths probelm
num = 100
people = list(range(1,num+1))
index = 0
while len(people) > 1:
people.pop((index+1) % len(people))
index = 0 if (index >= len(people)-1) else (index+1)
print people[0]
@openrijal
openrijal / months_delta.py
Created April 27, 2017 05:22
substract month from python datetime
def monthdelta(date, delta):
m, y = (date.month+delta) % 12, date.year + ((date.month)+delta-1) // 12
if not m: m = 12
d = min(date.day, [31,
29 if y%4==0 and not y%400==0 else 28,31,30,31,30,31,31,30,31,30,31][m-1])
return date.replace(day=d,month=m, year=y)
@openrijal
openrijal / mysql_transaction_iso
Created January 11, 2017 05:50
MySQL Transaction Isolation Level
##
# Set isolation level to READ-COMMITTED
# https://dev.mysql.com/doc/refman/5.6/en/set-transaction.html
##
SELECT @@GLOBAL.tx_isolation, @@tx_isolation;
SET GLOBAL tx_isolation='READ-COMMITTED';
SET SESSION tx_isolation='READ-COMMITTED';
##
# Set binlog to MIXED format
@openrijal
openrijal / periods_delta.py
Last active November 10, 2016 10:24
methods to calculate datetime from days, months and years delta in python
import datetime
def days_period_to_datetime(dd):
now = datetime.datetime.utcnow()
return now + datetime.timedelta(days=dd)
def months_period_to_datetime(mm):
now = datetime.datetime.utcnow()
new_day = now.day
@openrijal
openrijal / first_last_day.py
Last active October 3, 2016 07:57
return first and last day of a month (in datetime)
from datetime import datetime, timedelta, date
def get_first_day(dt, d_years=0, d_months=0):
# d_years, d_months are "deltas" to apply to dt
y, m = dt.year + d_years, dt.month + d_months
a, m = divmod(m - 1, 12)
dt = date(y + a, m + 1, 1)
return datetime(dt.year, dt.month, dt.day, 0, 0, 0)
def get_last_day(dt):
@openrijal
openrijal / nginx.conf
Created September 9, 2016 13:51 — forked from asmallteapot/nginx.conf
My default Nginx configuration for serving Django projects.
# file: /etc/nginx/sites-available/example.com
# nginx configuration for example.com
server {
listen 80;
server_name example.com;
access_log /srv/www/example.com/logs/access.log;
error_log /srv/www/example.com/logs/error.log;
# pass root to django
@openrijal
openrijal / difflake.sh
Created August 19, 2016 10:42
shell script to run pyflakes on all python files in a git diff
#!/bin/bash
PYFLAKES=$(which pyflakes)
GIT=$(which git)
BRANCH=$($GIT rev-parse --abbrev-ref HEAD)
if [ $# -eq 0 ]
then
echo "No arguments supplied, please provide atleast 1 branch or commit hash. SYNTAX: difflakes [src] [dst]"
exit;
#!/bin/sh
echo "Flush all firewall rules and allowing everyone..."
ipt="/sbin/iptables"
## Failsafe - die if /sbin/iptables not found
[ ! -x "$ipt" ] && { echo "$0: \"${ipt}\" command not found."; exit 1; }
$ipt -P INPUT ACCEPT
$ipt -P FORWARD ACCEPT
$ipt -P OUTPUT ACCEPT
$ipt -F
$ipt -X
#!/usr/bin/env bash
# OpenSSL requires the port number.
SERVER=yoursslsite.com:443
DELAY=1
ciphers=$(openssl ciphers 'ALL:eNULL' | sed -e 's/:/ /g')
echo Obtaining cipher list from $(openssl version).
for cipher in ${ciphers[@]}