Skip to content

Instantly share code, notes, and snippets.

James Robert jiaaro

Block or report user

Report or block jiaaro

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@jiaaro
jiaaro / installing_pyaudio.md
Last active Oct 16, 2019
How to install PyAudio into a VirtualEnv on Mac OS X 10.10
View installing_pyaudio.md

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:

[build_ext]
@jiaaro
jiaaro / async_children_with_cleanup.sh
Last active Oct 1, 2019
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)
View async_children_with_cleanup.sh
#!/bin/bash
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
View asyncio_example.py
import asyncio
async def sum_queue_vals(q):
result = 0
while True:
val = await q.get()
if val is None:
break
result += val
return result
@jiaaro
jiaaro / _INSTRUCTIONS.md
Last active Jul 16, 2019
Using Swift libraries in Python
View _INSTRUCTIONS.md

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:

@jiaaro
jiaaro / retirement calc.md
Last active Jun 30, 2019
A Simple, Easy-to-edit Retirement Saving Calculator (in python)
View retirement calc.md

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

View pydub_mixer.py
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):
self.parts = []
def overlay(self, sound, position=0):
@jiaaro
jiaaro / getjson.js
Last active Jan 9, 2019
super simple implementation of getJSON
View getjson.js
function getJSON(url, cb) {
var xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.onreadystatechange = function() {
if (xhr.status != 200 || xhr.readyState != 4) return;
cb(JSON.parse(xhr.responseText));
}
xhr.send();
};
@jiaaro
jiaaro / setup_local_codebuild_testing.sh
Last active Dec 4, 2018
Set up local testing for codebuild
View setup_local_codebuild_testing.sh
#!/bin/bash
docker --version
if [[ $? != 0 ]]; then
brew cask install docker
fi
echo "Make sure you have $HOME/bin in your PATH"
mkdir -p ~/bin/
curl https://raw.githubusercontent.com/aws/aws-codebuild-docker-images/master/local_builds/codebuild_build.sh > ~/bin/codebuild_build.sh
@jiaaro
jiaaro / hotkey_helpers.js
Last active Nov 27, 2018
Mac Automation – Javascript 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:
// https://developer.apple.com/library/mac/releasenotes/InterapplicationCommunication/RN-JavaScriptForAutomation/index.html
var sys_events = Application("System Events");
@jiaaro
jiaaro / script.bash
Created Apr 24, 2013
Embed Python in a bash script
View script.bash
#!/bin/bash
export FOO=100
python - <<END
import os
print "foo:", os.environ['FOO']
END
You can’t perform that action at this time.