Skip to content

Instantly share code, notes, and snippets.

View devisnotnull's full-sized avatar
🎯
Focusing

Alex Brown @lextech devisnotnull

🎯
Focusing
View GitHub Profile
@devisnotnull
devisnotnull / sh
Created September 28, 2017 11:41
Forward port request to another networked machine
sudo iptables -t nat -A OUTPUT -p tcp -m tcp --dport 999 -j DNAT --to-destination 10.10.10.10:443
@devisnotnull
devisnotnull / sh
Created September 28, 2017 14:43
Setup port forwarding
#!/bin/bash
# https://serverfault.com/questions/532569/how-to-do-port-forwarding-redirecting-on-debian
IPTBL=/sbin/iptables
IF_IN=eth0
PORT_IN=40022
IP_OUT=172.16.93.128
PORT_OUT=22
@devisnotnull
devisnotnull / reset_osx_routing_table.sh
Created November 14, 2017 21:56
OSX clear routing table, Useful when switching around multiple VPNS
#!/usr/bin/env bash
# Reset routing table on OSX
# display current routing table
echo "********** BEFORE ****************************************"
netstat -r
echo "**********************************************************"
for i in {0..4}; do
sudo route -n flush # several times
@devisnotnull
devisnotnull / virt-install-ubuntu-18.04.sh
Last active May 29, 2018 21:21
KVM virt-install Ubuntu 18.04
#!/bin/bash
if [ $# -ne 1 ] ; then
echo 'Please provide a name for the virtual machine '
exit 1
fi
############################################
function print_with_line_numbers {
@devisnotnull
devisnotnull / ssh-port-forward
Last active May 28, 2018 21:36
SSH port forward
#!/bin/sh
# Remote ARG1
# Remote port $ARG2
# Local port $ARG3
if [ $# -ne 3 ] ; then
echo 'Invalid aruments provided, Example ./cli.sh 192.158.1.1 5900 5900'
exit 1
fi

Opening and closing an SSH tunnel in a shell script the smart way

I recently had the following problem:

  • From an unattended shell script (called by Jenkins), run a command-line tool that accesses the MySQL database on another host.
  • That tool doesn't know that the database is on another host, plus the MySQL port on that host is firewalled and not accessible from other machines.

We didn't want to open the MySQL port to the network, but it's possible to SSH from the Jenkins machine to the MySQL machine. So, basically you would do something like

ssh -L 3306:localhost:3306 remotehost

@devisnotnull
devisnotnull / composition.js
Created April 3, 2019 21:25
Simple ES6 functional composition
const compose = (...fns) =>
fns.reduce((prevFn, nextFn) =>
(...args) => nextFn(prevFn(...args)),
value => value
);
const compose2 = (fn, g) =>
(...args) =>
fn(g(...args))
@devisnotnull
devisnotnull / install_webdriver.sh
Created April 8, 2019 11:32
REHL/CentOS install chrome driver binary
#!/bin/sh
yum update -y
yum install -y wget unzip openjdk-8-jre-headless xvfb libxi6 libgconf-2-4
wget https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
yum install -y ./google-chrome-stable_current_*.rpm
curl https://chromedriver.storage.googleapis.com/73.0.3683.20/chromedriver_linux64.zip > ~/chromedriver.zip
unzip -o ~/chromedriver.zip -d /usr/local/bin/chromedriver
docker run -p 8000:8000 amazon/dynamodb-local --name aws-dynamo-db-local
@devisnotnull
devisnotnull / postgres.yaml
Created December 23, 2019 19:38
Postgres docker compose
version: '3.1'
services:
db:
image: postgres
restart: always
environment:
POSTGRES_PASSWORD: example
ports: