puffpio [dot] com

puffpio [dot] com

David Pio  //  software developer, technology geek, gadget whore, motorsports junkie, video game nerd, partner engineer at Facebook

Sep 9 / 9:25pm

Tracking the generational/viral effects of the Like button

Note: I'm sure a ton of people do this, and I'm sure it's been documented before..but a quick search for "generational effects like button" yielded nothing interesting on the top half of the first page of the search results so imma write this.

Sometimes when your shit goes viral it would be nice to measure HOW viral..how is the fanout. Someone "likes" your page. Then it posts a Like story to Facebook. Their friends see it and click the link. Then they hit "like" too. And so on and so on. Your site starts getting a ton of hits, life is awesome. But how awesome was it really? Did a ton of poeple find it organically on thier own and then liked it? Or was it more of a viral thing where people saw the Like story and clicked. And how many "generations" did it go through before it started dying out?

Turns out there's a sweet way to Make This Happen. Check out this code snippet for a Like button:

I removed all the javascript part of it, but you get the gist (HAR!). When a user clicks this like button, it will create a story on their newsfeed. If their friends see it and click on it, they'll be taken to http://themostawesomewebsiteevar.com and life is good. But now check out this version:

Looks identical, right? But there is a ref="1" tacked on there. What does it mean? Well this time, when a friend clicks the story, they are taken to http://themostawesomewebsiteeavar.com?fb_ref=1&fb_source=home. BOOM. Now you can track if the visitor came in organically, or if they came in because someone clicked on a post in their newsfeed. fb_source can also tell you if they clicked on it from a person's profile, or other places, but that's not important now. What if fb_ref could increment on every generation? Then you would be able to tell if someone visited the page because someone clicked "Like," then their friend saw it and clicked "Like," then THEIR friend saw it and clicked "Like" etc etc etc.

You now have a way of measuring your Like viral fanout. You could compile stats saying "x thousand pageviews came from a 1st generation like story, y thousand pageviews came from a 2nd generation like story, z bazillion pageviews came from a 3rd generation like story." Neato.

So how do you do this autoincrementing magic? Check out this snippet written using Javascript using nodejs, the expressjs framework, and the mustache templating language:

The server reads the querystring param if it exists, and increments the generation count. Then my like button code in my mustache template file would like this:

Neat huh? That ref parameter can be expanded to do more than just track a generation. It could hold a hash value to some table in your database which tracks much more. The sky is the limit. The possibilities are endless. The world is your oyster. Take a look, it's in a book, reading rainbow.

Docs for the Like Button are here.

Filed under  //  facebook   generational   like button   ref   viral  
Mar 18 / 5:59pm

ESPN3 is awesome in an unintended way

So today marked the beginniing of qualifying for the first round of the ALMS and ILMC at Sebring International Raceway. It's only available streaming live on ESPN3.com so I duly headed over to that website and found the link to watch. Now, ESPN3 is setup so that you need to have ESPN at home in order to watch it. What happens when you try to watch a video is that it forces you to select your cable provider and then sends you to your cable company's website. From there you can login to your cable company, and it will send you back to ESPN3 in order to watch the videos.

Sounds nice, but I'm in the middle of a move, so I have my cable cancelled. I duly clicked on the link to watch the video, selected my former cable tv company and entered in my old login information praying it would work. It redirected back to ESPN3 but with a message saying "Sorry, you do not have the appropriate package" or something like that. :( My first thought was to ask a friend with cable for their login and password, but before I did that I clicked on the video again.

And what do you know, the show started playing just fine! MUAHAHAHAHHAA. I hope they never fix this

Filed under  //  alms   authentication   espn3   ilmc   sebring  
Jan 21 / 10:00pm

Avoiding the 10 East freeway suckage

I wrote this for a friend to give him some tips and tricks for avoiding the crappy 10 East traffic during evening rush hour. I decided to repost this here so everyone can read it. Feel free to add more tips to avoid slow spots! It doesn't have to be on the 10 East, but on any highway!

-------------------------------

The 10 eastbound sucks soooo much here's what I do.

