Skip to content

Instantly share code, notes, and snippets.

View kupiakos's full-sized avatar

Alyssa Haroldsen kupiakos

View GitHub Profile
@kupiakos
kupiakos / zerocopy-example.md
Created July 28, 2023 14:40
Using zerocopy to convert types to and from bytes safely

Converting types to and from bytes

To convert types to and from bytes, we use the [zerocopy][zerocopy] library to do this safely. It primarily works through three core marker traits, which are implemented for primitive types and can be implemented for your own types with #[derive()]. They indicate what operations can be done on a type:

  • FromBytes indicates that a type may safely be converted from an arbitrary byte sequence. This means that every possible byte pattern is valid for that type - as such, this cannot be implemented for most enums.
  • AsBytes indicates that a type may safely be converted to a byte sequence.

Keybase proof

I hereby claim:

  • I am kupiakos on github.
  • I am kupiakos (https://keybase.io/kupiakos) on keybase.
  • I have a public key whose fingerprint is BF8B 59CE 8374 DBC8 1AC2 9D3C C1D4 3091 9DB7 7547

To claim this, I am signing this object:

@kupiakos
kupiakos / d20.py
Created January 13, 2018 21:26
Dice roll in the d20 format
import re
from operator import pos, neg
from random import randint
def rolld20(fmt):
"""Perform a dice roll in the d20 format (e.g. 5d8-3)"""
x = 0
op = pos
for part in re.findall(r'(\d*d\d+|\d+|\+|-)', fmt):
@kupiakos
kupiakos / it567-installwin.ps1
Last active February 5, 2018 23:57
Install chocolatey and desired packages on the IT 567 Lab Computers
# Run in Administrator PowerShell
# First: Set-ExecutionPolicy RemoteSigned -Force
# Or: Set-ItemProperty -Path HKLM:\Software\Policies\Microsoft\Windows\PowerShell -Name ExecutionPolicy -Value RemoteSigned
# Then: iwr -UseBasicParsing https://gist.githubusercontent.com/kupiakos/1763617c76c1a13e7d496b4c4e72d691/raw/it567-installwin.ps1 | iex
function Check-Command($cmd) {
try {
$ErrorActionPreference = "Stop"
Get-Command $aoeu
@kupiakos
kupiakos / requirements.txt
Last active January 21, 2018 03:01
/r/upvoteexeggutor full subreddit generator script
Pillow
praw==3.4.0
@kupiakos
kupiakos / embeddedqtconsole.py
Created August 14, 2015 04:48
Must press Shift-Enter to execute commands with in-process embedded qtconsole (IPython 4.0.0)
def openInteractiveGui():
from qtconsole.rich_jupyter_widget import RichJupyterWidget
from qtconsole.inprocess import QtInProcessKernelManager
from IPython.lib import guisupport
app = guisupport.get_app_qt4()
kernel_manager = QtInProcessKernelManager()
kernel_manager.start_kernel()
kernel = kernel_manager.kernel