Nov 172015

Hey hey,

Sitting on a plane on a business trip, got a few minutes to spare so I figured I’d add a little tip I learned…

Over at Hifi we use Amazon’s Elastic Beanstalk to power one of our internal APIs. The idea here is that you expose a WSGI-enabled file that Amazon will allocate hardware for, spin up machines, serve, scale, handle DNS routing, etc. It’s some kind of magic (it’s not really that magical, but it is nice).

When setting up these machines, the general idea is that you specify a few parameters, like what kind of machines to use, what circumstances it should spin up and down machines for, but then these things should be basically hands off, running a pretty vanilla version of your code, and that you should never have to actually SSH into the boxes.

But sometimes you do have to SSH into the boxes! Sometimes you want to debug something, or add additional logging right on a machine, or something like that, but when you ssh in, those babies are pretty uninviting. Here’s where a little customization goes a long way (or not). Why not give that login prompt some nice PS1 coloring?!

As far as customizing your Elastic Beanstalk boxes:

  1. Create a directory in your project called .ebextensions that has one or more config files with information about specifically how/what to customize. There’s a bunch of documentation about possible customizations. If you don’t already have a config file, create one in this directory (something like sam.config)
  2. Modify that config by adding the following in the files section, creating it if it doesn’t exist:

A few notes:

  • The default user when you login to an Elastic Beanstalk box is ec2-user
  • Feel free to use whatever PS1 you like, the one I chose is the “Pink and Blue” theme from
  • Note the filename is /opt/elasticbeanstalk/hooks/appdeploy/post/ – this directory contains executable files that will be executed post-deployment. The 997 is just a high number, so it’s one of the last files in there that gets run. Do what suits you.
  • I’m sure this could be done a few other ways, this is just the one I went with.

Happy customizing!

May 102015

For a recent project, I had to create a game-style controller Android app that senses the phone’s tilt and uses it as an input. (image via SO)

To simplify the explanation, imagine a jet thruster game where the farther you tilt the phone back, the stronger the jet thrusters fire:

  • When the phone sits upright, the thrusters don’t fire at all
  • When the phone is tilted all the way back, the thrusters fire at full force

Going into it, I knew I would need to use Sensors, specifically something about the Accelerometer. Digging in a bit more, no amount of Googling/Stack searching provided me with exactly what I was looking for, so I figured I’d write it up here…

Initial search results:


My fully open-sourced solution lives here:

Specifically, check out

A few notes:

Jan 132015

Big fan of Retrofit, but have a staging server that has an invalid SSL cert?

Fear not! Just use the AllCertsValidClient!

Example usage:

Gson gson = new GsonBuilder()
AllCertsValidClient client = new AllCertsValidClient();
RestAdapter restAdapter = new RestAdapter.Builder()
    .setConverter(new GsonConverter(gson))
service = restAdapter.create(MyApiService.class);

Have fun, and be safe! (don’t use this thing in production environments!)

Dec 022014

This post serves as an update to my previous post Streaming Audio Wirelessly.

As suggested by my buddy Razr, I was indeed able to connect my Airport Express to my new apartment’s wireless network and enable AirPlay!


Thanks Razr!

Now playing (over the speakers via Airport Express + AirFoil, yay!), Sharon Van Etten – Spotify Sessions – perfect rainy Tuesday morning music

Nov 202014

So you use Spotify and want a list of all of your playlists so you can come up with your #AOTY (album of the year). I’m sure there are other ways of doing this, but my rudimentary google searches produced no results, so here goes…


  • Spotify account
  • python
  • internets

First, sign up as a Spotify developer and create an application, here:

Once you’ve created an application, make note of the Client ID and Client Secret, and add a new Redirect URIs to some working website.

Make sure to hit SAVE! If you don’t, this won’t work!!!

Now onto the code part…

First we need to put our Client ID Client Secret and Redirect URI into environment variables to be read later:

$ export SPOTIPY_CLIENT_ID='your-client-id-here'
$ export SPOTIPY_CLIENT_SECRET='your-client-secret-here'

Now we need an access token – here’s Spotify’s full formal auth guide:

but for this exercise we’ll be using Spotipy (docs)

Install spotipy:

$ pip install spotipy

Next we need to determine our scope. Here’s a list of the available scopes:

For this exercise, we’ll be using playlist-read-private.

Now let’s use this to get our scope. My username is loisaidasam, so that’s the username you’ll see me use throughout this post:

>>> import spotipy.util as util
>>> util.prompt_for_user_token('loisaidasam', scope='user-library-read')

This should open a browser window and trigger you to authenticate against your newly made application. When you say yes, it’ll redirect you to your redirect uri, which you copy and paste back here:

Enter the URL you were redirected to: 

The next string it gives you is your token. Copy and paste that into a variable called token

Now, for getting your playlists…

Here’s the Spotify documentation describing how to read a user’s playlists:

but for this exercise we’ll be using Spotipy’s user_playlists() method:

We have to use limit/offset to get all of the results, so try this code:

>>> import spotipy
>>> s = spotipy.Spotify(token)
>>> offset = 0
>>> while True:
>>>     playlists = s.user_playlists('loisaidasam', offset=offset, limit=50)
>>>     if not playlists['items']:
>>>         break
>>>     for item in playlists['items']:
>>>         print item['name']
>>>     offset += len(playlists['items'])

