Skip to content

Instantly share code, notes, and snippets.

@randy3k
randy3k / homeassistant.conf
Last active September 16, 2024 05:12
Relying homeassistant and octoprint login errors to host rsyslog
# /etc/rsyslog.d/homeassistant.conf on client
# Enabling logging in HA
# logger:
# logs:
# homeassistant.components.http.ban: warning
if ($programname == 'homeassistant' and $msg contains 'Login attempt or request with invalid authentication') then {
$ActionQueueFileName fwdRule1
$ActionQueueMaxDiskSpace 1g
@randy3k
randy3k / update-dns-v2.py
Created September 12, 2024 17:46
Cloudflare dns update
import CloudFlare
import requests
myip = requests.get('https://api.ipify.org').content.decode('utf8')
cf = CloudFlare.CloudFlare(token='<TOKEN>')
zones = cf.zones.get(params={'name': '<DOMAIN>'})
if not zones:
raise Exception("zone not found")
@randy3k
randy3k / docker-compose.yaml
Last active September 6, 2024 04:47
Isolate cloudflared from my LAN network
networks:
cloudflared-network:
name: cloudflared-network
driver: bridge
ipam:
config:
- subnet: 10.0.1.0/24
gateway: 10.0.1.1
services:
@randy3k
randy3k / cloudflare.ini
Created September 4, 2024 19:08
Docker setup for letsencrypt certbot cloudflare
dns_cloudflare_api_token = <CLOUDFLARE-API-TOKEN>
@randy3k
randy3k / internal-bridge.sh
Last active September 2, 2024 04:37
Docker network setup
# allow internal bridge to gain internet access
docker network create net0 \
--internal \
--subnet=172.18.0.0/16 \
--gateway=172.18.0.1 \
-o com.docker.network.bridge.name=br0
docker run --net=net0 --name=n0 --cap-add=NET_ADMIN -itd alpine /bin/sh
docker run --net=net0 --name=n1 -it --rm alpine ping n0 -c 2
@randy3k
randy3k / netcat.txt
Last active August 25, 2024 04:01
rsyslog netcat example
# 134 = 16 * 8 + 6, i.e. facility = local0 and severity = info
echo "<134>1 - $HOSTNAME $PROGRAMNAME - - hello world" | nc -u -w 0 $DEST 514
@randy3k
randy3k / octopi
Last active June 9, 2024 12:02
octopi/octoprint config for nginx proxy manager
location ~ ^/webcam/(.*) {
rewrite ^/webcam/(.*) /octopi/webcam/$1 redirect;
}
location /octopi/ {
if ($scheme != "https") {
rewrite ^ https://$host$uri permanent;
}
rewrite ^/octopi/(.*)$ /$1 break;
proxy_pass http://192.168.0.167;
@randy3k
randy3k / ender-5-pro-cura-g-code-end
Last active July 2, 2023 17:58
Ender 5 Pro Cura G-code
G91 ;Relative positioning
G1 E-2 F2700 ;Retract a bit
G1 E-2 Z0.2 F2400 ;Retract and raise Z
G1 X5 Y5 F3000 ;Wipe out
G1 Z10 ;Raise Z more
G90 ;Absolute positionning
G1 X0 Y0 ;Present print
M106 S0 ;Turn-off fan
M104 S0 ;Turn-off hotend
M140 S0 ;Turn-off bed
@randy3k
randy3k / systemd-journal-gatewayd.md
Last active April 15, 2023 06:55
Fix systemd-journal-gatewayd bug in Home Assistant
sudo rm -rf /run/systemd-journal-gatewayd.sock
sudo touch /run/systemd-journal-gatewayd.sock
sudo reboot
vim /lib/systemd/system/systemd-journal-gatewayd.socket
[Socket]
@randy3k
randy3k / nb_available.c
Created January 28, 2018 05:36
use PeekNamedPipe to check bytes available
#include <windows.h>
#include <stdio.h>
#include <stdbool.h>
#define BUFSIZE 1024
int main(int ac, char** av) {
HANDLE h = GetStdHandle(STD_INPUT_HANDLE);
DWORD rd;