Skip to content

Instantly share code, notes, and snippets.

Avatar

René Dudfield illume

View GitHub Profile
@illume
illume / python_close.py
Created Oct 21, 2011
# closures in python
View python_close.py
# closures in python
def f0(x):
closed_var = x + 1
def fclose():
return closed_var
return fclose
a_closure = f0(9)
# the 'closed_var' is now x + 1 == 10
View process_images.py
'''
How to download and cut up the video (requires python3 and ffmpeg)
virtualenv-3.4 anenv
. ./anenv/bin/activate
pip3.4 install you-get
you-get https://vimeo.com/45878034
ffmpeg -i View\ from\ the\ ISS\ at\ Night\ from\ Knate\ Myers\ on\ Vimeo.mp4 -ss 00:02:36 -t 00:00:10 -c copy source-video.mp4
@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 / circle.py
Created Feb 9, 2018
For testing out drawing pygame circles with thicknesses.
View circle.py
import pygame
def draw_outlined_circle2(surf, color, origin, radius, thickness):
width = radius * 2 + thickness * 2
background = (0, 0, 0, 0)
circle = pygame.Surface((width, width)).convert_alpha()
rect = circle.get_rect()
circle.fill(background)
pygame.draw.circle(circle, color, rect.center, radius)
pygame.draw.circle(circle, background, rect.center, radius - thickness)
@illume
illume / circle.py
Created Feb 19, 2018
circle.py thick circle bug
View circle.py
#circle.py
import pygame
def draw_outlined_circle2(surf, color, origin, radius, thickness):
width = radius * 2 + thickness * 2
background = (0, 0, 0, 0)
circle = pygame.Surface((width, width)).convert_alpha()
rect = circle.get_rect()
circle.fill(background)
pygame.draw.circle(circle, color, rect.center, radius)
@illume
illume / weirdomouse.py
Created Mar 1, 2018
See if there are weird mouse coordinates in the corners?
View weirdomouse.py
import pygame
pygame.init()
pygame.display.set_mode((500, 400), 0, 32)
while True:
for event in pygame.event.get():
print(event)
@illume
illume / sound_samples.py
Last active Mar 15, 2018
Plays short Tone using only pygame + python builtin 'array' type.
View sound_samples.py
""" Some examples for generating and converting sounds for pygame.
Python 2.7, 3.6
Shows:
- a simple 'square wave' generated
- resampling sample rates (eg, 8363 to 44100)
- using built in python array for making pygame.Sound samples.
- samples at different bit sizes
- converting from signed 8 to signed 16bit
@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 / invertit.py
Last active Apr 18, 2018
Shows the invert function.
View invertit.py
import os
import pygame as pg
main_dir = os.path.split(os.path.abspath(__file__))[0]
# data_dir = os.path.join(main_dir, 'data')
data_dir = main_dir
def show(image):
screen = pg.display.get_surface()
screen.fill((0, 255, 255))
@illume
illume / portmidi.rb
Last active May 17, 2018
portmidi homebrew formular without broken python
View portmidi.rb
class Portmidi < Formula
desc "Cross-platform library for real-time MIDI I/O"
homepage "https://sourceforge.net/projects/portmedia/"
url "https://downloads.sourceforge.net/project/portmedia/portmidi/217/portmidi-src-217.zip"
sha256 "08e9a892bd80bdb1115213fb72dc29a7bf2ff108b378180586aa65f3cfd42e0f"
revision 1
bottle do
cellar :any
sha256 "c8f2755fd775064c282da84d666336d9125c6e70082975ffdc0867dee60b5802" => :high_sierra