Skip to content

Instantly share code, notes, and snippets.

View lordmauve's full-sized avatar
👨‍👧‍👧
Young children, minimal free time

Daniel Pope lordmauve

👨‍👧‍👧
Young children, minimal free time
View GitHub Profile
@lordmauve
lordmauve / gha-detect-new-version.yml
Created February 16, 2024 23:46
Detect new versions of Python packages in GHA
name: Check Version Change and Tag
on: [push]
jobs:
tag-version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
@lordmauve
lordmauve / millionth_fib.py
Created July 17, 2022 12:21
High level vs low level languages
def fib():
a = 0
b = 1
while True:
yield a
a, b = b, a + b
for i, v in enumerate(fib(), start=1):
if i == 1_000_000:
@lordmauve
lordmauve / pick2py.py
Created May 28, 2021 16:12
Convert a Python pickle to equivalent Python source code
# Copyright 2021 Two Sigma Open Source LLC.
#
# 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
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
@lordmauve
lordmauve / rdgpydojo9.py
Created May 10, 2021 21:31
Listen and mimic an audio tone, created at the Reading Python Dojo
import math
import numpy
import pyaudio
import analyse
import pygame
from pygame import *
import pygame, time, numpy, pygame.sndarray
sample_rate = 44100
@lordmauve
lordmauve / benchmark.py
Created July 23, 2020 14:42
Benchmark script for various vector classes
"""Benchmarks for vector classes in Python"""
from timeit import Timer
def timeit(name, stmt):
defs = dict(
v=v,
a=v(1.0, 2.0),
b=v(-1.0, -1.0),
)
@lordmauve
lordmauve / bounce.py
Created May 30, 2020 11:27
Bouncing balls in Pygame
# 1000 balls find an equilibrium spatial hash collision
# credit to Daniel Pope for showing me the light :)
# fb.com/groups/pygame
import pygame
import random, math
from itertools import product
from pygame.math import Vector2 as v2
import colorsys
@lordmauve
lordmauve / plinko-numpy.py
Created May 23, 2020 07:04
Plinko implemented with numpy and threads
# Created by Anthony Cook
# fb.com/groups/pygame
import pygame
from pygame import gfxdraw
import random
import numpy as np
import time
import os
from itertools import product, count
@lordmauve
lordmauve / plinko-spatial.py
Last active May 23, 2020 06:34
Plinko game by Anthony Cook, adapted to use a Spatial Hash
# Created by Anthony Cook
# fb.com/groups/pygame
import pygame
from pygame import gfxdraw
import random
import os
import time
from itertools import product
@lordmauve
lordmauve / freetype_combining.py
Created October 19, 2019 08:56
Simple test of combining characters in pygame.freetype
import sys, os
import pygame
from pygame.locals import *
from unicodedata import normalize
try:
import pygame.freetype as freetype
except ImportError:
print("No FreeType support compiled")
sys.exit()
@lordmauve
lordmauve / check_dubious_concat.py
Created April 8, 2016 14:19
Linter for implicit string literal concatentation in list-like context
def check_dubious_concat(src):
"""Check for suspicious string literal concatenation.
We will warn about instances of string literal concatenation in list-like
contexts - that is, where concatenated string literals are adjacent to
commas or inside square brackets.
Such a heuristic will catch instances like this::
foo = [