Skip to content

Instantly share code, notes, and snippets.

View spyoungtech's full-sized avatar

Spencer Phillip Young spyoungtech

View GitHub Profile
spyoungtech /
Last active July 13, 2022 02:08
unasync rewriter
remove code from unasync-generated code wherever there is a `unasync: remove` comment is placed
MIT License
Copyright (c) 2022 Spencer Phillip Young
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
spyoungtech /
Last active June 26, 2022 12:08
Adaptive sound - Keyboard Inputs from audio pitch

How to use

(Windows only)

  1. Download the files from this gist
  2. Install Python (using default options is OK)
  3. In command prompt, type py -m pip install --prefer-binary -r C:\path\to\requirements.txt (replacing the actual path to the requirements.txt file you downloaded from this gist)
  4. In the command prompt, type py C:\path\to\ -- in 5 seconds recording will start
  5. Open the window you want to send input to
spyoungtech /
Last active October 3, 2022 16:48
Parse docker repo info
from parse_repo import parse
with open('') as f:
text =
images = parse(text)
for image in images:
print('Image Digest:', image.digest)
for layer in image.layers:
print('\t', "Digest:", layer.digest)
print('\t', "Size:", layer.size)
spyoungtech / upgradewsl.ps1
Last active June 1, 2020 11:19
Upgrade all WSL distros to version 2
$oldversion = "1"
$newversion = "2"
$output = wsl -l -v
$distros = $output -replace "`0",'' | ConvertFrom-String -PropertyNames Active,Name,State,Version | where {$_.Version -ne "VERSION"}
$outdated = $distros | where {$_.Version -like $oldversion}
$outdated | ForEach-Object {wsl --set-version $_.Name $newversion}
spyoungtech /
Last active May 26, 2020 04:59
generate json
# Make sure to pip install json-five
from functools import singledispatch, update_wrapper
from json5.model import *
from json5.dumper import ModelDumper
import json5
import random
import string
VALUE_MODELS = [Integer, JSONObject, JSONArray, DoubleQuotedString, SingleQuotedString, Float, NullLiteral,
BooleanLiteral, Infinity, NaN, UnaryOp]
spyoungtech /
Last active October 23, 2022 12:56
Download twitch emotes from channel
import os
from requests import Session
from bs4 import BeautifulSoup
requests = Session()
class EmoteNotFoundError(RuntimeError):
import builtins
from textwrap import dedent
from unittest import mock
from contextlib import contextmanager
from itertools import cycle
_print = builtins.print
TEMPLATE_HEART = dedent('''
#### ####
# # # #
spyoungtech /
Created June 22, 2018 16:54
A lambda function intended to be triggered by S3 object creations made by Appveyor S3 deployments
import boto3
client = boto3.client('codedeploy')
def lambda_handler(event, context):
s3_event = event['Records'][0].get('s3')
bucket_name = s3_event['bucket']['name']
key = s3_event['object']['key']
etag = s3_event['object']['eTag']
spyoungtech /
Last active March 29, 2018 20:22
Decorate a function to automatically convert specified arguments from strings to datetimes
Decorator to convert string arguments into datetimes automatically.
The decorated function will also still accept datetime objects per normal.
Useful for commandline tools, for example.
import dateutil.parser
import datetime
@parse_dates('start', 'some_date')
def days_until(some_date, start=None):
if start_time is None:
spyoungtech /
Last active November 5, 2019 11:27
A webscraping example
import re
import json
import requests
from pprint import pprint
from bs4 import BeautifulSoup
def type_section(tag):
"""Find the tags that has the move type and pokemon name"""
pattern = r"[A-z]{3,} Type: [A-z]{3,}"
# if all these things are true, it should be the right tag