Skip to content

Instantly share code, notes, and snippets.

Avatar

Cameron Steel Tugzrida

View GitHub Profile
@Tugzrida
Tugzrida / mta-sts.js
Created May 28, 2021
MTA-STS Cloudflare worker
View mta-sts.js
// This worker is designed to be able to neatly handle MTA-STS policies for multiple domains.
// Make a new worker with this script and add your domains to the stsPolicies dict like the example.
// Add a DNS AAAA record for mta-sts.yourdomain.com pointing to 100:: and set to proxied,
// then add a workers route for mta-sts.yourdomain.com/* pointing to this worker.
// You'll still need to manually add the appropriate _mta-sts.yourdomain.com TXT record to enable the policy,
// and the _smtp._tls.yourdomain.com TXT record for reporting.
const stsPolicies = {
@Tugzrida
Tugzrida / drop-unknown-hosts.conf
Last active Jun 28, 2021
Drop connections to nginx which don't match any server block
View drop-unknown-hosts.conf
server {
listen 80 default_server;
listen [::]:80 default_server;
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
## For nginx >= 1.19.4:
## If also using openssl >= 1.1.1j, the certificate directives can be removed.
## Even if present, the cert is never sent, it's just a workaround for an openssl bug.
@Tugzrida
Tugzrida / uCollapse.css
Last active Apr 20, 2020
A tiny independent JS library for easily making collapsible sections.
View uCollapse.css
/* uCollapse v0.2 Created by Tugzrida(https://gist.github.com/Tugzrida) */
.ucollapsible {
overflow: hidden;
transition: height 0.3s ease-in-out;
}
.ucollapsible.ucollapsed {
height: 0px;
}
@Tugzrida
Tugzrida / mta-sts
Last active Dec 11, 2020
MTA-STS vhost for Nginx
View mta-sts
# A simple Nginx vhost to direct all requests to mta-sts.example.com to the mta-sts file.
# Just substitute your domain and certificate paths(MTA-STS *must* be available over HTTPS)
# Then do mkdir -p /var/www/mta-sts/.well-known and add your policy to
# /var/www/mta-sts/.well-known/mta-sts.txt
server {
listen 80;
listen [::]:80;
server_name mta-sts.example.com;
@Tugzrida
Tugzrida / certbot-cloudflare-hook.py
Last active Mar 24, 2022
Certbot hook script for obtaining certificates via Cloudflare DNS challenge
View certbot-cloudflare-hook.py
#!/usr/bin/env python3
# v0.3 Created by Tugzrida(https://gist.github.com/Tugzrida)
# Hook script for obtaining certificates through Certbot via Cloudflare DNS-01 challenge.
# Offers more flexibility for Cloudflare authentication than the certbot-dns-cloudflare plugin.
# Begin by running this script to automatically get zone information from Cloudflare,
# or define it manually in the `domains` dict below - Zone IDs are available in the Cloudflare dashboard.
# Note that this script is not actively maintained or guaranteed to work consistently.
# Use in prod at your own risk!
@Tugzrida
Tugzrida / lametric_icon.php
Created Feb 19, 2020
LaMetric Time icon overlayer in PHP
View lametric_icon.php
<?php
// This file defines the function lametricFormatNumber which accepts a filepath to an 8x8px PNG and string.
// The general idea is that an 8-digit number can be displayed on the LaMetric without scrolling by overlaying
// the left-most digit over the icon. By providing your desired icon PNG file(GIFs for animated icons not yet
// supported) and number to lametricFormatNumber, you will recieve as output your icon and number, with the first
// digit overlaid on the icon if the number has 8 or more digits. The alphabet A-Z is also included, however does not
// work as well, as the letters I, M, N, Q and W deviate from the 3-pixel width of all the other characters and digits.
// Theoretically, a 9-digit number could also be displayed as there is enough room on top of the icon, however then there
// won't be much room left for the actual icon, so it's not really worth it. At the end of this file is an example json
// output in LaMetric time format using the function.
@Tugzrida
Tugzrida / Prometheus Water Meter.md
Last active Dec 22, 2021
Prometheus Smart Water Meter project for the ESP32
View Prometheus Water Meter.md

Prometheus Water Meter

This is a fairly involved process as it seems that no one currently makes a pre-made product that measures water usage from a household meter.

It took quite a while to set up due to WiFi issues and the flow rate code still needs some work as the output is semi-random at the moment.

If you get stuck anywhere I'm happy to answer questions provided this doesn't go viral 😂

Components:

@Tugzrida
Tugzrida / MicroPython_RTC_DST.py
Created Nov 23, 2019
Implementation of NTP and Australian DST in MicroPython
View MicroPython_RTC_DST.py
import time, socket
from struct import unpack
from machine import RTC
standardTimeOffset = 60 * 60 * 10 # The base TZ UTC offset in sec, AEST(UTC+10)
summerTimeDifference = 60 * 60 * 1 # The difference between the base TZ and DST TZ in sec, AEDT(UTC+11), 1 hour ahead
rtc = RTC()
lastSync = 0
@Tugzrida
Tugzrida / certspotter_acknowledge
Created Nov 18, 2019
Automatically acknowledge Certbot renewals on Cert Spotter
View certspotter_acknowledge
#!/usr/bin/env python
# v0.1 Created by Tugzrida(https://gist.github.com/Tugzrida)
# Dependencies: python, requests
# Add your Cert Spotter API key below, then save this script to
# /etc/letsencrypt/renewal-hooks/deploy/certspotter_acknowledge with execute permissions.
# Any certificates renewed by this instance of Certbot will then be automatically
# marked as acknowledged on Cert Spotter to reduce notifications for legitimate
@Tugzrida
Tugzrida / microview_boards.txt
Created Sep 22, 2019
boards.txt definition for SparkFun Microview in new Arduino IDE
View microview_boards.txt
uview.upload.tool=avrdude
uview.bootloader.tool=avrdude
uview.name=MicroView
uview.upload.protocol=arduino
uview.upload.maximum_size=32256
uview.upload.speed=115200
uview.bootloader.low_fuses=0xff
uview.bootloader.high_fuses=0xde
uview.bootloader.extended_fuses=0x05
uview.bootloader.file=optiboot/optiboot_atmega328.hex