Skip to content

Instantly share code, notes, and snippets.

@garcia
garcia / nativeosfs.py
Created December 22, 2021 17:56
Quick'n'dirty NativeOSFS implementation for pyfilesystem2
import io
import os
from typing import IO, Collection, Dict, Optional
import stat
from fs.base import FS
from fs.error_tools import convert_os_errors
from fs.info import Info
from fs.mode import Mode
from fs.osfs import OSFS

serumfrequencies.py

This script identifies the base position and Note modulation amount for a frequency knob to match the Note source in Xfer Records's Serum VST, allowing for creative use of tonal filters.

The default values for freq_max and freq_mid correspond to the Filter cutoff (the one in the OSC tab, not the FX module). They can be changed to find the values for other frequency knobs in Serum by identifying their maximum frequency (just crank the knob all the way up) and the exact midpoint frequency (assign the MIDI input value to 0.5 in your host, then click without dragging the knob). The script needs the midpoint frequency instead of the minimum frequency because the minimum (e.g. 8 Hz) isn't precise enough for this task.

Assign the two printed values to the frequency knob and the Note modulation amount for that knob, respectively, in your host application, then tweak the tuning frequency to account for imprecision in the base frequency. (You don't have to use your ears - play an A4, then

Keybase proof

I hereby claim:

  • I am garcia on github.
  • I am garcia (https://keybase.io/garcia) on keybase.
  • I have a public key whose fingerprint is D67C C76B 1CAE 1DB0 E55E 3465 EA5C 38CB F9A6 0617

To claim this, I am signing this object:

@garcia
garcia / plusorminus.py
Created January 31, 2015 04:37
Implements a plus-or-minus "operator", +OR-
import itertools
import math
class _OR(object):
def __radd__(self, lhs):
if isinstance(lhs, PlusOrMinus):
copy = PlusOrMinus(*lhs)
else:
copy = PlusOrMinus(lhs)
copy.plusorminus = True
#!/usr/bin/env python
def curry(f, args=None):
def curried(arg):
if args is None:
args_ = []
else:
args_ = args
args_.append(arg)
if len(args_) == f.__code__.co_argcount:
@garcia
garcia / selfreferencingtuple.py
Last active December 31, 2015 23:58
Self-referencing tuple in 32-bit CPython 2.7.
import ctypes
import struct
import sys
# Goal: obtain something like "outer = (outer,)", even though that's impossible with vanilla Python
inner = ()
outer = (inner,)
# Get CPython's internal representation of the outer tuple
c_outer = (ctypes.c_char * sys.getsizeof(outer)).from_address(id(outer))
@garcia
garcia / oppositeday.py
Created November 2, 2013 22:29
Swaps the values of False and True under CPython 2.7.5. Unlike the usual "False, True = True, False" prank, this alters the hardcoded values so that even built-in operations which return a boolean (like 1 == 1) return the opposite.
import ctypes
import sys
for b, boolean in enumerate((False, True)):
(ctypes.c_char * sys.getsizeof(boolean)).from_address(id(boolean))[8] = chr(1 - b)
@garcia
garcia / savephotos.py
Last active December 4, 2018 00:27
Save all photos from the tumblelog specified on the command-line using the Tumblr API v1. Requires the Python 'requests' module. Updated for a breaking API change and Python 3 support in 2018.
#!/usr/bin/env python
import argparse
import errno
import itertools
import json
import os
import requests
import time
WIDTHS = (1280, 500, 400, 250, 100, 75)
@garcia
garcia / imgurwords.py
Created July 12, 2013 05:55
Source for imgurwords.tumblr.com. Written in 30 minutes. Reuses some components of autotumble.py.
#!/usr/bin/env python
import json
import pickle
import pprint
import sys
import time
import traceback
import oauth2
import requests
@garcia
garcia / theultimateoneliner.py
Last active December 12, 2015 09:39
A one-liner that converts any Python script to a one-liner. There are no literal semicolons in this script or its output (i.e. it doesn't cheat).
print'exec '+(lambda L,R:lambda C:R(L,R,C))((lambda L,R,c:'type((lambda:0).__code__)(%s)'%','.join(R(L,R,getattr(c,'co_'+n))for n in'argcount:nlocals:stacksize:flags:code:consts:names:varnames:filename:name:firstlineno:lnotab:freevars:cellvars'.split(':'))),(lambda L,R,o:L(L,R,o)if type(o).__name__=='code'else'('+''.join(R(L,R,n)+','for n in o)+')'if type(o).__name__=='tuple'else repr(o)))((lambda n:compile(open(n,'r').read(),n,'exec'))(__import__('sys').argv[-1]))