Pages

Wednesday, August 31, 2011

LinkedIn's ShareArticle API

If you have found yourself in the (un)fortunate position of having to use LinkedIn's shareArticle API to share a URL, you may notice that there is around zero articles detailing exactly how to utilize the API correctly.  Even LinkedIn doesn't have an official developer support page which details exactly how to use their shareArticle API.

Too Long, Didn't Read:
Use proper meta tags and image combinations and just give LinkedIn the url parameter to their shareArticle API

Lucky for you I recently had to deal with this horribly under-documented share functionality at work and am going to outline exactly what to do to get it working!

Theoretically the shareArticle API should work like this, and actually this is how you want to use it:

www.linkedin.com/shareArticle?mini=true&url=http://www.mycoolwebpage.com

You may notice that if you try this with your webpage, LinkedIn doesn't gather all the correct information about your page, or possibly it doesn't gather any information about your page except for its title and url.  Where is the thumbnail?  And where is the description?  Lucky for you there's no documentation describing how you can get LinkedIn to pull that information save for a couple forum postings...that have no helpful information.  But the shareArticle API also allows you to pass some GET params to the shareArticle API - to trick you, you see, into doing it the wrong way.  For example, you can specify title, description, source and a couple other things (ooh this looks like it solves our problem!):


www.linkedin.com/shareArticle?mini=true&url=http://www.mycoolwebpage.com&title=mycoolTitle&source=dummysource.com&desc=blah%20blah%20blah...


Except...that if you try sending that URL to LinkedIn and your url-encoded URL is longer than approx. 700 characters, the LinkedIn script throws a Javascript error on IE6&7 on Windows XP, only!  Because this is a Javascript error on the LinkedIn side, you have zero control over how it can be fixed, and if you are dealing with a dynamic length description or title, or source url, constructing this URL can be extremely problematic.

Solution


Ignore LinkedIn's red-herring extra GET parameters, and just specify the url GET parameter.  This will cause LinkedIn to ping back on your URL and look for these tags (title, meta description, img...):


<html>
  <head>
    <title>The Title!</title>
    <meta name="description" content="This is the description of your linkedIn Article!">
  </head>
  <body>
    <img src="/my/img/path.jpg">
    <img src="/my/img/path2.jpg">
  </body>
</html>


If you're having trouble getting the images to work because your page is so cluttered, you can setup your page to skim the browser user-agent and look for 'LinkedInBot', and display an altered form of the webpage for LinkedIn specifically.

Wednesday, May 25, 2011

Sequel Pro - The Mac's Hidden SQL Gem

Sequel Pro is the SQL editor you've always wanted but didn't know existed

I've spent far too many hours searching for a good SQL editor.  Having used a wide variety ranging from MSSQL Server, MySQL Workbench, PhpMyAdmin and just rolling everything from the command line, I had practically given up on finding something that I thought would make me more efficient.  The good news is that Sequel Pro just about the best piece of database management software I've ever found on any platform, and it's free!  The UI is spectacular and everything is just so easy...  I can now throw together a database, edit, add keys delete tables and do just about everything in a few seconds/minutes.  Seriously, if you have a Mac and you do any sort of database work, this is the software you want to be using.

One other great thing is that if you're working in an environment where you need to take all your queries and save them as you make them, Sequel Pro keeps a detailed log of all queries that its running so you can add it to your migration file if you're keeping one.  Seriously awesome!

I was saddened that I didn't know about this software sooner, so that's why I'm sharing with you right now (apparently it's been around for years)!  Do you know of any other hidden gems for development purposes hiding away on the Mac?

Monday, May 16, 2011

Apple, iCloud and iTunes - Predictions

Apple is much expected to make an announcement next month that they're releasing a cloud based music service a la Amazon Cloud Drive and Google Music.  Much of what I've heard from others is speculation that they're going to release a competitor to those serices directly, a "music locker"  where you uplaod music that you already own to their servers are are able to stream it directly to your device.  While possible, I think they are going to release something of the same vein but drastically different.

If you look at the headlines, one thing is immediately obvious, record labels are unhappy with Google and Amazon.  They want in on the cloud based music streaming business as much as anyone, making absurd claims that streaming your own song from someone elses computer consitutes a public performance among other things.  Google and Amazon launched their services anyways, not worrying about any potential repercussions with the record labels (a good decision if you ask me).  Apple on the other hand is stil in talks with 2 of the record companies, but why?  Surely if they were announcing a cloud based locker service there's no reason to really get the approval of the record labels...

We speculate that Google's negotiations with the recording industry fell apart when trying to negotiate a deal to stream music purchased through Google Music to users from a single copy of the song hosted on Google's servers. Therefore with a little bit of extrapolation, it's not hard to imagine thats where Apple is held up as well.  So... if Apple is making that a core part of their business model then my prediction is that Apple is trying to make a cloud based service where they host only one version of the song....and everyone streams that one version that they've purchased through iTunes, foregoing the music locker concept altogether.

So a few people I've mentioned this to said they wouldn't use the service if Apple did this but if you think about it, Apple has every reason to only offer this service. No huge bandwidth requirements for people uploading 200 days of music, way less space required on the server side and perhaps most importantly Apple gives you yet another reason to buy things through iTunes. With tight integration into iOS and iTunes, Apple could make this offering seem pretty lucrative albeit restrictive.

What do you think?

Saturday, January 16, 2010

How to make your iPod 2G/3G bluetooth not suck

