Skip to content

Instantly share code, notes, and snippets.

@candale
candale / check_sub.py
Last active October 16, 2019 07:32
check_sub.py
"""
Run: python3 check_sub.py path_to.srt
Give the following:
- error if the first line in file is a number with no spaces around it
- error if there are two blank lines between two subtitle chunks
- error if sync info matches the standard format, with no spaces at the
beginning or end
- error if a subtitle chunk has more than three subtitles lines
- warning if a subtitle chunk has no subtitle lines
@candale
candale / run_tests_parallel.py
Last active May 20, 2019 11:50
django_test_parallel.py
# coding: utf-8
"""
This module provides
"""
from __future__ import unicode_literals
import os
import sys
from multiprocessing import Process, Queue
# Draft for installing everything needed for a fresh os.
sudo apt-get update
sudo apt-get upgrade -y
# === Install git ===
sudo apt-get install git -y
sudo apt-get install vim -y
sudo apt-get install build-essential -y
# === Install Sublime Text ===
@candale
candale / status.server.com
Created September 2, 2017 12:06
Multiple Netdata from same nginx
upstream local {
server localhost:19999;
keepalive 64;
}
upstream some_other {
server some_other:19999;
keepalive: 64;
}
@candale
candale / before.rules
Last active May 7, 2019 08:55
Forwarding from one interface to another (UFW)
# Place this in /etc/ufw/before.rules
*nat
-A PREROUTING -p tcp -s 10.10.0.0/24 --dport 7000 -j DNAT --to-destination 10.0.0.3:7000
-A PREROUTING -p tcp -s 10.10.0.0/24 --dport 9160 -j DNAT --to-destination 10.0.0.3:9160
-A PREROUTING -p tcp -s 10.10.0.0/24 --dport 9042 -j DNAT --to-destination 10.0.0.3:9042
COMMIT
@candale
candale / packet_sniff.py
Last active November 11, 2017 10:13
Python Packet Sniffer
import sys
import socket
from struct import unpack
import pprint
from collections import namedtuple
interface = sys.argv[1]
raw_socket = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_TCP)
@candale
candale / heap.py
Last active May 31, 2017 09:24
Python heap usage
# From stackoverflow answer https://stackoverflow.com/a/938800
import os
_proc_status = '/proc/%d/status' % os.getpid()
_scale = {'kB': 1024.0, 'mB': 1024.0*1024.0,
'KB': 1024.0, 'MB': 1024.0*1024.0}
def _VmB(VmKey):
'''Private.
@candale
candale / install_zsh_and_co.sh
Last active November 26, 2022 22:03
Install zsh and oh-my-zsh for yourself or other user
# to get in a terminal: curl -X GET http://is.gd/installzsh_sh > installzsh.sh
TARGET_USER=$1
echo "Installing zsh..."
sudo apt-get install git curl zsh -y > /dev/null;
echo "Installing oh-my-zsh"
if [ "$TARGET_USER" != "" ]; then
echo "Installing oh-my-zsh for user $TARGET_USER";
export RUNZSH=no
# Config taken from http://www.hamvocke.com/blog/a-guide-to-customizing-your-tmux-conf/
set-option -g default-shell $SHELL
# split panes using | and -
bind | split-window -h
bind - split-window -v
unbind '"'
unbind %
#/bin/sh
du -k --max-depth=1 | sort -nr | awk '
BEGIN {
split("KB,MB,GB,TB", Units, ",");
}
{
u = 1;
while ($1 >= 1024) {
$1 = $1 / 1024;
u += 1