Skip to content

Instantly share code, notes, and snippets.

View pong.py
#
# http://programarcadegames.com/python_examples/show_file.php?file=pong.py
#
import math
import pygame
import random
from ctypes import windll, Structure, c_long, byref
user32 = windll.user32
screensize = user32.GetSystemMetrics(78), user32.GetSystemMetrics(79)
@arpruss
arpruss / accrete.py
Last active Feb 22, 2020
accrete falling pixels
View accrete.py
# public domain
import pygame
from random import randint
width = 400
height = 400
screen = pygame.display.set_mode((width, height))
color = (255,255,255)
@arpruss
arpruss / lsi.py
Created Feb 3, 2020
Look for a counterexample for a conjecture regarding Level Set Integrals
View lsi.py
from random import *
pa = 0.25
pb = 0.25
def E(f):
fa,fb = f
return fa + (fb-fa) * pb if fa < fb else fb + (fa-fb) * pa
def r():
@arpruss
arpruss / saitekmouse.py
Last active Jan 3, 2020
Saitek x45 mouse emulation
View saitekmouse.py
import sys
import time
import win32gui, win32con, win32api, win32file, win32event, win32gui_struct, winnt
import threading
from pywinusb import hid
RIGHT_CLICK = 1<<(5-1)
LEFT_CLICK = 1<<(6-1)
ACTIVE = 1<<(11-1)
UP = 1<<(23-1)
@arpruss
arpruss / vote.py
Last active Jan 15, 2020
Black's or Nanson's voting algorithm
View vote.py
import sys
#
# MIT Licensed code by Alexander R Pruss
#
# Implements Black's Procedure: Condorcet backed up with Borda to generate a ranked list from ranked votes
# and Nanson's Method: drop all candidates with Borda scores below average
#
# require n [default: None]
View amazon-offers.js
(function(){
var url = window.location.href;
var m = url.match("/(dp|gp/product)/([^/]+)");
var pid = undefined;
if(m) {
var pid = m[2];
var s = url.match("[^:]*://[^/]+")[0];
window.open(s+"/gp/offer-listing/"+pid);
}})();
@arpruss
arpruss / cec-to-keyboard.py
Last active Jan 17, 2020
cec to keyboard map
View cec-to-keyboard.py
#!/usr/bin/python3
import cec
from time import sleep, time
from evdev import UInput, ecodes
import os
import sys
from threading import Thread
DEBUG = False
logfile = sys.stdout
@arpruss
arpruss / ctrlwmonitor.py
Last active Jun 28, 2019
Runs specified commands on ctrl-w press
View ctrlwmonitor.py
import evdev
from select import select
from sys import argv, exit
from os import system
TRIGGER_KEY = evdev.ecodes.KEY_W
TRIGGER_MODIFIER_DISJUNCTIVE = set((evdev.ecodes.KEY_LEFTCTRL, evdev.ecodes.KEY_RIGHTCTRL))
keysDown = set()
@arpruss
arpruss / conciliatepriors.py
Last active Feb 19, 2019
averaging priors vs averaging posteriors
View conciliatepriors.py
from random import *
from math import *
def randomOpen():
while True:
r = random()
if 0 < r:
return r
class Grid(object):
View remote.py
# Volume and pause/play in Netflix and Acorn with Philips 642 DVD remote
# PageUp/Down with projector remote
import win32com.client
import win32api, win32con, win32gui
from espremote import ESPRemote
try:
from showtime import showtime
except:
pass
You can’t perform that action at this time.