----------- WEST LA TO 110 ---------------

I am guessing you get onto the 10 around Robertson or La Cienega, but that is a bad place to get on cuz all these on ramps and lanes are merging
If you can, go past the 10 freeway and get onto Adams which runs parallel to the 10. MUCH FASTER

You can take Adams all the way to USC and get back on the 10 at Vermont or the next one...BUT here is another tip:
From Adams, get back on the 10 at La Brea...the way the on ramp is designed, it doesn't merge into the 10 but it opens up a new lane so it's not as slow.
Once you get on the freeway dont change any lanes, stay in the right most lane...pass Crenshaw.

After you pass Crenshaw, another lane will open on your right that started from the Crenshaw on-ramp
It only lasts till the next exit (Arlington) and then it goes off the freeway.
GET IN THIS LANE it's so fast even for just 1/2 mile

Just duck back into the 10 right at the end OR; if you think you can time it, exit Arlington and just drive straight back onto the 10. Sometimes I try to time it so I exit Arlington, hit the green light and right back onto the 10.

If you decided to duck back onto the 10 and not exit Arlington..stay in the right lane..it will exit off into it's own 2 lane minifreeway that is separate from the main 10. This minifreeway is WAY faster than the main 10.
If you decided to exit Arlington and go straight back onto the 10, you will automatically be placed in this minifreeway.

Stay on this minifreeway, pass Western, pass Normandie, then merge back onto the main 10 after Normandie.
You don't wanna stay on this minifreeway at this point cuz it merges down to 1 lane at the 110.

-------------- 110 to downtown LA ---------------------------

After you get back onto the main 10, stay in the right most lane you should be already in.
Eventually you will hit the 110 interchange..continue to stay in your lane as you separate from the main 10 freeway.

Once you separate from the main 10 freeway, move one lane to the left. The reason being you are now at the point where that minifreeway merges back, and there will be a ton of cars changing lanes. There will also be cars stopped in the middle lane (the one you were in) trying to get to the right lane cuz they want to get on the 110.
So stay in the left lane at this point to avoid those stopped cars.

Once you pass the 110 offramp, immediately move 2 lanes to the right so you are in the right most lane. This piece will not rejoin the 10 freeway just yet. However you will see up ahead where it rejoins...sometimes the lane that rejoins is jammed...if it's jammed just exit the freeway. If not, rejoin the main 10.

If you exited the 10 you should be on a one way street going east, south of the staples center.
If this one way street is not crowded, just drive on it all the way till you see a 10E entrance at Los Angeles St and get on there.

If it's crowded, make a left to go under the 10 freeway and then make a right on Venice and make another right on Los Angeles St. You will be at the same 10E entrance, but from the opposite side of the freeway

Enter back on the freeway here. 

--------------------- downtown LA to the 10/60/5 split ------------------

At this point you should be in the right lane of the 10 either just getting on from Los Angeles St, or you just stayed on the 10 cuz it wasn't crowded enough.
Stay in the right lane cuz it splits into 2 lanes and most people take the left one.

If the 10 is still slow, take the next exit Central. just exit the freeway them immediately get back on...you just skipped a bunch of traffic :D
Once you are back on the 10, I usually immediately exit Alameda cuz I'm going to head for an alternate route around the 5 South..but for you get back on the 10

Exit Santa Fe, but you will notice once you are on there, it can just rejoin back up to the 10E, or it can go back to the 60E/5S interchange.  If you want to take the 10E, take it from here. Otherwise continue on this little side road till you get back up to the 60E/5S split and take the 60E

---------------------

that's all i know!

Filed under  //  10 freeway   rush hour   traffic  
Nov 10 / 12:29am

What I want for asynchronous WCF clients and C#5 async/await

I have a problem with Adding a Service Reference (and thus using svcutil). It generates proxy interfaces and proxy datatypes. If my WCF service used custom datatypes, the service reference would create a proxy datatype for it. This gives me headaches because I think I have a type Foo when in fact I have a proxied version. Now I have to cast between them. Also, if I have added two service references and they used the same datatype, guess what? It will generate two different proxied datatypes. And if I change anything about the service or the datatypes, I need to regenerate the service reference. What a pain.

