Skip to content

Instantly share code, notes, and snippets.

@porn
porn / gist:d8e1beec85b41ce41030
Created February 3, 2016 14:59
find zombies using ansible
ansible -i inventories/production.ini webservers -m shell -a "ps aux | awk '\$8~/^Z|^STAT/{ print }'"
@porn
porn / gist:491725e91ac35f581bc0
Last active February 12, 2016 15:12
makefile for creating tags for python
####################################################
# ctags for vim
CTAGS_COMMON_EXCLUDES = \
--exclude=*.vim \
--exclude=public \
--exclude=install \
--exclude=doc \
--exclude=application/temp \
--exclude=application/logs \
--exclude=todo
include/image
Edit=/usr/bin/kolourpaint %f
Open=/usr/lib/mc/ext.d/image.sh open ALL_FORMATS
View=%view{ascii} /usr/lib/mc/ext.d/image.sh view ALL_FORMATS
# vim sessions
shell/.vim
Open=/usr/bin/vim -S %f
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.css" />
<script src="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.js"></script>
<script src='https://api.tiles.mapbox.com/mapbox.js/plugins/leaflet-pip/v0.0.2/leaflet-pip.js'></script>
<script type='text/javascript'>
window.onload=function(){
var map = new L.Map('map', {center: new L.LatLng(49.1, -122.5), zoom: 10});
# -*- coding: utf-8 -*-
from contextlib import contextmanager
from timeit import default_timer
@contextmanager
def elapsed_timer():
start = default_timer()
elapser = lambda: default_timer() - start
yield lambda: elapser()
@porn
porn / run_tests.sh
Last active August 2, 2016 11:37
prepend timestamp and custom text before stdout and stderr
#!/bin/bash
COMMAND=./test.sh
STDERR=./test.err
STDOUT=./test.out
# prepend timestamp followed by given string before each line of the output
IFS='' # preserve whitespaces
timestamp(){ while read line; do echo `date "+%Y-%m-%d %H:%M:%S"` $1 $line; done }
{ $COMMAND 2>&3 | timestamp "[$COMMAND]:" > $STDOUT; } \
@porn
porn / Makefile
Created August 2, 2016 06:35
Makefile with help
# print help
help: ## list available targets (this page)
@awk 'BEGIN {FS = ":.*?## "} /^[0-9a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
clean:: ## clean all compiled files
find . -name '*.pyc' -delete
@porn
porn / force_resync_mongo_secondary.sh
Created August 29, 2016 14:44
script for forcing initial resync of mongo secondary
#!/bin/bash
# this script is intended for forcing initial resync of mongo secondary
read -p "This will DELETE ALL data on the machine! If you wish to continue then type: 'sure'> "
if [[ ! $REPLY == 'sure' ]]
then
echo "Okay, bye!"
exit 1
fi
@porn
porn / tunnel.sh
Created April 6, 2020 13:40
ssh tunnelling
# when run on localhost, you can see on localhost:1234 what remote_machine sees on 172.31.26.6:2345
ssh remote_machine -fnNTL 1234:172.31.26.6:2345
@porn
porn / redirects.sh
Created September 25, 2020 06:52
redirect local 443 requests to another port
# after this commnad you can query https://localhost which will actually serve https://localhost:4200
sudo iptables -t nat -A OUTPUT -s localhost -p tcp --dport 443 -j REDIRECT --to 4200
# to view the rules
sudo iptables -L -t nat
# to remove the rule:
sudo iptables -t nat -D OUTPUT -s localhost -p tcp --dport 443 -j REDIRECT --to 4200