Damn Good Iced Coffee

So for the last 6 months I have been scouring the city for the best iced coffee. I have come up with many of the known SF favorites like Philz and Blue Bottle, but none have been consistently  over the top good. So I set out to design from the ground up the best home brewed iced coffee known to the local universe.

First, you gotta start with a half pound of freshly ground coffee. You can find whole beans at most of your local grocery stores with a grinder right next to it. Its usually not much more expensive to grab fun varieties from your local coffee shop that come from South America or Africa. Remember : if you use Foldgers “your gonna have a bad time”.

Grab a 1 gallon container that has a lid and pour in the 1/2 pound of coffee. Fill the container with GOOD WATER. I can’t stress this enough filtered water really does make such a difference. The ground coffee is really the only REQUIRED ingredient but here is where the ridiculous deliciousness comes in. Grab these items from your local spice shop or grocer :

  • Lavender
  • Whole Cinnamon Sticks
  • Whole Vanilla beans (These are expensive so if you cant get the whole beans you can substitute with a TINY bit of extract)
  • Nutmeg (optional)

Smash the cinnamon sticks with the side of a knife to increase the surface area the water will be touching, toss em in. Cut the vanilla bean in half then run the blade up vertically to open the pod. Scrape out the seeds into the coffee water mixture. Put about 3 fat pinches of lavender in with a SMALL amount of nutmeg (if your into that kind of thing). Then lightly stir so that all the spices are suspended in the middle not floating on the top.

Cover with the lid and let sit over night….

In the morning grab a strainer and some cheese cloth. Pour your coffee concoction through the strainer into a 1 gallon (or 2 2qt) GLASS container. Refrigerate.

To Serve:

Start with a glass and fill with ice.  Pour in your black icy nectar. Top with a splash of Half-and-Half and a dash of sugar (or cream and sugar sub.), mix and enjoy!

3D Projection As In Home Art

Below you can see the cardboard fractal I made by cutting many triangles and connecting them together with duct tape. Then next to that an initial video test rig that is designed to highlight the edges.

Horizontal Scaling With Auto Balancing DB Nodes

 So for a while now I have been wrestling over the idea of horizontal scaling of a (for the purpose of this article) mysql db. Not how to actually do it but to make it better. I want a system that can grow and scale as a product does allowing small operations to build on a powerful stack from the beginning with a super low overhead. I should take a moment here to note that I am sure I am not the first to come to this idea but I have not located another source that talks about it. If you do know of some good info please pass it along to aaron@inburst.io and I will link to it from here.
 

    I guess it would be good to note that mysql has a tendency to begin to perform badlywith super large table sizes. To counter this a standard approach is to shard the db. This basically means breaking the database into smaller databases and using a hash algorithm, usually linked to the users id, to make sure we always query the same db instance for a particular user. This is great, if I have a db that is too big, split it in two and now I have 2 that are much faster. Easy enough, right? Ok, so lets continue this example by having our 2 shards now reach capacity, then what do we do? You would probably say “Add two more nodes” so this is a little more difficult, now we have to take two nodes off line, shard them, update our hash function, then bring the whole thing back online…Is there a better way?
 

    So lets start with the hash algorithm. Knowing the space the hash will map to could potentially increase, we need to consider a space not bound by integer values. Instead lets consider the infinite space between 0.0 and 1.0. Targeting this space will allow for an addition of an arbitrary set of indexable db nodes without further modifications to the hash function. A key consideration is the idea that a hash lookup COULD fail meaning the db index returned by the hash function does not contain the target record and will have to recover properly.
Lets put this in a concrete example…
Lets say I started with a single db instance and that we have a hash function that takes in a user id and spits out a floating point number between 0 and 1. A user record is queried and the hash function returns 0.6, well we dont have a db node at 0.6 only one at 0. We search a list of the db nodes we have and their decimal ids, we then take the node with the closest index, in this case 0 so we ask db 0 for the user record. So for the base case its pretty simple, there is only one node so every hash and distance operation points back to the single db node at 0. Now lets say that db is headed towards becoming overloaded and you decide to expand your db shards but your product requires a really high up-time and taking it down to bisect it is out of the question, so what do we do. Well lets look at the hash algorithm again lets say we need to get the record for the same user as before. The hash function points us to 0.6 whos closest node is 1.0 (We know from before that the user record is located on node 0). So we consider this a MISS. This is where the auto-balancing part comes into play, after a miss the system will search the other db nodes in an expanding radius from the hashed value. Once the record is found (in shard 0) we would then move the record to the node we first checked. We now only have to search N/2 db nodes where N is the total number of nodes in the system to either find the record or be guaranteed it does not exist. This allows us to dynamically scale up the number of db nodes as demand increases and have the load automatically re-distribute itself to the new shards.

