Skip to content

Instantly share code, notes, and snippets.

import pprofile
profiler = pprofile.Profile()
profiler.enable()
# Your slow code here
profiler.disable()
with open('/some/path/to/profile.prof', 'w') as file_:
// #define GENERAL_SWITCH_PIN 13 // 8
// #define DIRECTION_PIN 12 // 9
// #define UP_SWITCH_PIN 11 // 10
// #define DOWN_SWITCH_PIN 10 // 11
// #define BUTTON_UP_PIN 9 // 12
// #define BUTTON_DOWN_PIN 8 // 13
#define GENERAL_SWITCH_PIN 6 // 8
#define DIRECTION_PIN 5 // 9
#define UP_SWITCH_PIN 3 // 10
#!/bin/sh
if wmctrl -m | grep "mode: ON"; then
exec wmctrl -k off
else
exec wmctrl -k on
fi
#/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
# 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 %
@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
@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 / 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 / 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 / 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;
}