Instead, I do something like this:

 [ServiceContract]
 public interface IContract
 {
   [OperationContract]
   int Add(int a, int b);
 }
 
 public class MyClient : ClientBase<IContract>, IContract
 {
   public int Add(int a, int b) { return base.Channel.Add(a, b); }
 }
 

Nice and clean huh? The WCF client uses the same interface and same datatypes as the service so no need to regenerate service references. It's tightly coupled and I also get compile time errors if I change the service interface. The only problem is that doing it this way does not generate asynchronous client methods.

The Visual Studio Async CTP gives a sneak preview into the future of the language. It adds two new keywords async and await which make it dead simple to convert regular code into asychronous code. I won't go into detail on how it works, but in addition to the language/compiler changes it also includes a bunch of extension methods that add this new style of asynchronous access to a bunch of preexisting classes that have asynchronous methods. For example, TextWriter contains a synchronous Write() as well as the asynchronous BeginWrite() and EndWrite(). This CTP adds WriteAsync() which wraps the BeginWrite() and EndWrite() into this new async/await syntax. What I envision, and what I hope happens is that they also do some work on WCF client generation (hopefully not using svcutil, but extending ClientBase). I want there to be something like this:

 [ServiceContract]
public interface IContract
{
   [OperationContract]
   int Add(int a, int b);
}

public class MyAsyncClient : AsyncClientBase<IContract>, IAsyncContract<IContract>
{
   public async Task<int> AddAsync(int a, int b) { return await base.AsyncChannel.AddAsync(a, b); }
}

That's my pipe dream. I want to not have to generate proxy interfaces and datatypes, retain compile time errors when the interface changes, and not use svcutil. The IAsyncContract<T> would be enforced to take an interface that is marked as a ServiceContract. It would then take all the methods in the interface marked as an OperationContract and create a new interface with them, but changing their return types from what they were originally (e.g. int, string, List<double>, etc) to async Tasks (e.g. Task<int>, Task<string>, Task<List<double>>).

Right now I think it's impossible for an interface like IAsyncContract to exist and do what I would like, but maybe some kind of autogenerated code could take place on compile could net similar results. Thoughts?

Filed under  //  .net 4   async   asynchronous programming   await   c#   c#5   wcf  
Sep 17 / 3:23pm

.Net 4 Task Parallel Library and Asynchronous Amazon SimpleDB Access

At work we use Amazon SimpleDB for our distributed, redundant database; and Amazon supplies an SDK to use in which to access the service. Unfortunately for some, this SDK exposes all of the calls synchronously, with no asynchronous versions of any web service calls. As such, my initial implementation of data access was something like:

 IEnumerable<MyData> data1;
 IEnumerable<MyData> data2;
 IEnumerable<MyData> data3;
 IEnumerable<MyData> data4;
 
 data1 = GetData1FromSDB();
 data2 = GetData2FromSDB();
 data3 = GetData3FromSDB();
 data4 = GetData4FromSDB();
 
 return DoSomethingCool(data1, data2, data3, data4); 

Now that looks readable and straightforward, but it does not scale. Eventually we got to the point where each of the calls to SDB were retrieving significant amounts of data. Enough to cause site slowness when looking at large datasets. Reading about the handy dandy Task Parallel Library, I modified the implementation to this:

 Parallel.Invoke(
    () => { data1 = GetData1FromSDB(); },
    () => { data2 = GetData2FromSDB(); },
    () => { data3 = GetData3FromSDB(); },
    () => { data4 = GetData4FromSDB(); }
 );
 

Great! Immediate speedup and all was good..for the moment. The data access was parallelized, but the interesting thing about Parallel.Invoke is that it limits itself to the number of processor cores your system contains. It was designed for compute bound tasks, not IO bound ones. Well great, I needed a way to go beyond the number of processor cores in the system, and I played with passing in some ParallelOptions with different parameters to try and mix it up, but settled on this:

 var tasks = new Task[] {
    Task.Factory.StartNew(() => { data1 = GetData1FromSDB(); }),
    Task.Factory.StartNew(() => { data2 = GetData2FromSDB(); }),
    Task.Factory.StartNew(() => { data3 = GetData3FromSDB(); }),
    Task.Factory.StartNew(() => { data4 = GetData4FromSDB(); })
 };
 Task.WaitAll(tasks);
 

