Skip to content

Instantly share code, notes, and snippets.

@arpruss
arpruss / dmapwm.ino
Created October 26, 2017 14:59
Arduino stm32f1 code to do PWM with DMA
#include <dma_private.h>
#define PIN_TO_PULSE PB12
#define DMA_PWM_MAX_DUTY 32
uint32_t data[DMA_PWM_MAX_DUTY];
void setDMAPWM(uint32_t pin, uint32_t duty_cycle) {
gpio_dev *dev = digitalPinToPort(pin);
uint32_t maskOn = digitalPinToBitMask(pin);
@arpruss
arpruss / template.py
Last active August 14, 2018 17:32
Process wildcard templates to generate Arduino board files
import re
import sys
dict = {}
overrideDict = {}
ignore = set()
unknown = []
equalRE = re.compile(r'\s*([^<=\s]+)\s*\=\s*(.*)')
copyRE = re.compile(r'\s*([^<=\s]+)\s*\<\=\s*(.*)')
@arpruss
arpruss / bitbandgpio.ino
Last active November 26, 2017 21:15
stm32f1 bitbanding gpio
#define BITBAND_SRAM_BASE 0x22000000u
#define SRAM_START 0x20000000u
#define BITBAND_PERIPHERAL_BASE 0x42000000u
#define PERIPHERAL_START 0x40000000u
#define BITBAND_SRAM(address, bit) ( *(volatile uint32*)( BITBAND_SRAM_BASE + ((uint32)(address)-SRAM_START) * 32u + (uint32)(bit)*4u) )
#define BITBAND_PERIPHERAL(address, bit) *( (volatile uint32*)( BITBAND_PERIPHERAL_BASE + ((uint32)(address)-PERIPHERAL_START) * 32u + (uint32)(bit)*4u) )
#define GPIO_OFFSET(gpioLetter) (0x400u * (uint32)((gpioLetter)-'A'))
#define BITBAND_GPIO_INPUT(gpioLetter, bit) BITBAND_PERIPHERAL((uint32)&(GPIOA_BASE->IDR)+GPIO_OFFSET(gpioLetter), (bit))
#define BITBAND_GPIO_OUTPUT(gpioLetter, bit) BITBAND_PERIPHERAL((uint32)&(GPIOA_BASE->ODR)+GPIO_OFFSET(gpioLetter), (bit))
@arpruss
arpruss / grab.py
Last active January 11, 2018 19:48
screenshot grabber
import PIL
import PIL.ImageGrab
import os.path
import sys
import keyboard
import ctypes.wintypes
from getopt import getopt
def makefilename(base):
if base.lower().endswith(".png"):
@arpruss
arpruss / stretchvideo.js
Last active July 11, 2023 18:05
Bookmarklet to change aspect ratio of html5 video
document.dispatchEvent(new Event('mobi.omegacentauri.killStretchVideoEvent'));
var vid = document.getElementsByTagName('video');
if (vid.length == 0) {
alert("No video elements found in this page.");
}
else {
var mode = prompt("Enter one of these:\n"+
"(a) horizontal,vertical : a pair of scale ratios\n"+
"(b) horizontal:vertical : the correct aspect ratio for a badly encoded video\n", "1,1");
@arpruss
arpruss / videorate.js
Created August 12, 2018 20:58
Video playback rate bookmarklet
var vid = document.getElementsByTagName('video');
if (vid.length == 0) {
alert("No video elements found in this page.");
}
else {
var rate = prompt("Enter rate", vid[0].playbackRate);
if (rate != null)
for(let v of vid)
v.playbackRate = rate;
}
@arpruss
arpruss / loadbookmarklet.js
Created August 12, 2018 21:06
Make bookmarklet available from gist
function bookmarklet(linkId, gistRawLink) {
fetch(gistRawLink).then(function(response) {
if (!response.ok) {
//alert("Error fetching "+response.statusText);
}
else {
response.text().then(function(text) {
var link = document.getElementById(linkId);
link.href = "javascript:"+encodeURIComponent("(function(){"+text+"})()");
});
@arpruss
arpruss / disablezoomcontrol.js
Last active August 13, 2018 00:33
Disable zoom control
var meta = document.querySelector('meta[name="viewport"]');
if (meta != null)
meta.content = 'min-width=10, max-width=10000, min-height=10, max-height=10000, initial-scale=1.0, maximum-scale=50.0, minimum-scale=0.02, user-scalable=1';
/**
The MIT License (MIT)
Copyright (c) 2015 Don McCurdy
Copyright (c) 2018 Alexander Pruss
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
@arpruss
arpruss / remote.py
Created November 26, 2018 04:18
espremote
# 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