Skip to content

Instantly share code, notes, and snippets.

Avatar
🦀
cargo install coffee

Reilly Tucker Siemens reillysiemens

🦀
cargo install coffee
View GitHub Profile
@reillysiemens
reillysiemens / bitmask_battleship.rs
Created Mar 3, 2021
Battleship, but it's an int.
View bitmask_battleship.rs
//! # Bitmask Battleship
//!
//! The ship sections and their status are maintained in a 17-bit mapping. A
//! zero bit means the section is OK and a one means the section has been hit.
//!
//! ```text,ignore
//! 1
//! 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
//! | C | b | c | s | d |
@reillysiemens
reillysiemens / signing-vbox-kernel-modules.md
Last active Mar 24, 2021
Signing VirtualBox Kernel Modules
View signing-vbox-kernel-modules.md

Signing VirtualBox Kernel Modules

These are the steps I followed enable VirtualBox on my laptop without disabling UEFI Secure Boot. They're nearly identical to the process described on [Øyvind Stegard's blog][blog], save for a few key details. The images here are borrowed from the [Systemtap UEFI Secure Boot Wiki][systemtap].

  1. Install the VirtualBox package (this might be different for your platform).
    src='https://download.virtualbox.org/virtualbox/rpm/fedora/virtualbox.repo'
@reillysiemens
reillysiemens / instructions.md
Last active Dec 28, 2018
Create a Windows 10 USB image from Fedora 29
View instructions.md

Instructions

The URL https://git.io/this-time-for-real-tho links to the win10-usb.sh script below. It created something bootable from my Fedora 29 workstation.

Try to run

curl -L https://git.io/this-time-for-real-tho | sh

and if that doesn't work try explicitly setting an environment variable for the location of the .iso file

@reillysiemens
reillysiemens / README.md
Created Dec 19, 2018
Python Typing Optional String Callback
View README.md

The Python here works just fine, but mypy doesn't like it...

example.py:14: error: Argument 1 to "callback" has incompatible type "Optional[str]"; expected "str"

The if url is None: conditional should prevent the url in the else block from ever being None, but maybe it doesn't work like that? Or I'm just wrong...

@reillysiemens
reillysiemens / README.md
Created Dec 19, 2018
Python Typing Protocol Default Class
View README.md

This is perfectly fine Python. It outputs

Opening...
Opening...
1337
Closing...

when run, but Mypy complains...

example.py:29: error: Incompatible default for argument "cls" (default has type "Type[Concrete]", argument has type "SupportsOpenClose")
@reillysiemens
reillysiemens / callback.py
Created Dec 18, 2018
Python Callback Type Annotation
View callback.py
def fn(
url: str,
state: State,
payload_type: PayloadType,
verify: bool = True,
method: Callable[..., Response] = requests.post,
) -> None:
"""
Given a function with the above signature, how can the type of
``method`` be made more specific?
View nag_isp.py
#!/usr/bin/env python3.6
# Copyright © 2018, Reilly Tucker Siemens <reilly@tuckersiemens.com>
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
View minecraft-backup.sh
#!/bin/sh
: ${MINECRAFT_WORLD="survival"}
src="/srv/${MINECRAFT_WORLD}/world"
dst="/var/games/minecraft/${MINECRAFT_WORLD}.txz"
send_command() {
world=$1
cmd=$2
@reillysiemens
reillysiemens / avatar.md
Last active Sep 17, 2017
Generate a PNG with the remote IP address in it.
View avatar.md

avtar.png

These files are web applications that generate PNGs on request containing a friendly greeting with the IP address of the requester.

The PHP was originally written by Andrew Kvalheim probably around 2010. Its filename at that time was avatar.png, so as to give the illusion that it was a static file.

I wrote the Python many years later in an attempt to understand what Andrew had

@reillysiemens
reillysiemens / README.md
Last active Jul 19, 2017
Testing Click Applications with Pytest
View README.md

Requirements

  • Python 3.6
  • pip
  • virtualenvwrapper

Instructions

Copy these files into a directory. Run the tests.

mkvirtualenv greet && pip install -e .'[dev]' && pytest -v