(Oh iPod... Why does your bluetooth suck so much?)
One of the better features in iPhone OS 3.0 was that it enabled you to use the Bluetooth module hidden within second generation iPods (and of course third gen now). Although I was initially excited at this prospect, I realized quickly that I had basically no reason to use the Bluetooth - after all I don't have a Bluetooth headset and its not like Apple would ever let you sync it wirelessly to your computer... So, while the functionality was cool, I never really had a need for it until recently when I got a bluetooth enabled car stereo.

The prospect of having no wires running everywhere in my car to get my iPod to play over the stereo has long been a dream of mine, and now that I have it working, it's pretty amazing. Until recently however; I was stuck with choppy playback and a spotty bluetooth connection on my iPod - which after doing some Googling for 'iPod touch 2G bluetooth sucks' returned some interesting results. According to some users, the iPod was given a really horrible bluetooth module, so I was left feeling ripped off by Apple for putting in terrible hardware - after all I knew it wasn't my stereo since it would play music from my phone with no choppiness. I considered switching all my music over to my phone, but I kept reminding myself that, "No, I bought this damn iPod to play my music, and I'm going to use it."

So after doing some more reading, I discovered that bluetooth operates on the already crowded 2.4 GHz frequency, and as it turns out something else on the device runs in the same frequency - WiFi. So after reading some postings by people on a forum, I decided to turn off the WiFi and give the bluetooth some time to try on its own. Guess what! My music streams to my stereo almost completely uninterrupted and the connection almost never drops!

So the solution is surprisingly simple, just turn off WiFi when using bluetooth (unless you're already connected to a network).

I think the reason behind the choppiness is not due to the fact that the WiFi is being used but instead that the iPod scans for WiFi networks. If you notice, the iPod is periodically scanning for wireless networks in the background to connect to, and when it does so - the entire iPod lags up (not just the Bluetooth). Now imagine all the networks the iPod is encountering as you're driving down a residential street... And I think you might just see why the audio starts getting choppy :)

Thursday, August 20, 2009

C++: Reference to Pointer

Recently working with some code, I came across an interesting concept - references to pointers. What does that even mean? Why would you need a reference to a pointer - ever?

After spending some time with my friend Google, I found out the answer. Suppose we have these two function definitions, and a main function:
void function_a(int *& a) {
*a += 5;
int * c = new int(7);
a = c;
}
void function_b(int * a) {
*a += 5;
int * c = new int(7);
a = c;
}
int main() {
int * myInt = new int(5);
int * myInt2 = new int(5);

function_a(myInt);
// what is the value of myInt?

function_b(myInt2);
// what is the value of myInt2?

return 0;
}

Analysis

Above, in 'function_a' we're actually passing in 'int *& a', which is a 'reference to a pointer' - a better way to think of this as passing in a 'pointer by reference'. Now, I admit, when I first saw this I thought it was called a 'pointer to a reference' but I'm not really sure what that actually would mean. So for now, just take my word for it that it's called a reference to a pointer. :)

Ok, well if you look at 'function_b', it's passing in it's paramter by pointer only ('int * a'). Both functions do the same operations within their bodies, so whats with the ampersand in function_a? Lets assume that you compiled this application and ran it. Using the int main above, you would expect the value of myInt to be 7 after function_a, right? How about for myInt2? Again, you'd expect it to be 7 after function_b. That's where you're wrong though. After running the main function above you'll get this output:

  • myInt = 7
  • myInt2 = 10

Hooray for unexpected results! The reasoning behind this actually makes sense when you realize this rule for C++:


All parameters are passed by value, unless the ampersand is specified.


Yes, even pointers are passed by value, meaning that a local copy is made for that function. This gets confusing because a pointer simply stores a memory address - and you can change the value at that memory address. The key though, is that if you make a local copy of that memory address in another variable, you can still modify the area in memory that memory address refers to, but now since it's a copy of that, if you try to change the address, it only changes for the scope the variable lives in. Confused? Lets see an example:

int * outside - points to memory at 0xFF9999, and lets say the value at that address is the integer '27'.

suppose we write

int * outside = new int(27);
function_b(outside);  // Using function_b from above
  1. Inside function_b, our local int pointer 'a' now has a copy of that memory address 0xFF9999.
  2. We first add 5 to the value at that address the way we normally would... So, 27+5 = 32. Now 'a' has a value of 32. And so does 'outside', since they both point to the same location. This is what we expected!
  3. Now we initialize int * c = new int(7) - so 'c' has a value of 7 and lets say it has an address of 0x22CCCC.
  4. Then we set the address of 'a' to 'c'. Well 'a' now has the address 0x22CCCC, and consequently the value 7, but we're no longer changing the 'outside' pointer value, since 'a' was a copy of 0xFF9999. So 'outside' still is pointing to 0xFF9999, and 'a' is pointing to '0x22CCCC'.
  5. The function returns, 'outside' now has a value of 32, and the memory at address 0x22CCCC has been leaked since nothing is pointing to it any longer!

How Passing a Pointer by Reference Solves this Problem

When we pass the pointer by reference, as in function_a, the local variable 'a' is no longer a copy of the memory address that 'outside' points to, it literally is the variable 'outside'. Therefore setting the address of 'a' to 'c', will actually change the value of 'outside' to 7, as it changes the address of 'outside'. (You may have noticed that function_a also leaks memory as it never deletes the memory that 'a' pointed to before switching to 'c' as well!)

Hopefully this explanation ends up helping someone out there that may encounter this problem, which seems to be some what not well documented and untaught in basic programming classes in school!

Feel free to post about your experiences with references to pointers below.
Thanks!