Skip to content

Instantly share code, notes, and snippets.

View daveio's full-sized avatar
🧑‍🎤

Dave Williams daveio

🧑‍🎤
View GitHub Profile
@daveio
daveio / simon-sweeney-letter.md
Last active February 23, 2016 10:03
What has the EU ever done for us?

This letter was originally published by [Guardian Letters][0], and has been reformatted for clarity and ease of reading. Other than minor punctuation and significant layout changes, it is presented verbatim.

At last we may get a debate on Britain's relationship with Europe ([Leader][1], 11 January). What did the EEC/EU ever do for us? Not much, apart from:

  • Providing 57% of our trade.
  • Structural funding to areas hit by industrial decline.
  • Clean beaches and rivers.
  • Cleaner air.
  • Lead free petrol.
  • Restrictions on landfill dumping.
@daveio
daveio / youtube.sh
Created February 10, 2018 19:28
Stream from the Raspberry Pi Camera to YouTube Live
#!/bin/bash
# Stream from the Pi camera to YouTube Live.
# Uses information from https://www.makeuseof.com/tag/live-stream-youtube-raspberry-pi/
# Modified to use v4l2 directly (lower cpu, lower latency, higher frame rate, basically More Better)
# Setup: standard Pi Camera setup, then sudo apt-get install libav-tools
# You may need to modify the horizontal and vertical flip options to suit your mount.
# Usage: youtube.sh YOUTUBE-SECRET-KEY

You have a shredder connected to an empty box, and various rubber balls. The balls are all the same colour, each ball of a certain type is identical, and each type is made of a different material from each other type. The shredder is special, in that if you put a ball in the shredder, the pattern of the shredded-up remains in the box will be the same every time, but distinct from any other type of ball.

You want to demonstrate to someone who does not know a secret that you and Bob both know that secret. The secret is a sequence of four balls of any type.

The secret value is a Type 1 ball, followed by a Type 2 ball, a Type 3 ball, and a Type 4 ball.

Bob puts his four balls in the machine, one after the other, and the resulting state of the box is a chaotic mess; each shredded bit has been buffeted around by all the other shredded bits. It looks nothing like any one ball’s pattern.

The state of the box is a hash of the secret information.

@daveio
daveio / keybase.md
Created April 11, 2019 11:37
keybase proof

Keybase proof

I hereby claim:

  • I am daveio on github.
  • I am dave (https://keybase.io/dave) on keybase.
  • I have a public key ASC4CBtFVpJlyTVB1Kk42Fl748ngJZpT6WqQ5w21o8ABZAo

To claim this, I am signing this object:

@daveio
daveio / foo.rb
Last active February 15, 2020 18:54
ruby 'in' keyword abuse
# hi
# let's imagine we have this kind of structure for a website user. the user can add arbitrary websites,
# which are stored in the userdata[:websites] hash as { :user_selected_name => 'https://example.com' }.
userdata = {
username: 'dave',
websites: {
homepage: 'https://dave.io',
twitter: 'https://twitter.com/syn'
@daveio
daveio / dantemagic.sh
Created January 15, 2021 17:12
dante sending socks requests out alternate interface
# get dante to use uid 'proxy' for priv and unpriv
# echo "201 fastlane" >> /etc/iproute2/rt_tables
ip rule add fwmark 0x1 table fastlane
ip route add default via 10.0.104.1 dev fastlane table fastlane
iptables -A OUTPUT -t mangle ! -d 10.0.101.0/24 -m owner --uid-owner proxy -j MARK --set-mark 1
iptables -t nat -A OUTPUT -m owner --uid-owner proxy -p udp --dport 53 -j DNAT --to 10.0.104.1:53
iptables -t nat -A OUTPUT -m owner --uid-owner proxy -p tcp --dport 53 -j DNAT --to 10.0.104.1:53
@daveio
daveio / mastodon-maintenance.sh
Last active June 23, 2024 19:14
Mastodon maintenance
#!/bin/bash
set -euxo pipefail
clear
RAILS_ENV=production bin/tootctl preview_cards remove --days=7
RAILS_ENV=production bin/tootctl maintenance fix-duplicates
RAILS_ENV=production bin/tootctl media remove-orphans
RAILS_ENV=production bin/tootctl media remove --days=7
@daveio
daveio / rust-tutorial.md
Last active March 7, 2025 21:38
Rust Tutorial

Learn You A Rust

Welcome! In this tutorial, we'll walk through building a Rust CLI application that clones GitHub repositories and downloads GitHub release binaries. This guide is written for developers experienced with Python or Ruby who are new to Rust. We'll introduce key Rust concepts as they come up – including ownership, borrowing, lifetimes, and error handling with Result and Option – and highlight Rust best practices for project structure and code clarity. By the end, you'll have a working CLI tool and a solid understanding of fundamental Rust principles.

What our CLI tool will do:

  • Parse command-line arguments using the clap crate.
  • Read a configuration file in TOML format (with serde and toml) to get a list of repos and binaries to manage.
  • Clone GitHub repositories (supporting both using the Git CLI or the libgit2 library for cloning).
  • Download the latest release binaries from GitHub and install them to `~/.l
@daveio
daveio / wipe-workflows.fish
Last active March 10, 2025 19:27
Remove all workflow runs from a GitHub repository
function wipe-workflows -d "Wipe all workflow runs for a GitHub repository. Invoke with username/reponame as a parameter."
set -lx REPONAME $argv[1]
echo "Wiping all workflow runs for $REPONAME..."
gh api --paginate "/repos/$REPONAME/actions/runs" | jq '.workflow_runs.[].id' | \
parallel -j 16 "echo {}; gh api --silent -X DELETE /repos/$REPONAME/actions/runs/{}"
end
@daveio
daveio / downloader.py
Last active March 14, 2025 01:50
Gmail downloader
#!/usr/bin/env python3
"""
Gmail Downloader
This script downloads all emails from a Gmail account using IMAP and saves them as JSON files.
It includes features for handling connection drops, resuming downloads, and robust error recovery.
The script can handle various charset encoding issues and maintains state between runs to allow
resuming after interruptions. It also logs problematic emails rather than failing on them.