Skip to content

Instantly share code, notes, and snippets.

View jasonbot's full-sized avatar
🥉

Jason Scheirer jasonbot

🥉
View GitHub Profile
local class = require("middleclass/middleclass")
local Keyboard = class("Keyboard")
function Keyboard:initialize()
self.keys = {}
self.keypresses = {}
function love.keypressed(key)
-- set time pressed down to 0 for key
@jasonbot
jasonbot / github_access_token_for_app_install.py
Last active April 27, 2023 10:42
Get a github3 client instance for an app installation
def get_github3_client():
"""See
https://developer.github.com/apps/building-github-apps/authenticating-with-github-apps/#authenticating-as-a-github-app
for an explanation of how/why this is like it is.
Requires requests, pyjwt, and github3. Make sure you intall a newer
version of cryptography for pyjwt as well."""
@jasonbot
jasonbot / thing.py
Created August 15, 2019 17:49
PYTHON LAZER
e = lambda x: "".join(u":lazer_{}:\u200b".format(c) if (c.isalpha() or c.isdigit()) else " {} ".format(c) for c in x.upper())
import urllib.parse
def order_query_string(url):
parsed_url = list(urllib.parse.urlparse(url))
# Put the query string params in determinisitic order.
# According to docs.python this is in [3], but docs.python is a liar.
parsed_url[4] = urllib.parse.urlencode(sorted(urllib.parse.parse_qsl(parsed_url[4])))
return urllib.parse.urlunparse(parsed_url)
import random
class TemperamentalClass(type):
@classmethod
def __instancecheck__(cls, other):
return random.choice([True, False])
class MyClass(metaclass=TemperamentalClass):
pass
Alpeppert
ampepperage
ampeppere
ampepperes
ampeppersand
ampeppersands
apepperiodic
apepperiodicity
apepperture
appeppertain
func RotateAround(pt, origin image.Point, angle float64) (int, int) {
x1, y1 := float64(pt.X-origin.X), float64(pt.Y-origin.Y)
magnitude := math.Hypot(x1, y1)
rotationAngle := math.Atan2(y1, x1) + angle
return origin.X + (int(math.Cos(rotationAngle) * magnitude)), origin.Y + (int(math.Sin(rotationAngle) * magnitude))
}
func RotatedImage(i *ebiten.Image, rotation float64) *ebiten.Image {
if i == nil {
func RotatedImage(i *ebiten.Image, rotation float64) *ebiten.Image {
if i == nil {
return i
}
w, h := i.Size()
maxDim := int(math.Hypot(float64(w), float64(h)))
newimage := ebiten.NewImage(maxDim, maxDim)
op := ebiten.DrawImageOptions{}
@jasonbot
jasonbot / to-parquet.py
Last active May 10, 2023 23:16
Consume a common crawn (WARC) file to parquet table
import gzip
import os
import pathlib
import warcio.archiveiterator
from bs4 import BeautifulSoup
import pandas
def warc_stream(stream):
@jasonbot
jasonbot / update_date_added.py
Last active June 13, 2023 23:38
Change the "date added" column in Rhythmbox's DB to the creation time of the music file
import pathlib
import xml.dom.minidom
path = pathlib.Path("~/.local/share/rhythmbox/rhythmdb.xml").expanduser()
out_path = path.parent / "new_rhythmdb.xml"
print("Updating date addeds in", path, "and outputting to", out_path)
d = xml.dom.minidom.parse(str(path))