Skip to content

Instantly share code, notes, and snippets.

@arpruss
arpruss / saitekmouse.py
Last active January 3, 2020 03:08
Saitek x45 mouse emulation
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 January 15, 2020 21:56
Black's or Nanson's voting algorithm
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]
@arpruss
arpruss / cec-to-keyboard.py
Last active January 17, 2020 22:52
cec to keyboard map
#!/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 / lsi.py
Created February 3, 2020 16:58
Look for a counterexample for a conjecture regarding Level Set Integrals
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 / accrete.py
Last active February 22, 2020 14:33
accrete falling pixels
# 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 / pong.py
Created March 15, 2020 16:53
pong
#
# 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)
/*
Multi BLE Sensor - Richard Hedderly 2019
Based on heart sensor code by Andreas Spiess which was based on a Neil
Kolban example.
Based on Neil Kolban example for IDF:
https://github.com/nkolban/esp32-snippets/blob/master/cpp_utils/tests/BLE%20Tests/SampleServer.cpp
Ported to Arduino ESP32 by Evandro Copercini
updates by chegewara
class ScratchGamepad {
constructor(runtime) {
this.id = null
this.runtime = runtime
this.currentMSecs = -1
this.previousButtons = []
this.currentButtons = []
}
getInfo() {
#!/usr/bin/python
# based on : www.daniweb.com/code/snippet263775.html
import math
import wave
import struct
# Audio will contain a long list of samples (i.e. floating point numbers describing the
# waveform). If you were working with a very long sound you'd want to stream this to
# disk instead of buffering it all in memory list this. But most sounds will fit in
# memory.
TIA 0
TIY 0
zeroLoop:
AM
AIY 1
CIY F
JUMP zeroLoop
mainLoop:
TIA 1
TIY -1