Skip to content

Instantly share code, notes, and snippets.

pathunstrom /
Last active Apr 26, 2022
Sample Fizz Buzzes
def fizzbuzz_generator():
value = yield
while True:
rv = ""
if not value % 3:
rv += "Fizz"
if not value % 5:
rv += "Buzz"
value = yield rv or value
pathunstrom /
Created Jun 23, 2020
A simple model of a deck of cards.
import enum
from collections import UserList
from dataclasses import dataclass
from itertools import product
from random import shuffle
from random import choice
from typing import List
class Suit(enum.Enum):
CLUBS = "♣"
pathunstrom /
Last active Mar 10, 2020
A one line PursuedPyBear demo. Because we can.
(lambda ppb: scene: scene.add(s := ppb.Sprite(position=ppb.Vector(0, -4), image=ppb.Image("player.png"), on_update=lambda update, signal: setattr(s, 'position', s.position + (ppb.Vector(0, 1) * update.time_delta))))))(__import__("ppb"))
from functools import partial
from flask import Flask
from flask import jsonify
from flask import render_template
from flask import request
app = Flask(__name__)
View player.png
# Assume this is an image file.
pathunstrom /
Created May 14, 2018
Testing various ways to make safe iteration on sets
from copy import copy
from timeit import timeit
count = 1000000
test_set = {str(x) for x in range(100)}
snippets = {
"list_comprehension": "list(list(test_set))",
"method intersection": "list(test_set.intersection(test_set))",
"copy": "list(copy(test_set))",
from typing import Iterable
import pygame as pg
class Target(pg.sprite.Sprite):
def __init__(self, image: pg.Surface, position: Iterable[int]):
"""position needs to be length 2."""
self.image = image