‘Programming’ Category

JSON Facepalm

Wednesday, June 23rd, 2010

I’ve only recently been dabbling in the world of JSON, and I’m realizing that it is an excellent alternative to XML. Being fairly new to it, however, has found me on a few code-based wild goose chases. For a side project I’m working on, I decided it would be slick to have the chosen value from one HTML select element populate. I found a few code samples and hacked them together to work for my form.

Using the jQuery function $.getJSON, I had it running in no time. Now, keep in mind I was testing in Firefox. More often then not, when I put something together in javascript or jQuery it seems to work flawlessly in Firefox. But when I come to check it in Chrome or Safari, something is amuck.

Have spent a good twenty minutes on the Google tubes searching for what could be the matter, I came up empty handed. After some debugging in the ten line jQuery script, I realized that data from my JSON response wasn’t being passed along. To the JSON I went! And that’s where I found the issue:

[{"key0": "value0", "key1": "value1"},{"key0": "value2, "key1": "value3"},]

Hanging out at the tail end of the string was the wayward ‘,’! No doubt the result of some careless output from the database. It worked like a charm in Chrome after cleaning it up with a simple line of PHP before adding the final ‘]’:

$output = substr($output,'',-1);

So, as you can see, it wasn’t a case of ajax not working in Chrome, but rather a case of invalid JSON working in Firefox. While I appreciate Firefox’s leniency, this isn’t the first time it has bit me the ass. But, in the end, a great lesson learned regarding the output of valid JSON.

Grids in a UITableView?

Thursday, March 25th, 2010

As I explained a few posts ago, one of the reasons I’m firing this site back up is to help fellow developers, programmers and fermentors find answers to their questions.  I spend a good chunk of my day both at home and work Google-ing how to do this or that.

This quick post is to give a little shout out to TJS over at dewpoint.snagdata.com.  In particular, their post titled, Drawing a Grid in a UITableView.  I had a similar experience to the author when I started trying to figure out how to display tabular data within a UITableView.  It seemed like a grid system should be built in, but alas, it was not.  I tried inserting tabs, messing with alignments but nothing really worked.  I considered inserting individual labels into the cell, but I wasn’t sure how to go about it.

After searching for what seemed like an hour, I couldn’t find anything.  Finally, I happened upon TJS’s solution and immediately knew I had found what I was looking for.  After tweaking the label’s size, font color and setting the background color to ‘clear’, I was in business.

So, besides keeping the authors info intact in the file headers, I wanted to give an internet high five and maybe in doing so, help the post get a better positioning in the Googles.  If anyone is having any issues with their Objective C code, feel free to hit me up on Twitter, @mhokie.  I’m by no means an expert, but I’ve learned a few things in the last year or so.

Genetic A/B Testing

Monday, March 8th, 2010

I’m not sure I remember being this excited about a piece of open source code.  While the premise is fairly simple, the algorithms at play and the potential uses are vast.  Before I get too far ahead of myself, please let me clarify.  I’m talking about a piece of software called Genetify.

The code, in a nutshell, allows for the real time testing of variations on aspects of a website.  These aspects range from html elements to css styles to javascript variables.  With a few small lines of javascript and a several variations in the code, you can let ‘genetics’ take care of the rest.  For more information on how the software works, check out the usage section of the Github page.

I first read of this code being used on shoemoney.com.  In the post titled, ‘Split Testing with a Genetic Algorithm’, the company’s CTO explained how he used Genetify to split test several lines of text, colors of buttons and various call to action arrow configurations.  Over several thousand page views, the algorithms eventually determined which combination of elements resulted in the highest success rate.  Read more about how the use of genetic algorithms increased their sales figures in the article.

After poking around a bit, I learned that the software has been around in some form for a while now.  It was set to the back burner for some time while the creators explored a more lucrative version of the concept, SnapAds.  In a November 2008 post, John Resig talks about being very excited about the rumor of the Genetify code being open sourced.  A quick look in the Github history of the project shows that less than one month later, author gregdingle committed the first version.  A year later, we have the most current commit, which is what I’ve been experimenting with.

The most obvious use for this code seems to be for advertisement landing pages and product sales pages.  That being said, I’d love to find a use for it in my freelancing.  Being a web developer first, and barely a designer second, it’s a very intriguing to think that I could allow a site’s user base to determine a very important design decision.  I’d be very interested to know what web designers think of this use of genetic algorithms.

About

mhokieAs a computer science nerd, I enjoy dabbling in all things related to web development and programming. Be it wrangling HTML/CSS across several browsers or harnessing the power of Objective-C while developing iPhone Apps, I enjoy a challenge.

I've recently become a champion of fermentation and all the great things it can do for your body. For the last year or so, I've been dabbling in sauerkraut, kimchi, mead and beer.

My goal for this site is that by posting information regarding my experiences, it will help others where the internets have fallen short. If you have any questions, feel free to contact me, or find me on twitter, @mhokie.

Sponsors

Archives

Categories

Blogroll