Loisaida Sam

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:

https://gist.github.com/loisaidasam/d4cd1bc55a0c62ca6554

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 kirsle.net/wizards/ps1.html
  • Note the filename is /opt/elasticbeanstalk/hooks/appdeploy/post/997_setup_ps1.sh – 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!

Nov 032015
 

After all that hubbub about not posting about my 2014 CMJ, I never even posted about how my 2015 CMJ went down!

http://blog.samsandberg.com/wp-content/uploads/2015/11/little_jerk.jpg

Wednesday

I skipped Tuesday this year (#oldmanthings) and kicked of CMJ on Wednesday night at the NME, PopGun, House Arrest CMJ Party! showcase at Santos Party House, where I caught a few acts we’ve been loving lately in the office: Shopping, Protomartyr (awesome new record!) and Perfect Pussy (those Interference Fits though!).

Friday

I skipped Thursday too (more #oldmanism) but was determined to hit it hard on Friday. I feel like the town was abuzz with talk of Car Seat Headrest, so I was eager to catch them. I rushed over to the Aquarium Drunkard Presents / No Jacket Required show at Rough Trade (second year in a row at this showcase, impressed yet again). The dude played the whole first song on his back, which was pretty odd and hilarious, but also really allowed us to concentrate on the music, which was fucking great.

https://irs3.4sqi.net/img/general/1000x1000/10066_wXnBsUCLH32Cw0LqPGIRwjpFq4764Dtz5689IDRxMhs.jpg

He eventually stood up and rocked out the rest of the set.

https://irs1.4sqi.net/img/general/1000x1000/10066_KqDSAD3oaBjVmSD-KuDU42Py_it-yG7BuZspjUtm-Vw.jpg

What really blew me away Friday night though, was this band out of Athens, Georgia called Mothers. They don’t have an LP out yet, but they’ve got it where it counts, kid. Watching this band play gave me EXACTLY the feeling I look for at every CMJ. I was totally captivated. We all were.

I wasn’t that impressed with Yoko and the Oh No’s, so we dipped over to CAMEO to check out one of my former CMJ darlings, Kirin J Callinan who was impressive as always, although he refused to play my favorite, “Love Delay”.

https://irs3.4sqi.net/img/general/1000x1000/10066_MGhlZzcVAkijwgWQatOQeUfyGZmzeycclDjYAZ3EOls.jpg

After Kirin, I caught a bit of Empress Of, but then headed out. My buds ended up hitting up the Ryan Hemsworth latenight thing though and apparently it was incredible. Regrets, but then again, #oldmansyndrome.

Saturday

When I came to on Saturday I meandered over to Baby's All Right for the Brooklyn Vegan CMJ Day Party. And we’re drinking again!

https://irs0.4sqi.net/img/general/1000x1000/10066_fYuTlB2U1ziUjUYkR3klUJ87_yMAmioWx2izmR-tSH0.jpg

I caught The Go To Beds, a full set of Shopping (only caught a partial set Wednesday night, wanted to see the rest), and some of Dilly Dally. I particularly liked the Drake – “Know Yourself” cover from Dilly Dally, heh.

We took a break for some Schmackary’s cookies, evaluated our options, and decided that Mothers was playing at Pianos across the river, and that we weren’t missing it! We jumped on the L with everyone else, walked the 14 blocks, and hit a few more sets. We caught part of Weaves set upstairs while we waited, and then finally the moment was upon us. Mothers played another surreal set to an even smaller crowd and blew our minds again. I just can not wait to hear more good things about this band!

Darlings of CMJ 2015

I doubt there’s any question, but my darlings from this year were:

Happy CMJing, see y’all next year :)

Oct 162015
 

After looking around a bit, here’s my list of Friday picks:

http://www.brooklynvegan.com/archives/2015/10/whatsgoingon_2906.html

Happy CMJ people!

Oct 162015
 

Wow, I just came across this draft from one year ago that I never published. Welp, it’s CMJ season again, so without further ado, here it is, my show summary from last year:


Tuesday Night:

Cameo Gallery

  • Oh My Rockness Showcase
  • PINS, September Girls, Mannequin Pussy, Vasudeva, Amanda X

http://www.ticketfly.com/purchase/event/683553

Wednesday Night:

Glasslands

  • NME & Hate Hate Hate Records
  • The Wytches
  • Happyness
  • Twin Peaks
  • Public Access TV
  • Bo Ningen
  • Fat White Family

http://www.theglasslands.com/event/687279-nme-hate-hate-hate-records-brooklyn/

Thursday Night:

off

Friday Night:

Rough Trade – Aquarium Drunkard – No Jackets Required

Knitting Factory

  • SAFIA
  • Kate Boy

http://www.cmj.com/live/aquarium-drunkard-kevin-morby-chris-forsyth-twin-peaks-springtime-carnivore-modern-vices-ryley-walker-geronimo-getty-rough-trade-october-24th-2014/

Saturday:

Baby’s All Right – Brooklyn Vegan Showcase – SATURDAY, Oct 25 @ NOON @ Baby’s — FREE (RSVP)!

  • 12:00 Residual Kid
  • 12:45 Bully
  • 1:30 Flowers
  • 2:15 Girlpool
  • 3:00 Bo Ningen
  • 3:45 Beverly
  • 4:30 White Fence
  • 5:15 Fat White Family
  • 6:15 Titus Andronicus

http://www.brooklynvegan.com/archives/2014/10/brooklynvegans17.html


My darlings of CMJ 2014 were certainly Twin Peaks, Beverly, PINS, SAFIA, and Titus Andronicus. Also, RIP Glasslands!

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.

http://i.stack.imgur.com/ylWJb.png (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:

Solution

My fully open-sourced solution lives here: https://github.com/loisaidasam/tilt

Specifically, check out MainActivity.java:

A few notes:

Jan 202015
 

Yeah yeah, I know everyone usually does their AOTY writeups in November/December, but I always end up dragging my feet. I don’t even think I even came up with final lists for 2013 (or even 2012 for that matter), but I finally ended up getting it together for 2014, and without further ado, here’s my tops, with a few words about each pick…

Favorites:

http://blog.samsandberg.com/wp-content/uploads/2015/01/AOTY-2015-1to5.jpg

Maybe one of the most depressing records of all time (someone literally dies in every song), and yet really powerful storytelling with vivid imagery.

The album I likely spent the most time with this year. Just a great rock record through and through.

Another one I spent a ton of time with this year. Something about this one really hooks me.

Killer record, and finally a breakthrough for these guys! Plus that Letterman performance, you kidding me?!

She’s great. After digging into this one I even listened to her previous one a bunch. Plus somehow “Forgiven/Forgotten” became my airplane takeoff song (somehow that’s a thing, I guess?).

http://blog.samsandberg.com/wp-content/uploads/2015/01/AOTY-2015-5to10.jpg

Maybe the fullest record she’s done yet, my favorite songs she’s made are some of the best songs of the year, for sure.

My darlings of CMJ, probably the funnest record for me this year. And funnest shows. Do these guys know how to party or what?!

A nice nostalgia record, lots of heavy play time on the early side of 2014. The last song on Days left me off at the end of summer (in 2011) and Atlas picks up after a loooong winter to try and reintroduce spring.

I remember the first time I heard “Coffee”, I was listening to Sirius XMU and returning a rental car in Hoboken – blew me away. The rest of the album absolutely holds up as well.

Solid record full of great songs. Absolutely rocked Bowery Ballroom with an emotional performance when we saw them at the Hifi team outing in early December. And of course I was sure to get a big sweaty hug from Timothy Showalter after the show.

Honorable Mention:

  • The Men – Tomorrow’s Hits
  • Caribou – Our Love
  • Wye Oak – Shriek
  • Parquet Courts – Content Nausea
  • Eagulls – Eagulls
  • Hospitality – Trouble
  • D’Angelo – Black Messiah
  • Spoon – They Want My Soul
  • St. Vincent – St. Vincent
  • Karen O – Crush Songs
  • S. Carey – Range of Light
  • Julian Casablancas+The Voidz – Tyranny
  • Beck – Morning Phase

Top EPs:

  • Speedy Ortiz – Real Hair
  • Panda Bear – Mr Noah
Jan 132015
 

http://f.cl.ly/items/25322w1e2O163G1S1l39/kenken.jpg

So my wife and I were riding the train this morning, and having finished the crossword puzzle, we gave the KenKen a shot. It definitely provided some fun, but more so it got me thinking about combinations and permutations…

Eventually I started wondering how many total permutations there are of the 6 by 6 grid of numbers, and how many of those constitute valid KenKen boards (each row and each column must have all of the numbers between 1-6).

I ended up writing this script to brute force it:

https://gist.github.com/loisaidasam/507e82157d670023500b

But it seems like there are more combinations than I’d guessed! …

$ ./kenken.py 1
Number of unique combinations for cardinality 1: 1
Good: 1
Bad: 0

$ ./kenken.py 2
Number of unique combinations for cardinality 2: 6
Good: 2
Bad: 4
$ ./kenken.py 3
Number of unique combinations for cardinality 3: 1680
Good: 12
Bad: 1668

I’m running it with cardinality of 4 now (4×4 grid of numbers between 1-4) and it’s checking board 3 billion something…

Next steps would be trying to think of a clever way to find out the number of valid combinations for a 6×6 grid. Either we can continue with a programatic approach, either by using multiprocessing or just throwing random combinations at it, or both…

OR we could probably divert to math. A quick Google search gave me this link that seems to explain it pretty well:

http://www.math.cornell.edu/~mec/KenKen/Lecture_4.html

I guess the answer is 6! * 5! * 4! * 3! * 2! * 1!, or 24883200 (right? someone wanna double check me here?).

Long story short, it looks like there’s no shortage of viable KenKen boards!

Thanks Cornell Department of Mathematics…

Jan 132015
 

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

Fear not! Just use the AllCertsValidClient!

https://gist.github.com/loisaidasam/d4caf3659c8fa7a38222

Example usage:

Gson gson = new GsonBuilder()
    .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
    .create();
AllCertsValidClient client = new AllCertsValidClient();
RestAdapter restAdapter = new RestAdapter.Builder()
    .setEndpoint(host)
    .setConverter(new GsonConverter(gson))
    .setClient(client)
    .build();
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!

Screens:

http://f.cl.ly/items/270t2r463p1O031T0R2M/Screen%20Shot%202014-12-02%20at%208.10.05%20AM.png

http://f.cl.ly/items/1P43392R0f3J201P1b0b/Screen%20Shot%202014-12-02%20at%208.10.19%20AM.png

http://f.cl.ly/items/453A402d3s450C142527/Screen%20Shot%202014-12-02%20at%208.10.22%20AM.png

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…

Requirements:

  • Spotify account
  • python
  • internets

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

https://developer.spotify.com/my-applications/

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'
$ export SPOTIPY_REDIRECT_URI='http://samsandberg.com'

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

https://developer.spotify.com/web-api/authorization-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:

https://developer.spotify.com/web-api/using-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:

https://developer.spotify.com/web-api/get-list-users-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.

Voila!