Skip to content

Instantly share code, notes, and snippets.

@pathunstrom
pathunstrom / cards.py
Created June 23, 2020 16:39
A simple model of a deck of cards.
View cards.py
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
pathunstrom / main.py
Last active March 10, 2020 20:28
A one line PursuedPyBear demo. Because we can.
View main.py
(lambda ppb: ppb.run(setup=lambda 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"))
@pathunstrom
pathunstrom / README.md
Last active April 2, 2019 20:36
SCRIPT-8
View README.md
View README.md
View README.md
@pathunstrom
pathunstrom / app.py
Created August 9, 2018 00:35
API Demo
View app.py
from functools import partial
from flask import Flask
from flask import jsonify
from flask import render_template
from flask import request
app = Flask(__name__)
@pathunstrom
pathunstrom / player.png
Created June 5, 2018 13:50
cool game code
View player.png
# Assume this is an image file.
@pathunstrom
pathunstrom / test_set_copy.py
Created May 14, 2018 18:38
Testing various ways to make safe iteration on sets
View test_set_copy.py
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))",
View hovertext.py
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."""
super().__init__()
self.image = image
View music_game.py
import time
import pygame
WHITE = 255, 255, 255
BLACK = 0, 0, 0
whole_note_image = pygame.Surface((20, 20))
whole_note_rect = whole_note_image.get_rect()
whole_note_image.fill(WHITE)