Skip to content

Instantly share code, notes, and snippets.

@blha303
blha303 / digitalocean-torrentdl.sh
Last active January 27, 2021 08:32
Provisions a droplet on DigitalOcean to download a given torrent file, then reupload to a given rclone remote
#!/bin/bash
# Provisions a droplet on DigitalOcean to download a given torrent file, then reupload to a given rclone remote
# Prints estimated USD cost of transaction when complete
# uses your user's rclone.conf, so set up the remote locally and make sure it works
# torrentdl.sh https://releases.ubuntu.com/20.04/ubuntu-20.04.1-live-server-amd64.iso.torrent b2:my-linux-isos/ubuntu/
echo "Checking dependencies (wget, installed doctl, configured rclone)"
[ -s "$HOME/.config/rclone/rclone.conf" ] || (echo "Set up rclone (from rclone.org, not from package manager) with a remote, or write to ~/.config/rclone/rclone.conf, then run this script again"; exit)
if type doctl >/dev/null 2>&1; then
if ! doctl compute droplet list >/dev/null 2>&1; then
@blha303
blha303 / cahdiscord.py
Created November 13, 2019 03:56
A brief musing on the plausibility of a cards against humanity bot for discord
#!/usr/bin/env python
import discord
from json import load
from random import shuffle
client = discord.Client()
# https://github.com/crhallberg/json-against-humanity
with open("full.md.json") as f:
cards = load(f)
@blha303
blha303 / bandersnatch.py
Created September 9, 2019 16:41
Bandersnatch v2
#!/usr/bin/env python3
from random import choice
import json
from sys import stderr
with open("bandersnatch.json") as f:
bandersnatch = json.load(f)
with open("segmentmap.json") as f:
smap = json.load(f)
@blha303
blha303 / ffmpeg_flask_stream.py
Created August 20, 2019 07:32
A simple flask server to encode a specified video/audio file and stream the chunks with a generator
#!/usr/bin/env python3
from subprocess import Popen, PIPE
from flask import Flask, Response
import os.path
app = Flask(__name__)
PREFIX = "/media/storage"
FORMAT = ("mp3", "audio/mpeg")
def ffmpeg_generator(fn):
@blha303
blha303 / b64dec.py
Created August 3, 2019 06:47
a dumb pair of python scripts to encode/decode files as base64 when dragged or dropped. so i don't have to transfer binary files between servers, just paste into cat <<EOF
#!/usr/bin/env python
from base64 import b64decode
from sys import argv
for fn in argv[1:]:
with open(fn, "rb") as f:
with open(fn[:-4], "wb") as of:
of.write(b64decode(f.read()))
#!/usr/bin/env python3
from requests import post
import twitter # pip install python-twitter
from json import load
with open("twitter.json") as f:
api = twitter.Api(**load(f))
with open(".bottoken") as f:
token = f.read().strip()
@blha303
blha303 / wp-sitemap.php
Created July 24, 2019 01:09
Generates a sitemap.xml from Wordpress
<?php
include( './wp-load.php' );
header("Content-Type: application/xml");
?>
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <?php
foreach(get_pages() as $page) { ?>
<url>
<loc><?php echo get_page_link( $page->ID ); ?></loc>
<lastmod><?php echo date("Y-m-d", strtotime($page->post_modified)); ?></lastmod>
@blha303
blha303 / bandersnatch.md
Last active August 20, 2021 03:10
Code to make your own Black Mirror: Bandersnatch
@blha303
blha303 / hibp-sha1-check.py
Created June 12, 2019 12:21
Wrote this to check AD hashes against haveibeenpwned's sha1 password list
#!/usr/bin/env python
# input files:
# - hashlist.txt, a file containing the user hashes to check, in format username:hash, one per line.
# (or change the input to whatever you need it as)
# - pwned-passwords-sha1-ordered-by-count-v4.txt, get this from https://haveibeenpwned.com/Passwords
# any format is fine, just update the file name below
# the script will output percentage of the password file completed to stdout. compare this against your
# original password list, or modify the block at the end to further process the data
import os.path
inp_users = "hashlist.txt"
@blha303
blha303 / mediakeys.ahk
Last active June 11, 2019 09:04
I don't have media keys on my keyboard
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#InstallKeybdHook
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
; win+f4
#F4::MEDIA_NEXT
; win+f5
#F5::MEDIA_PLAY_PAUSE