Skip to content

Instantly share code, notes, and snippets.

Avatar

René Dudfield illume

View GitHub Profile
@illume
illume / flask_matplotlib.py
Last active Sep 12, 2021
Shows how to use flask and matplotlib together.
View flask_matplotlib.py
""" Shows how to use flask and matplotlib together.
Shows SVG, and png.
The SVG is easier to style with CSS, and hook JS events to in browser.
python3 -m venv venv
. ./venv/bin/activate
pip install flask matplotlib
python flask_matplotlib.py
"""
@illume
illume / image_save.py
Created Feb 12, 2017
A tool for saving files to and from a postgresql db BYTEA table.
View image_save.py
"""A tool for saving files to and from a postgresql db.
"""
import os
import sys
import argparse
import psycopg2
db_conn_str = "postgresql://username:password@localhost:5432/dbname"
create_table_stm = """
CREATE TABLE files (
@illume
illume / reinitbug.py
Created Feb 14, 2021
press g key, see key repeat is slow. Press f key, then pressing g key means the key repeat is fast (broken).
View reinitbug.py
"""
Manual test for pygame #2100
Press F to quit and restart the screen
"""
import pygame
#pygame.init() # <- problem doesn't happen at all with this
@illume
illume / custom_events.py
Created Mar 16, 2018
pygame custom events, arudino serial ports.
View custom_events.py
# Shows how to send custom events with pygame.
# AND serial port data (from perhaps an arduino).
# It sends the serial data into pygame (with custom events).
# The SERIAL event is only posts when it receives a new line.
# NOTE: No error correction is done here. Serial data can corrupt.
import pygame as pg
import serial
ser = serial.Serial('/dev/tty.usbmodem1411', 9600, timeout = 0)
@illume
illume / decision_tree.py
Created Jun 3, 2020
Decision trees in python using recursion and eval.
View decision_tree.py
# Decision trees in python using recursion and eval.
TREE_SIMPLE = {
"expression": 'state["x"] > 1',
True: {"result": "b"},
False: {"result": "a"},
}
def decide(state, node):
return (
View sdl2-mac-10-11.patch
--- src/video/cocoa/SDL_cocoavideo.h.orig Sat Jul 27 20:21:42 2019 +0200
+++ src/video/cocoa/SDL_cocoavideo.h Tue Jul 30 10:04:46 2019 -0700
@@ -113,9 +113,8 @@
/* Utility functions */
extern NSImage * Cocoa_CreateImage(SDL_Surface * surface);
-/* Fix build with the 10.10 SDK */
-#if MAC_OS_X_VERSION_MAX_ALLOWED < 101100
-#define NSEventSubtypeTouch NSTouchEventSubtype
+/* Fix build with the 10.11 SDK */
View install_python.ps1
# Install specified Python version.
# Install only if:
# Our current matrix entry uses this Python version AND
# Python version is not already available.
# from https://raw.githubusercontent.com/matthew-brett/multibuild/11a389d78892cf90addac8f69433d5e22bfa422a/install_python.ps1
$py_exe = "${env:PYTHONPATH}\Python.exe"
if ( [System.IO.File]::Exists($py_exe) ) {
echo "$py_exe exists"
exit 0
@illume
illume / midimusic.py
Created Oct 14, 2019
How to play midi music with pygame.mixer.music.
View midimusic.py
# midimusic.py
# curl -O https://upload.wikimedia.org/wikipedia/commons/5/55/MIDI_sample.mid
import time, sys, pygame
pygame.mixer.init()
pygame.mixer.music.load('MIDI_sample.mid')
pygame.mixer.music.play()
while pygame.mixer.music.get_busy():
print('Still playing :)')
View fullscreen_toggle.py
import pygame
from pygame.locals import *
pygame.init()
RES=(160, 120)
FPS=30
clock = pygame.time.Clock()
@illume
illume / play_audio_layer.py
Last active Jul 14, 2019
headless pygame (without a window) playing two sounds at different times.
View play_audio_layer.py
""" headless pygame (without a window) playing two sounds one after the other.
"""
import os, sys, time
import pygame
import pygame.examples
# a pretend video.
os.environ["SDL_VIDEODRIVER"] = "dummy"