This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## | |
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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[@]} |
NewerOlder