Algorithm Summary

  • Hash space between 0.0 and 1.0
  • Keep a list of the db nodes and their decimal id
  • Look up record in closest db id to hash result
  • Search radially outward to a max of N/2 for record if needed
  • Move record to the first db searched (if needed)

    In conclusion database management at a large scale can be a giant pain so building in transparent flexibility at the beginning can be the difference between a hyper-viral hit and a missed opportunity.

Hacked – Old Bluetooth Headphones

Often I love playing music from my phone or device while at partys but hate having to leave it sitting there, next to the stereo, out in the open where people can mess with it or worse, walk off with it. So for this hack I wanted to come up with a low cost wireless audio receiver that was super generic.

I was looking for something that would give me the following
- Decent wireless distance ~50ft
- Reasonable transmission security
- Digital audio with Stereo support
- battery powered
- Work with any (pre)amp with an aux or RCA input

I ended up stumbling across an old bluetooth headset  that I had not used in a long time. It was a really cheep set that I got off amazon (link) and looked like it would be perfect for this project. A quick tip : make sure to turn the volume to the half way mark before you go tearing off any buttons.

I removed the casing around each earbud and traced the positive and negative leads on each ear bud connection. Then I soldered (using flux core solder for best results) the speaker leads to each of 3 conductors in a shielded cable, splicing the ground to the negative lead of both earbuds. Then on the other end I attached a 3.5mm male audio jack, being sure to match left and right lines from the earbuds to their proper positions.

Thats It!
Super simple generic wireless audio receiver that you can take anywhere! I took an old pill container I had lying around and drilled a hole in the top for the audio jack. I also grabbed a female 3.5mm to male RCA converter to keep in the container in case I ever need it.

Glassware:Is There A Fucking Giants Game

On the heels of the first Google Glass push to the public I have built a simple piece of glassware to help out people who hate getting surprised by the huge influx of people during SF Giants games.

It is built on Node.js and is meant to be simple and non obtrusive.
The glassware reminds you of transit and traffic delays on the day of and 3 hours before a game.
Check it out and feel free to shoot me any feedback you have.

– GLASSWARE LINK –

GPS Distance Calculation

During a recent project I needed to calculate the distance between two GPS coordinates. After a little research I found tons of people that have done this before and most(well the correct ones) are baseed on the Haversine formula. I wanted to share my implementation just to help people get to the answer quickly with-out having to analyze the trig.

A little helper I will be calling.

var toRad = function(deg) {
    return deg * Math.PI / 180;
}

The meat of the work…

var earthRadiusMiles = 3963; // earths radius in Miles var lat1 = coord1.lat; // get lat of coord1 in deg var lon1 = coord1.lon; // get lon of coord1 in deg var lat2 = coord2.lat; // get lat of coord2 in deg var lon2 = coord2.lon; // get lon of coord2 in deg var latRad1 = toRad(lat1); // convert to rad var lonRad1 = toRad(lon1); var latRad2 = toRad(lat2); var lonRad2 = toRad(lon2); var distance = 0; // this will hold our final distance distance = Math.sin(latRad1) * Math.sin(latRad2) + Math.cos(latRad1) * Math.cos(latRad2) * Math.cos(lonRad2 - lonRad1); distance = earthRadiusMiles * (-1 * Math.atan(distance / Math.sqrt(1 - distance * distance))+ Math.PI / 2); // distance now holds the distance in miles along the earths surface between the 2 given points // if you wish to have the distance in km you can multiply distance by 1.609.

SONOS Plugin – Shuffler.FM

I have just put together another SONOS plugin, this time for Shuffler.FM!
It is still a work in progress though… I have the public genre streams all available and the associated tracks but no specific user content. Shuffler does not support username/password auth for their oauth api so it make is a little more difficult to get access to that content. Also the only content sources that are currently supported are official.fm and Soundcloud. I am working with Shuffler to get their streams available and I will never be able to support youtube streams.

