Skip to content

Instantly share code, notes, and snippets.

View tmcolby's full-sized avatar

Tyson Colby tmcolby

View GitHub Profile
@tmcolby
tmcolby / config.yml
Last active April 5, 2019 15:15
using yaml configuration file for python
database:
username: admin
password: foobar # TODO get prod passwords out of config
socket: /var/tmp/database.sock
options: {use_utf8: true}
memcached:
host: 10.0.0.99
workers:
- host: 10.0.0.101
port: 2301
@tmcolby
tmcolby / pacman.commands
Created April 26, 2019 14:35
arch linux pacman commands
To update the system
sudo pacman -Syu
Update the database:
sudo pacman -Syy
Installing
To install a package (always run pacman -Syu, before installing):
sudo pacman -S package_name
@tmcolby
tmcolby / config.json
Created May 7, 2019 16:54
using json configuration file for python
{
"rs485": {
"method" : "rtu",
"port" : "/dev/ttyUSB2",
"baudrate" : 9600,
"stopbits" : 1,
"parity" : "N",
"timeout" : 5
},
"modbus": {
@tmcolby
tmcolby / enable-wifi-raspberrypi.md
Last active May 16, 2019 16:28
enable wifi connection on raspberry pi

To enable wifi connection (assuming dhcp), enter the following commands from a shell prompt..
cd /etc/wpa_supplicant
wpa_passphrase <some ssid> <some ssid psk> | sudo tee -a wpa_supplicant.conf
echo "country=<some country code - ie: US>" | sudo tee -a wpa_supplicant.conf
sudo wpa_cli -i <your wireless interface - ie: wlan0> reconfigure
Now you can check to see if you get connected...
ifconfig

@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"' &
@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"

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 / 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
@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;