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 / lepton 64-bit bug
Created April 17, 2013 22:31
This patch fixes a bug in lepton on 64-bit architectures makes particles go everywhere and appear in all the wrong colours.
Index: lepton/renderermodule.c
===================================================================
--- lepton/renderermodule.c (revision 247)
+++ lepton/renderermodule.c (working copy)
@@ -59,6 +59,9 @@
/* Vertex data functions and structs */
+#pragma pack(push)
+#pragma pack(4)
@lordmauve
lordmauve / rot13.rs
Created April 27, 2014 13:44
ROT13 stdin to stdout in Rust
use std::io;
// Get the ROT13ed equivalent of char
fn rot13(c: char) -> char {
let base = match c {
'a'..'z' => 'a' as u8,
'A'..'Z' => 'A' as u8,
_ => return c
};
@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 = [
@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 / 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 / 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 / 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 / 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 / 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 / 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