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
@garcia
garcia / fruity_controller_frequencies.md
Last active November 18, 2024 21:21
Map Fruity Keyboard Controller's note value to any other software's frequency parameter

fruity_controller_frequencies.py

This script enables you to map the Note output value from Fruity Keyboard Controller (set to the full keyboard range) to any other software's frequency or cutoff knob. All you need to specify is the target control's maximum and median frequencies (freq_max and freq_mid). The script prints a Fruity Formula Controller expression that takes Fruity Keyboard Controller's Note value as the "a" knob and outputs the equivalent frequency for your desired software. Note that the target frequency/cutoff knob must be logarithmic.

How to use

  • Add a Fruity Keyboard Controller in the Channel rack.
    • Select the full keyboard range and auto-map it to white & black notes.
  • Add a Fruity Formula Controller in the Mixer window. Paste the output from this script into the Formula input.
  • Set the "b" and "c" knobs to their median values of 0.5. From there, you can tweak them to adjust the semitone or octave.
@garcia
garcia / keybase.md
Last active January 27, 2025 20:34

Keybase proof

I hereby claim:

  • I am garcia on github.
  • I am garcia (https://keybase.io/garcia) on keybase.
  • I have a public key ASACADhJrVlvsNQCi89p44aQ8bYZSnqPq-qaHJW9aYg3ywo

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]))