Skip to content

Instantly share code, notes, and snippets.

View tmcolby's full-sized avatar

Tyson Colby tmcolby

View GitHub Profile
@tmcolby
tmcolby / api.py
Created August 13, 2021 19:35
simple web server that allows a host to post a file transfer
from flask import Flask, abort, request
from werkzeug.utils import secure_filename
import os
import requests
import json
# change this to set where you want the file to be saved
UPLOAD_FOLDER = "./"
# change this to only allow files with a given extension to be accepted
@tmcolby
tmcolby / git reset to master.md
Last active September 23, 2020 20:34
git reset to master including submodules

git reset --hard HEAD
git clean -f -d
git checkout master
git fetch origin master
git reset --hard origin/master
git pull
git submodule update
git submodule update --init --recursive
git submodule foreach git reset --hard HEAD
git submodule foreach git clean -f -d

@tmcolby
tmcolby / readme.md
Created August 11, 2020 14:47
step-ca: nginx reverse proxy with TLS passthrough

Use-case:
I have two servers running on my host instance.
The first, step-ca running on local port 1442.
The second, an ACL server running on local port 2443.
Each server terminates TLS directly.

I want both servers accessable from the public internet on port 443.
In this case, I have two DNS A records pointing to the same public IP address of the host instance.

I want requests to the CA @ https://ca.mydomain.io to be passed through to localhost:1443.

@tmcolby
tmcolby / readme.md
Last active February 2, 2020 20:43
raspberrypi systemd-nspawn

https://www.freedesktop.org/software/systemd/man/systemd-nspawn.html
chroot improved.

on arch - i needed qemu-user-static AUR. it takes FOREVER to biuld.
the conf files were absent and so systemd-binfmt (instead of binfmt-support) was failing to load. followed this and resolved: https://github.com/computermouth/qemu-static-conf/blob/master/README.md

create loopback of the raspberrypi.img file
sudo losetup -P -f --show some/path/to/raspbian.img
assuming loop0, mount the boot and rootfs
sudo mkdir-P /mnt/rpi

@tmcolby
tmcolby / dhcpd.conf
Last active December 21, 2019 18:12
docker dhcp server on localhost
default-lease-time 86400;
max-lease-time 86400;
authoritative;
log-facility local7;
subnet 172.17.1.0 netmask 255.255.255.0{
range 172.17.1.100 172.17.1.200;
@tmcolby
tmcolby / gist:799b1cf36a8f087aea1b97ce3b9aacd0
Created September 13, 2019 22:00
install python 3.6 on raspberry pi
sudo apt-get install python3-dev libffi-dev libssl-dev -y
wget https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tar.xz
tar xJf Python-3.6.3.tar.xz
cd Python-3.6.3
./configure
make
sudo make install
sudo pip3 install --upgrade pip

Elevate to root privilage, in VIM, on the go

Suppose you opened a file in the Vim editor, made a lot of changes, and then when you tried saving those changes, you got an error that made you realize that it's a root-owned file, meaning you need to have sudo privileges to save these changes.

:w !sudo tee %

The aforementioned command will ask you for root password, and then let you save the changes.

Credit: https://www.howtoforge.com/linux-tee-command/

@tmcolby
tmcolby / 99-usb-serial-by-port-3b.rules
Last active May 28, 2019 17:21
helpful udev rules for usb-serial adapters on the raspberry pi
# predictable enumeration based on physical port the usb serial adapter is plugged into
# Hardware : BCM2835 raspberry pi 3b
# Revision : a02082
# view looking at the ports of the pi
# usbSerial0 usbSerial1
# usbSerial2 usbSerial3
KERNELS=="1-1.2", SUBSYSTEMS=="usb", SUBSYSTEM=="tty", ATTRS{devpath}=="1.2", SYMLINK+="usbSerial0", GROUP="dialout", MODE="0666"
KERNELS=="1-1.3", SUBSYSTEMS=="usb", SUBSYSTEM=="tty", ATTRS{devpath}=="1.3", SYMLINK+="usbSerial2", GROUP="dialout", MODE="0666"
KERNELS=="1-1.4", SUBSYSTEMS=="usb", SUBSYSTEM=="tty", ATTRS{devpath}=="1.4", SYMLINK+="usbSerial1", GROUP="dialout", MODE="0666"
@tmcolby
tmcolby / shell commands
Last active May 23, 2019 20:49
socat tricks - relaying serial ports, sniffing/monitoring/data logging traffic
This first example assumes two usb serial port adapters are connected to the host machine. They enumerate as ttyUSB0 and ttyUSB1.
We want data coming into ttyUSB0 to be piped right back out of ttyUSB1 (so our host sits as a man in the middle).
We want an application running on the host to be able to connect to a com port and monitor the traffic.
# create the fifo
sudo mkfifo -m 777 /tmp/fifo
# stream serial data on /dev/ttyUSB0 to the fifo AND a virtual com port /tmp/relay
sudo socat /dev/ttyUSB0,raw,echo=0 system:'sudo tee /tmp/fifo | sudo socat - "pty,raw,echo=0,link=/tmp/relay"' &