Running this should print out all of your playlist names one by one.


Nov 072014

Backstory: we moved into a new apartment a few weeks ago, and being that we no longer live in Manhattan, we actually have an apartment big enough that my stereo system doesn’t have to sit right next to my TV. What this boils down to is that the wall where our TV/cable/internet hookup lives is on a different side of the room than my stereo/turntable setup.

The Problem: I’m no longer able to use my Airport Express to wirelessly stream music over my stereo (which I previously did with the assistance of AirFoil), and I’m looking for an alternate solution.

In short, I need something that plugs into an AUX port of my stereo that also hooks up to my home wifi network that will allow me to stream music from sources such as Spotify, iTunes, Youtube, etc. If it has a power jack and can plug into the wall to power itself, that’s great too.

What I’ve Found: There are a variety of offerings that seem to be in this space.

Here’s some of what I’ve found:

  • Airport – from $99 for Airport Express, what I currently have, but the router is not near the Airport, so this won’t work
  • Sonos Connect – $349 / Connect:Amp – $499 – similar to Airport Express, but ridiculously expensive
  • Apple TV – $99 / Google Chromecast – $35 – these are interesting, but are for streaming things to your TV – I want to stream things to my stereo
  • gramofon – $49 – seems to only work for Spotify and WahWah(?) :\
  • Blueflame Wireless Music Receiver – $29.99 – doesn’t seem to be out yet according to their website, although Target has some pretty shitty reviews
  • Beep – $? – seems to be limited to Pandora + local music
  • Rocki – $49 – limited to Soundcloud/LastFM

That’s what I can find so far – does anyone have any other suggestions/ideas?

At this point I’m thinking I should just buy a REALLY long ethernet cable and wire it carefully along the doorframes so I can continue to use my Airport Express…

Nov 032014

Recently I bought a three-pack of these cool Nike Dri-FIT Crew Socks and I guess they mold them specifically for your left and right foot?

In getting ready for work this morning, I grabbed a pair of these bad boys, and I noticed that more often than not, the laundry place where I get my laundry done seems to pair them correctly (meaning that each “L” sock is paired with a corresponding “R” sock). I was wondering if they’re just hyper-considerate laundry folders over there, or if maybe it was just a coincidence.

Not recalling my statistics, I wrote a brute-force script to figure out what percentage of the time they would be bundled “correctly” when bundled at random:

And I found the answer to be an astonishing 40%!

$ python 3 -n 100000
3 pairs of socks
100000 iterations
{False: 60011, True: 39989}
Good 39.99% of the time 

I don’t know about you, but I find that percentage to be super high! We’re saying that when choosing socks in random order, that almost half of the time they’ll end up being bundled “correctly” with three bundles of properly matched “R” and “L” socks!

Update: I finished getting ready and hopped on my bike, and as I was commuting into work I started thinking about my results, specifically wondering if I could come up with a statistical explanation, and I think I figured it out.

Steps and corresponding probabilities:

  1. Choose one sock at random (cool 100% of the time, hard to mess this one up)
  2. Choose a sock that matches (cool 60% of the time – of the 5 remaining socks, 3 should be the correct match, and 2 the wrong one)
  3. Choose another remaining sock at random (cool 100% of the time)
  4. Choose a sock that matches this sock (cool 66.666…% of the time – of the remaining 3 socks, 2 are the correct match and 1 is wrong)
  5. The last two socks will always match each other (100%)

Now using statistics, you multiply the probabilities of these events happening (right?):

1.00 * 0.60 * 1.00 * 66.666 * 1.00

or in fractions

3/5 * 2/3





Yay, math!

Oct 292014

This morning I set out on a quest to grab ESPN’s latest headlines using pup.

Long story short: I couldn’t figure out how to do it using pup alone.

Luckily, Eric Chiang (pup’s creator) came to my rescue with a solution using pup and jq in combination, and I’ve since written a command-line script for grabbing ESPN’s latest headlines, as well as modified my motd to include them!

Happy ESPN’ing! :)

Oct 202014

After spending some fun time with the subway schedule data the other night, I’m a bit more curious now about usage.

On the data list I found the following resources:

(could be helpful for finding fare type popularity? dunno how interesting that is…)

Location data, cool! Through the NYC open data site, I even found this cool little map showing the NYC subway entrances (I’m assuming based on this data):

THIS is interesting because hourly turnstile data COULD be helpful for trying to estimate station popularity at a given time of day/day of week/etc. The only problem is that the Remote Unit/Control Area/Station Name Key data doesn’t really matchup with the GTFS dataset Stops identifiers:

Remote Booth Station Data


GTFS Stops Data

Hopefully more soon…

Oct 142014

A follow up to my last post about trying to make something useful of the NYC subway data provided by the MTA…

I was googling around to try and see if I could find a list of stations per subway line, and didn’t really find any good answers.

I did find this post, essentially asking for the same thing I was looking for:

And decided that I’d lend a hand and help out, so I came up with this:

(feel free to upvote my answer)

Happy commuting y’all!