Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
I may be slow to respond.

Spencer Phillip Young spyoungtech

💭
I may be slow to respond.
View GitHub Profile
View unasync-rewrite.py
"""
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
spyoungtech / 1.README.md
Last active Jun 26, 2022
Adaptive sound - Keyboard Inputs from audio pitch
View 1.README.md

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\adaptivesound.py -- in 5 seconds recording will start
  5. Open the window you want to send input to
@spyoungtech
spyoungtech / 0.example.py
Last active Sep 21, 2022
Parse docker repo info
View 0.example.py
from parse_repo import parse
with open('6.0.5.md') as f:
text = f.read()
images = parse(text)
for image in images:
print('Image Digest:', image.digest)
print('Layers:')
for layer in image.layers:
print('\t', "Digest:", layer.digest)
print('\t', "Size:", layer.size)
@spyoungtech
spyoungtech / upgradewsl.ps1
Last active Jun 1, 2020
Upgrade all WSL distros to version 2
View upgradewsl.ps1
$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
spyoungtech / generate.py
Last active May 26, 2020
generate json
View generate.py
# 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
spyoungtech / download_emotes.py
Last active Sep 30, 2021
Download twitch emotes from twitchemotes.com channel
View download_emotes.py
import os
from requests import Session
from bs4 import BeautifulSoup
requests = Session()
class EmoteNotFoundError(RuntimeError):
...
View lovely_printer.py
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
spyoungtech / appveyor_lambda_codedeploy.py
Created Jun 22, 2018
A lambda function intended to be triggered by S3 object creations made by Appveyor S3 deployments
View appveyor_lambda_codedeploy.py
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
spyoungtech / parse_dates.py
Last active Mar 29, 2018
Decorate a function to automatically convert specified arguments from strings to datetimes
View parse_dates.py
"""
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
spyoungtech / pokemon_scraper.py
Last active Nov 5, 2019
A webscraping example
View pokemon_scraper.py
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