This implementation queues up all the tasks in the ThreadPool and goes to town. It's not limited by the number of processor cores, but by the size of the ThreadPool. Nice. But this implementation and the one above share another problem: Even while the tasks are blocked and waiting for data from SDB, it is still holding onto a Thread in the Threadpool. What I really needed was an asynchronous version of the SDB SDK but I don't want to rewrite their entire SDK to do it. After some more research into the Task Parallel Library and its compatibility with the Asynchronous Programming Model, I came up with this implementation:

 var tasks = new Action[] {
    () => { data1 = GetData1FromSDB(); },
    () => { data2 = GetData2FromSDB(); },
    () => { data3 = GetData3FromSDB(); },
    () => { data4 = GetData4FromSDB(); }
 }.Select(a => Task.Factory.FromAsync(a.BeginInvoke, a.EndInvoke, null)).ToArray();
 Task.WaitAll(tasks);
 

See what I did there? I took each data accessor and wrapped it into an Action via a lambda expression. Action's (and Func's) contain built in BeginInvoke and EndInvoke asynchronous versions of their execution. Nice. Now I just needed to batch them up and wait for them all to execute before continuing. I wrapped them into Tasks using Task.Factory.FromAsync and then issued a Task.WaitAll to wait till they finished. I then abstracted the functionality into an extension method:

 public static void InvokeAsyncAndWaitAll(this IEnumerable<Action> actions) {
    Task.WaitAll(actions.Select(a => Task.Factory.FromAsync(a.BeginInvoke, a.EndInvoke, null)).ToArray());
 }
 

I can create multiple extension methods for each type of Action and Func as well (the Func version would need to return some type of collection). The nice thing about this is that all the data access happens asynchronously (though I have no control over when the thread sleeps during the data access), and data access is parallelized as well. Additionally using the Task Parallel Library lets the code look readable and definitely more maintainable than using some type of sync'd/locked counter for checking when all data accesses complete.

Aug 26 / 11:21pm

Android and Google made me smile today

Today I had to goto my wife's friend's house to pick up some stuff. I looked at his contact info on my phone and I had his email address and phone number but I didn't have his street address. However, I know that I once used Google Maps to look up his address so onto Google Maps I went. I inputted his city and the autocomplete suggested the full address I had typed in months earlier *sweet*.
So now I needed to get that address into my phone. I know that Android phones auto-sync with Google Contacts, so I opened up my contacts list in Gmail only to discover that he wasn't in there. I looked back at his contact info on my phone and realized that the info came from the Facebook integration, kinda cool.  Back in Google Contacts, I proceeded to add him into my contacts, I started typing his name and the autocomplete suggested his email address since I had emailed him before *nice*.
Finally I added his phone number and address into the contact. I turned back to my phone - which was showing his contact details from earlier - with the intention to manually refresh my contacts to pick up the new info, but it was already there! His contact info which was displayed autorefreshed and had his address in it and showing on my screen *nice*.
So that part made my smile today. The tipping point was that when the address auto synced to my phone, I did not have to manually refresh the display of contact info, it just changed automatically.
Filed under  //  android   autocomplete   contacts   google  
Jul 29 / 11:03am

24 Hour Fitness has my fingerprints

Summary:
My gym doesn't trust me and fingerprints me like a criminal. I don't trust my gym to safeguard my personal info. I also didn't like the face they forced me to do it or I couldn't access the facility.
 
My friend had this to say about it:
"I'm paying to use fucking gym equipment, not a laboratory w/ explosive chemicals. That's invasive ass shit just so you dont' have to pay someone to sit at a desk 24/7 at near minimum wage"
 
Detail:

Went to the gym last night and discovered they are transitioning to a new authentication system where instead of scanning your card, they instead take your fingerprint.