Well if you are still interested simply use the following info in the correct places while following the instructions from http://inburst.io/soundcloud-on-your-sonos/

Endpoint and Secure Endpoint URL: http://inburst.io/sonos/shuffler/SonosAPI.php

Authentication SOAP header policy: Anonymous

Container Type: Music Service

Generating Long Lived FB Access Tokens

I have put together a quick bash script that will convert a short lived token obtained from the Facebook access token tool (https://developers.facebook.com/tools/access_token/) into a long lived token that will last 60 days. This is extremely useful if you are using Facebook’s new Unity SDK. You can plug in the resulting access token and actually log in and utilize Facebook features in the Unity SDK. Grab it off github or check out the raw below.

https://github.com/ajones/longlived-fb-token

#!/bin/sh

echo "---------------------------------------------------------------------"

echo "--- Welcome to the Long Lived Access Token exchange tool ---"

echo "--- all info can be found @ https://developers.facebook.com/apps/ ---"

echo "---------------------------------------------------------------------"

echo "Paste your Facebook application ID: "

read APPID


echo "Paste your Facebook App Secret : "

read APPSECRET


echo "Paste your current short-lived access token : (https://developers.facebook.com/tools/access_token)"

read ACCESSTOKEN


echo "------------------------------------"

echo " Using App ID [$APPID]"

echo " Using App Secret [$APPSECRET]"

echo " Using Access Token [$ACCESSTOKEN]"

echo "------------------------------------"


echo "Retrieving long lived token ..."


URL="https://graph.facebook.com/oauth/access_token?client_id=$APPID&grant_type=fb_exchange_token&client_secret=$APPSECRET&fb_exchange_token=$ACCESSTOKEN"

echo " URL: $URL"


app_json=$(curl "$URL")

token=(${app_json//access_token=/ })

token=(${token//&expires=/ })

echo "------------------------------------"

echo " YOUR NEW LONG LIVED ACCESS TOKEN IS :"

echo " $token"

echo "------------------------------------"

Converting .CER to .PEM, Apple Push Certificates

 

.CER -> .PEM

A good snippit to have is the code to convert Apple push certificates to the pem file format for your server.

In KeyChain Access, select the certificate and choose File > Export Items. Select the Personal Information Exchange (.p12) option, select a save location, and click Save.

Launch the Terminal application and enter the following command after the prompt:

openssl pkcs12 -in CertificateName.p12 -out CertificateName.pem -nodes

Bluetooth RSSI to actual distance

I have recently been investigating the new bluetooth proximity exchange profile. As part of a new library I am building I needed to map RSSI values to real world distances. Understanding that RSSI can be effected by local obstructions I attempted to create a clear environment for testing.

The set up is as follows. I begin by building 3 bluetooth beacons using both Raspberry models and an iPhone5 along with iPhone app that would track them. I then created a large empty area to place my beacons in. I then took RSSI measurements using the latest iPhone5S at 1 foot intervals to 10 feet away then 2 foot intervals from 10ft to 20 ft. I then graphed the results.

SONOS Plugin – TheFuture.FM

I don’t know about you but TheFuture.FM is my go-to for incredible electronic mixes. I decided to build a plugin for SONOS so I could wake up every morning to a new heart thumping mix put together by the worlds leading DJs.
To get it all set up you can follow my step-by-step instructions for my Souncloud plugin for SONOS and simply use the following info.

Endpoint and Secure Endpoint URL: http://inburst.io/sonos/futurefm/SonosAPI.php

Authentication SOAP header policy: Anonymous

Container Type: Music Service

SONOS Plugin – DI.FM

Need a new flavor of electronic music to pulse through your house? Then grab my DI.FM plugin for your SONOS unit and instantly have access to tons of free curated electronic music!
To get it all set up you can follow my step-by-step instructions for my Souncloud pluginfor SONOS and simply use the following info.

Endpoint and Secure Endpoint URL: http://inburst.io/sonos/difm/SonosAPI.php

Authentication SOAP header policy: Anonymous

Container Type: Music Service

SONOS Plugin – Sky.FM

I have been creating these like crazy recently but I wanted to share with the community another SONOS plugin I have built. Sky.FM has tons of great radio channels, all free, and now all on your SONOS!
To get it all set up you can follow my step-by-step instructions for my Souncloud pluginfor SONOS and simply use the following info.

Endpoint and Secure Endpoint URL: http://inburst.io/sonos/skyfm/SonosAPI.php

Authentication SOAP header policy: Anonymous

Container Type: Music Service

Dynamic Perspective FOV

So for starters I should mention that the syntax I will be using for this will be C# for Unity but the math can be applied to any 3D Engine.

The Problem :
      I am developing a game which utilizes a perspective camera. Every thing looks great in the initial screen size I designed it for but when I run it on a device with a different aspect ratio or different screen dimensions the page looks really zoomed in or zoomed way out!

Whats Happening :
    As you change the viewport of the camera by running the application on devices with different screen sizes you increase or decrease (respectively) the visible area at the bounds of the view frustum.

How To Fix It :
     To counter this you need to modify the Field Of View of the camera to ensure the edges of your designed play area perfectly match up with the bounds of the screen. Easier said than done…

First thing to note is that FOV is always relative to the vertical axis. So if you are doing a Landscape game you will find a much simpler calculation to change your FOV  but for a Portrait game it is much more difficult, so thats what we are gonna solve for here.
Calculating the Horizontal FOV in radians is done by applying trig to the triangle formed by the [designed] screen width and the distance from the camera to your UI.IMPORTANT: It is important to note you will use the width that you designed for the screen width parameter NOT the current width of the screen.
If you built your UI to look good with a resolution of 640×960 pixels your horiz fov in rad would look like this

float designedScreenWidth = 640f; // I built my UI based on a 640px wide screen

float distanceToUI = 500f; // My UI elements are 500 units from the perspective camera

float hFOVrad = Mathf.Atan((designedScreenWidth/2f)/distanceToUI);

Now that we have our target hFOV in radians we now want to calculate the corresponding vertical FOV so we can apply it to our cam. (remember: cam FOV is vertical).

float aspect = Screen.width/Screen.height; // capture the CURRENT camera aspect ratio

float vFOVdeg = Mathf.Atan(Mathf.Tan(hFOVrad/2f)/aspect) * 2f * Mathf.Rad2Deg;

Awesome! We now have calculated the FOV to apply to the perspective camera to make our UI look perfect on any size device in Portrait orientation.

Finally apply the vFOVdeg to the camera

camera.fieldOfView = vFOVdeg;

Ultimate Cooler – Build

-How to make your own Ultimate Cooler-

     First off i will say that this build is pretty straight forward. It does not require any soldering (if you dont do wireless audio) and can be built in a single evening assuming you have the tools.
 

Parts

Note : All of these parts can be interchanged with higher quality or more expensive parts if you wish. I chose to keep mine cheap because I knew it would take a beating on the river, at the beach , and party hopping.

  • A cooler with wheels. (Trust me wheels are a must!) Try and find one with a lot of flat space on the top. amazon
  • 2 Speakers. 5 or 6 inch ~200 watt amazon
  • Headphone to RCA Y cable. amazon
  • A 2ch Car audio amplifier
  • A 12v gel cell led acid high capacity battery (My personal fav)
  • A 12v Automatic battery charger amazon
  • 4 ~3in long 1/8th wide machine screws along with 8 washers and 4 matching nuts
  • A power switch. Radio Shack has some. I used an old light switch I had laying around.

Tools

  • Phillips head screwdriver
  • Drill (with assorted bits)
  • Jigsaw or Router (optional but makes the large hole cutting a lot easier)
  • Pencil

Step 1 – Audio Wire Up

     I always like to start by wiring up the audio circuit just to make sure everything is in working order before we install it into the cooler. Follow the diagram below to get music playing from the speakers. It probably wont sound to good right now. This is because speakers need a resonance chamber to get those sexy bass levels.

 

Step 2 – Cooler Mod

I apologize for the lack of pictures but this is a pretty straight forward process. Begin by marking circles on the top of the cooler to lay out where you will need to cut the holes. BE SURE not to trace the outer rim of the speaker. If you do your holes will be too large and the speakers will fall right through. Also be sure to leave enough room on the inside of the lid to mount your amp. Instead use the provided template (most car speaker sets come with them) or measure the inner cone diameter and use a compass to mark circles. Next use your jigsaw or router to cut out the marked holes.

 

Step 3 – Speaker and AMP Mounting

Next mount the speakers in the holes you just cut. Then with your drill make pilot holes by laying your amp on the lid where you want it to end up and drill through the 4 mounting holes on the corners. Then mount your amp by threading the 4 machine screws through the holes and up through the lid, use the washers on either side so the screws dont pull through the plastic.
The result should look close to this :

 

Step 4 – Wiring it up

So Close! Follow the wiring diagram one more time and you should be booming. I drilled one more in the top to feed the Y cable through and screwed an iPhone case on the top to hold my phone while I the tunes are bumpin! Stay tuned for adding a Rasberry Pi for streaming audio over AirPlay.

 

Final Notes

I added some other upgrades that make the system more tolerant to water splashes, power led, dual batteries, and alerts if some one tries to steal it. I will make another post with these a little later.
Have Fun and send me pics!!!

 

WANT IT TO STREAM WIRELESS AUDIO FROM YOUR iPHONE?

Auto Start VNC on Raspberry PI boot up

Quick tip :
To have a VNC server automatically start when your Raspberry Pi boots up follow these steps.

 

Install VNC

First off make sure you have a vnc server installed. I used tightvnc because it hasent let me down yet.

$ sudo apt-get install tightvncserver

Now start the VNC server process with :

$ tightvncserver

ou can start now start a session with

$ vncserver :1 -geometry 1024x728 -depth 24

Configure Auto Start

Go to your “/home/pi/.config” directory.
Create a directory called “autostart”
Inside that directory create a file called “tightvnc.desktop”

$ vi tightvnc.desktop

Then paste the following and after a reboot you should be good to go.

[Desktop Entry]
Type=Application

Name=TightVNC

Exec=vncserver :1

StartupNotify=false

Lastly if you plan on doing any work with the GPIO pins be sure you have the latest package!

$ sudo apt-get install python-RPi.GPIO

SONOS Plugin – Soundcloud

Hey awesome people enjoying this free service. So many of you are now using this plugin that my server costs have become insane. If you like this, or any of the other SONOS plugins, please consider donating to help me keep this service up.

bc_donate

Update: You may now be seeing the tag “[NOT STREAMABLE]” appear next to some of your songs. Soundcloud gives control to each individual content creator as to weather or not their song is streamable via the external api. I was contacted by a few users were wondering why some of the songs fail to play and upon investigation I found each one of these songs had their streaming access disabled. I asked around to some of the people using this plugin and the consensus was not to hide the songs that cannot be played but to simply mark them instead. This should only effect a very small number of your songs (if any) and will mostly be concentrated on billboard and ultra popular tunes. I apologize for the inconvenience but can tell you I am already working on a new class of plugin which will not have this problem. Thank you for your continued support and please reach out if you have any thoughts on this topic.

I recently purchased a Sonos Playbar. I have got to say it is pretty awesome, especially because it can be controlled by BlueKey. I am really enjoying it except for the fact that there are a few media sources that have not yet become available. One of which is Soundcloud. So I decided to fix that.

http://<Your Sonos IP>:1400/customsd.htm

You will be greeted by a pretty bland web page that will allow you to add a custom service. Start by changing the SID or Service ID to 240 (unless you created other custom services, then you already know which SID is not in use). Next give the service a name, this is the name of the entry that will show up in your Sonos controller app. I chose to use “Soundcloud”. For “Endpoint URL” and “Secure Endpoint URL” put“http://inburst.io/sonos/soundcloud/SonosAPI.php“. Then put “30” for polling interval and select “Session ID” for Authentication SOAP header policy. Check out the following image for reference :

 

 

I know that was a lot but we are almost done. The name you chose for the service (I used Soundcloud) will now appear in the “More Music” option of your Sonos Desktop application. Click on it and choose “I already have an account”.

Input your Soundcloud login credentials and you are done!! You will now see your service name (Soundcloud for me) under your music sources. You should now have access to all your content! The system currently supports:

  • Stream
  • Favorites
  • Playlists
  • People you are following
    • Their stream
    • Their playlists
    • Their favorites

I really hope you enjoy this, I know I have!! If you have a music service you would like to make available on the Sonos platform you can contact me at aaron@inburst.io for licensing of my Sonos Service Control software.

Dont forget to check out the other SONOS plugins I have created!