Skip to content

Instantly share code, notes, and snippets.

jiaaro /
Last active Oct 3, 2022
Using Swift libraries in Python

Using Swift libraries in Python

So... this is obviously totally, 100%, like for. real. not. supported. by. Apple. …yet?

But still... I thought it was pretty badass. And, seeing how there's already a Swift buildpack for Heroku you could move some slow code into Swift can call it as a library function. But, you know, not in production or anything. That would be silly, right?

Now, having said that, the actual Python/Swift interop may have bugs. I'll leave that as an exercise to the reader.

How to get Python code calling Swift functions:

import asyncio
async def sum_queue_vals(q):
result = 0
while True:
val = await q.get()
if val is None:
result += val
return result
jiaaro / hotkey_helpers.js
Last active Jul 31, 2022
Mac Automation – Javascript (JSX) Hotkey helpers
View hotkey_helpers.js
// How to use:
// 1. Open "Script Editor" (requires OS X 10.10 Yosemite)
// 2. Change the language from "AppleScript" to "JavaScript"
// 3. Paste the code below and replace the safari example.
// More info:
var sys_events = Application("System Events");
jiaaro / Generate WAV from
Last active May 3, 2022
Generate a wave file from a MIDI file with Pydub
View Generate WAV from

Simple example of rendering a midi file with Pydub

Basically, this takes a MIDI input file (I just googled and grabbed one of Maroon 5's "Animal" – I know, I know) and generates a WAV file.

NOTE: This is the slowest midi rendering program I have ever seen!


jiaaro /
Last active Mar 9, 2022
How to install PyAudio into a VirtualEnv on Mac OS X 10.10

Install portaudio using homebrew (or method of your choice)

brew install portaudio

create $HOME/.pydistutils.cfg using the include and lib directories of your portaudio install:

from pydub import AudioSegment
from pydub.utils import db_to_float
# note: see usage example at the bottom of the gist :)
class Mixer(object):
def __init__(self): = []
def overlay(self, sound, position=0):
jiaaro / controller.lua
Last active Jun 11, 2021
gamepad emulation of playdate crank
View controller.lua
-- uses:
local Object = require 'classic'
local lume = require 'lume'
---@class Controller
local Controller = Object:extend()
local function getStickAngle(x, y)
jiaaro /
Last active May 7, 2021
Run some commands asynchronously in bash and then make sure to kill the child processes if the user kills the process with CTRL-C (or similar)
trap "exit" INT TERM # Convert INT and TERM to EXIT
trap "kill 0" EXIT # Kill all children if we receive EXIT
# Run stuff in the background
sleep 3 &
sleep 4 &
# Find child processes and wait for them to finish so this script doesn't
jiaaro /
Last active Apr 27, 2021
Coinbase Export: Parse and Process "Convert" Transactions
import csv
csv_path = "/path/to/Coinbase-xxxxx-TransactionsHistoryReport-2021-03-13-22-28-28.csv"
outcsv_path = csv_path + ".processed.csv"
with open(csv_path, "r") as fi, open(outcsv_path, "w") as fo:
r = csv.reader(fi)
w = csv.writer(fo)
for i, row in enumerate(r):
if row and row[-1].startswith("Converted"):
jiaaro / retirement
Last active Feb 25, 2021
A Simple, Easy-to-edit Retirement Saving Calculator (in python)
View retirement

Retirement Calculator

  • ages are in years
  • contribution, and savings are in dollars
  • avg_annual_return is a ratio, so 1.07 is a 7% annual return

let's say I'm 25 years old, I am going to contribute $2000/yr in bonds (~5% return), and I've already invested $5700 in bonds