I was informed that this system was mandatory and they were phasing out card scanning.  The people behind the counter asked for my phone number, then took fingerprints of my index finger on both hands.
 
To me, I feel like this is BS:
  • Why should my GYM be creating a database of fingerprints of its customers? Do you trust your gym to safeguard that information? The same gym that uses pressure sales tactics, "club tours" that force you to stay and be pressured.
  • The lady at the counter said that this is not optional. Why is this not optional? They say that the point of this is convenience. You no longer need to carry your card, and it'll be quicker to get access into the club. Maybe, but everytime I goto the gym it took all of 5 seconds for the person to swipe my card. It's going to take longer to type my 10 digit code and then scan my finger.
  • Why was there no communication a month or two ahead of time warning of this change? Usually with large policy changes like this, a responsible company should inform its customers ahead of time to prepare them for the change. The fact that the first time I hear of this is when I get to the gym, and I am FORCED to do it or will not be able to access the equipment is bad customer relations.
  • Why do I have to supply my phone number? The person at the counter asked for our phone number to be used as our access code. When I said that I don't want to give out my phone number, they told me that actually I could just use any 10 digit number. If that is the case, why not say that in the beginning? Thousands of people who don't dig any deeper are going to be supplying their phone number without realizing that they didn't need to give it out.
  • If this is mandatory, why can I not get a refund? According to the people at the counter, I have to do it and tough luck. There was no option to cancel my membership. I'm sure I could call corporate and get a refund, but I would have to fight for it. If you are going to make a policy change that infringes on your customers private information, the "opt out" should be clear and prominent.
So now my gym has: My name, address, phone number, head shot, and fingerprints. My bank doesn't even have my fingerprint! Someone could do some serious damage with all that info.  I started thinking, why would 24 Hour Fitness want to do this..what's in it for them? They get a database of your most private information that I hope to God they will not use for marketing purposes or resell. I started to think, they could use this as a way to not have to hire counter staff. They could be like a subway with a turnstile gate, and you supply your code and fingerprint.  I guess that would save on labor cost. It sucks then that the counter staff who are setting all this up are basically working themselves out of a job.
 
There are three main reasons why this upset me:
  • I was not given a CHOICE.  There was no advance notice, and I had to sign up or they would deny my entry.  There was no way to opt out and use the old system, and no obvious way to cancel and refund my membership fee.
  • I am worried about my private information.  I am a software developer, and knowing too much for my own good makes me worried about my GYM having that kind of info on me. A gym is not a bank, they don't have the same kind of security and safeguards about data. They will not have invested in top software developer talent for their systems.
  • Being forced to submit to a fingerprinting makes me feel like I am a criminal. You are surreptitiously telling your customers that you do not trust them.
 
If they sent out a letter a month or two in advance explaining the new access system and how great it would be for the customers, I would grumble about it, but ultimately accept it and move on. Springing it on me is the tipping point that makes me actually motivated to write about it.
Filed under  //  24 hour fitness   fingerprint   gym   privacy   security  
Jul 8 / 11:07am

Back to the Future has one flaw

In the first movie, when Marty is playing songs at prom, and his parents are not really hitting it off, he starts to fade away...as well as his family in the family photo he carried.
This suggests a singular timeline, since if his parents don't get together he will never be born and thus fade away.

HOWEVER, in the sequel where Biff gets sports almanac and then makes it rich, they return to a timeline where Biff is all powerful, and the Doc never invented the time machine...
If, then it was a singular timeline, then Marty could not have time traveled and thus would have faded away...
The fact that they appeared in this alternate timeline makes me believe it is suggesting a branching timeline where each decision point in time generates infinite universes

Head explode.
Jul 2 / 4:49pm

Alum Rock Park

(download)

Jun 3 / 10:24am

Elements of a five act story

  1. Hi! Who are you! What's going on?!
  2. ALL RIGHT LET'S DO THIS!!! WOOOO
  3. WE ARE DOING IT!! YEAAAHH
  4. oh shit something went wrong
  5. Everything turned out better than expected
Filed under  //  act   five   story