Skip to content

Instantly share code, notes, and snippets.

@porn
porn / tf-upgrade.sh
Last active October 9, 2023 13:24
terraform 0.12.31 -> 1.5
tfswitch 0.12.31
terraform plan # should show no changes
tfswitch 0.13.7
terraform 0.13upgrade
terraform state replace-provider -- -/aws hashicorp/aws
tfswitch 1.5.7
terraform init
terraform plan # should show no changes
rm versions.tf
terraform apply # store new version to tfstate
# vim: filetype=dosini:
add_newline = false
[username]
show_always = true
format = '[$user](bold green)'
[hostname]
ssh_only = false
format = '[@$hostname](bold green):'
@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
@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 / 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 / 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 / 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; } \
# -*- 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()
<!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});
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