<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Dither and Bicker</title>
	<atom:link href="http://www.ditherandbicker.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ditherandbicker.com</link>
	<description>Tech Musings, Personal Project Hub</description>
	<lastBuildDate>Thu, 29 Mar 2012 11:36:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Couldn&#8217;t find iOS SDK 5 in Xcode</title>
		<link>http://www.ditherandbicker.com/uncategorized/couldnt-find-ios-sdk-5-in-xcode/</link>
		<comments>http://www.ditherandbicker.com/uncategorized/couldnt-find-ios-sdk-5-in-xcode/#comments</comments>
		<pubDate>Thu, 29 Mar 2012 11:36:40 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.ditherandbicker.com/?p=153</guid>
		<description><![CDATA[Sometimes I spend hours banging my head over dumb problems. I needed some iOS 5 functionality (the built-in JSON serialization) and had the latest version of XCode installed on my Mac. So said the App Store anyway. But in XCode the latest SDK available was 4.3. It took me a while, too long, to figure [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes I spend hours banging my head over dumb problems. I needed some iOS 5 functionality (the built-in JSON serialization) and had the latest version of XCode installed on my Mac.  So said the App Store anyway.  But in XCode the latest SDK available was 4.3.  </p>
<p>It took me a while, too long, to figure out that I&#8217;d locked a previous version of XCode to my dock.  And that previous minor versions of XCode were each standalone applications, so moving from 4.1 to 4.2 meant you had to uninstall 4.1. </p>
<p>The solution was to delete the link from my dock and then to Spotlight search for all the available XCode&#8217;s on my Mac.  The newest version did provide an option to delete older copies on the hard drive. </p>
<div class="fb-like" data-href="http://www.ditherandbicker.com/uncategorized/couldnt-find-ios-sdk-5-in-xcode/" style="" data-send="false" data-layout="standard" data-width="260" data-show-faces="true" data-action="like" data-colorscheme="light"></div>]]></content:encoded>
			<wfw:commentRss>http://www.ditherandbicker.com/uncategorized/couldnt-find-ios-sdk-5-in-xcode/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Programming is hard</title>
		<link>http://www.ditherandbicker.com/uncategorized/programming-is-hard/</link>
		<comments>http://www.ditherandbicker.com/uncategorized/programming-is-hard/#comments</comments>
		<pubDate>Mon, 02 Jan 2012 14:02:06 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.ditherandbicker.com/?p=150</guid>
		<description><![CDATA[After a full week to devote to personal programming projects, and actually devoting a good amount of time to them, I can safely say I&#8217;ve made barely any tangible progress. I tend to forget just how complex even a simple site can be&#8230;]]></description>
			<content:encoded><![CDATA[<p>After a full week to devote to personal programming projects, and actually devoting a good amount of time to them, I can safely say I&#8217;ve made barely any tangible progress.  I tend to forget just how complex even a simple site can be&#8230; </p>
<div class="fb-like" data-href="http://www.ditherandbicker.com/uncategorized/programming-is-hard/" style="" data-send="false" data-layout="standard" data-width="260" data-show-faces="true" data-action="like" data-colorscheme="light"></div>]]></content:encoded>
			<wfw:commentRss>http://www.ditherandbicker.com/uncategorized/programming-is-hard/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>No More Mobile Device Browser Updates&#8230;</title>
		<link>http://www.ditherandbicker.com/uncategorized/no-more-mobile-device-browser-updates/</link>
		<comments>http://www.ditherandbicker.com/uncategorized/no-more-mobile-device-browser-updates/#comments</comments>
		<pubDate>Thu, 20 Oct 2011 12:07:40 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[mobile device browser]]></category>
		<category><![CDATA[scentia mobile]]></category>
		<category><![CDATA[wurfl]]></category>

		<guid isPermaLink="false">http://www.ditherandbicker.com/?p=148</guid>
		<description><![CDATA[So the WURFL group became Scentia Mobile, and along with the change eventually followed stricter and stricter licensing. As it stands now, there&#8217;s no way to use the newer versions of the WURFL xml file in the public sphere, outside of using Scientia-provided APIs. In other words mobile device browser cannot be updated using new [...]]]></description>
			<content:encoded><![CDATA[<p>So the WURFL group became Scentia Mobile, and along with the change eventually followed stricter and stricter licensing.  As it stands now, there&#8217;s no way to use the newer versions of the WURFL xml file in the public sphere, outside of using Scientia-provided APIs.  </p>
<p>In other words mobile device browser cannot be updated using new official WURFL data.  </p>
<p>I&#8217;d hoped that Luca and the Scientia people would&#8217;ve protected their GPL community at the very least given the project&#8217;s community-sourced roots.  Alas, there&#8217;s money to be made in all of this and principles are always the first thing to go. </p>
<div class="fb-like" data-href="http://www.ditherandbicker.com/uncategorized/no-more-mobile-device-browser-updates/" style="" data-send="false" data-layout="standard" data-width="260" data-show-faces="true" data-action="like" data-colorscheme="light"></div>]]></content:encoded>
			<wfw:commentRss>http://www.ditherandbicker.com/uncategorized/no-more-mobile-device-browser-updates/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Simple PHP Database Class</title>
		<link>http://www.ditherandbicker.com/uncategorized/simple-php-database-class/</link>
		<comments>http://www.ditherandbicker.com/uncategorized/simple-php-database-class/#comments</comments>
		<pubDate>Mon, 29 Aug 2011 21:54:48 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.ditherandbicker.com/?p=145</guid>
		<description><![CDATA[It seems in every new project I always need a few core components, one of which is a wrapper for some database functionality. Why a wrapper class? Why not just use the baked-in PHP commands? Well it&#8217;s generally helpful to abstract certain functionality, say if you wind up switching databases from mysql to postgres or [...]]]></description>
			<content:encoded><![CDATA[<p>It seems in every new project I always need a few core components, one of which is a wrapper for some database functionality.  Why a wrapper class? Why not just use the baked-in PHP commands?  Well it&#8217;s generally helpful to abstract certain functionality, say if you wind up switching databases from mysql to postgres or postgres to oracle, you don&#8217;t necessarily want to rewrite every system call, especially since the syntax of the queries will probably be fairly similar. Also you may want to bolster error handling or extend the functionality of the native functions.  </p>
<p>A real world example is PHP&#8217;s decision to phase out its mysql client in favor of mysqli and other variants.  Using a wrapper class can take the pain out of such transitions.</p>
<p>Finding myself rewriting the same DB wrappers over and over again, I&#8217;m putting a fresh one up on Github with an MIT license (i.e. free for personal or commercial use). It&#8217;s pretty simple at this point, accepting only mysql and postgres as database types. </p>
<p>Download or fork it here:  <a href="https://github.com/cbroome/PHP-DB-Class" title="PHP Database Class" target="_blank">https://github.com/cbroome/PHP-DB-Class</a> </p>
<p>Examples from the README file: </p>

<pre name="code" class="php"> 
include 'db.php';

$db = new DB( 'mysql' );

if(!$db->connect('hostname', 'username', 'password', 'database') ) {
	print "Could not connect! \n";
}
else {
	
	$sql = "CREATE TEMPORARY TABLE temp_table( gallons INTEGER, galleons VARCHAR(255))";
	if(!$db->query($sql)) {
		print "Query failed: " . $db->get_error() . "\n"; 
	}
	else 
	{
		print "Query succeeded!\n"; 

		$value1 = $db->clean( "Should get an extra' character? " );
		$value2 = $db->clean( "Imagine this off of a GET var: ';drop temp_table;#" );

		$sql = "INSERT INTO temp_table(gallons, galleons) VALUES
			(100, '$value1'),
			(200, '$value2')";

		print "Running query: \n" . $db->get_sql() . "\n";
		if(!$db->query($sql))
		{
			print "Query failed: " . $db->get_error() . "\n";
		}
		else 
		{
			print "Just ran: " . $db->get_sql() . "; Now let's see what was inserted: \n";
			$sql = "SELECT * FROM temp_table";
			if(!$db->query($sql)) {
				print "Query failed: " . $db->get_error() . "\n"; 
			}
			else {
				while( $row = $db->fetch_assoc()) {
					print_r($row);
				}

				print "Finished \n"; 
			}
		}
	}
}
</pre>
<p>Which results in:</p>

<pre style="overflow: auto;">
$ php driver.php

Query succeeded!
Running query: 
CREATE TEMPORARY TABLE temp_table( gallons INTEGER, galleons VARCHAR(255))
Just ran: INSERT INTO temp_table(gallons, galleons) VALUES
			(100, 'Should get an extra\' character? '),
			(200, 'Imagine this off of a GET var: \';drop temp_table;#'); Now let's see what was inserted: 
Array
(
    [gallons] => 100
    [galleons] => Should get an extra' character? 
)
Array
(
    [gallons] => 200
    [galleons] => Imagine this off of a GET var: ';drop temp_table;#
)
Finished 
</pre>
<div class="fb-like" data-href="http://www.ditherandbicker.com/uncategorized/simple-php-database-class/" style="" data-send="false" data-layout="standard" data-width="260" data-show-faces="true" data-action="like" data-colorscheme="light"></div>]]></content:encoded>
			<wfw:commentRss>http://www.ditherandbicker.com/uncategorized/simple-php-database-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Scourge of Errno.pm on Centos</title>
		<link>http://www.ditherandbicker.com/uncategorized/the-scourge-of-errno-pm-on-centos/</link>
		<comments>http://www.ditherandbicker.com/uncategorized/the-scourge-of-errno-pm-on-centos/#comments</comments>
		<pubDate>Mon, 25 Jul 2011 02:45:17 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://www.ditherandbicker.com/?p=140</guid>
		<description><![CDATA[I took this site down over the weekend to rebuild the underlying system from scratch.  While reinstalling the APC cache for PHP I got a stubborn error: $ pecl install apc downloading APC-3.1.9.tgz ... Starting to download APC-3.1.9.tgz (155,540 bytes) .................................done: 155,540 bytes 54 source files, building running: phpize Configuring for: PHP Api Version: 20090626 [...]]]></description>
			<content:encoded><![CDATA[<p>I took this site down over the weekend to rebuild the underlying system from scratch.  While reinstalling the APC cache for PHP I got a stubborn error:</p>
<pre>
$ pecl install apc
downloading APC-3.1.9.tgz ...
Starting to download APC-3.1.9.tgz (155,540 bytes)
.................................done: 155,540 bytes
54 source files, building
running: phpize
Configuring for:
PHP Api Version:         20090626
Zend Module Api No:      20090626
Zend Extension Api No:   220090626
Errno architecture (i386-linux-thread-multi-2.6.9-42.0.3.elsmp)
does not match executable architecture (i386-linux-thread-multi-2.6.18-53.el5)
at /usr/lib/perl5/site_perl/5.8.8/Errno.pm line 11.

Compilation failed in require at /usr/share/autoconf/Autom4te/XFile.pm line 90.
BEGIN failed--compilation aborted at /usr/share/autoconf/Autom4te/XFile.pm line 90.
Compilation failed in require at /usr/bin/autom4te line 44.
BEGIN failed--compilation aborted at /usr/bin/autom4te line 44.
ERROR: `phpize' failed
</pre>
<p>
I trusted the Centos yum packages to handle all the other system setup stuff so figured the only errors would come from me.  I was actually a bit surprised to see perl used for a PHP application.  Checking around on the web, it seems sometimes a second, conflicting, Errno.pm file will appear from one package or another.  And by the dictates of Murphy’s Law, my system defaulted to the wrong one&#8230;
</p>
<p>
To fix the error I checked for the files and whether they disagreed about my system&#8217;s state:
</p>
<pre>
$ diff /usr/lib/perl5/site_perl/5.8.8/Errno.pm \
  /usr/lib/perl5/5.8.8/i386-linux-thread-multi/Errno.pm

12,13c12,13
< "i386-linux-thread-multi-2.6.9-42.0.3.elsmp" or
< 	die "Errno architecture (i386-linux-thread-multi-2.6.9-42.0.3.elsmp)
does not match executable architecture ($Config{'archname'}-$Config{'osvers'})";
---
> "i386-linux-thread-multi-2.6.18-53.el5" or
> 	die "Errno architecture (i386-linux-thread-multi-2.6.18-53.el5)
does not match executable architecture ($Config{'archname'}-$Config{'osvers'})";
15c15
< $VERSION = "1.10";
---
> $VERSION = "1.09_01";
22,26c22,26
</pre>
<p>
Very inconsistent.  Fortunately, moving the outdated file out of view resolved the issue and I lost nothing more than an hour of my time.
</p>
<pre>
$ sudo mv /usr/lib/perl5/site_perl/5.8.8/Errno.pm ~/Errno.pm
</pre>
<div class="fb-like" data-href="http://www.ditherandbicker.com/uncategorized/the-scourge-of-errno-pm-on-centos/" style="" data-send="false" data-layout="standard" data-width="260" data-show-faces="true" data-action="like" data-colorscheme="light"></div>]]></content:encoded>
			<wfw:commentRss>http://www.ditherandbicker.com/uncategorized/the-scourge-of-errno-pm-on-centos/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mobile Device Browser Updated</title>
		<link>http://www.ditherandbicker.com/uncategorized/mobile-device-browser-updated/</link>
		<comments>http://www.ditherandbicker.com/uncategorized/mobile-device-browser-updated/#comments</comments>
		<pubDate>Sun, 26 Jun 2011 18:50:07 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[mobile device browser]]></category>
		<category><![CDATA[wurfl capabilities browser]]></category>

		<guid isPermaLink="false">http://www.ditherandbicker.com/?p=134</guid>
		<description><![CDATA[This release brings it up to version &#8220;db.scientiamobile.com &#8211; 2011-06-16 12:51:18&#8243;. Check it out: http://www.mobiledevicebrowser.com]]></description>
			<content:encoded><![CDATA[<p>This release brings it up to version &#8220;db.scientiamobile.com &#8211; 2011-06-16 12:51:18&#8243;.  Check it out: http://www.mobiledevicebrowser.com</p>
<div class="fb-like" data-href="http://www.ditherandbicker.com/uncategorized/mobile-device-browser-updated/" style="" data-send="false" data-layout="standard" data-width="260" data-show-faces="true" data-action="like" data-colorscheme="light"></div>]]></content:encoded>
			<wfw:commentRss>http://www.ditherandbicker.com/uncategorized/mobile-device-browser-updated/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WURFL Capability Browser = Mobile Device Browser (dot com)</title>
		<link>http://www.ditherandbicker.com/uncategorized/wurfl-capability-browser-mobile-device-browser-dot-com/</link>
		<comments>http://www.ditherandbicker.com/uncategorized/wurfl-capability-browser-mobile-device-browser-dot-com/#comments</comments>
		<pubDate>Tue, 12 Apr 2011 23:43:49 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.ditherandbicker.com/?p=135</guid>
		<description><![CDATA[I&#8217;m moving the WURFL Capability Browser to its own domain with a slightly different name (and look):  http://www.mobiledevicebrowser.com So there it is. &#160;]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m moving the WURFL Capability Browser to its own domain with a slightly different name (and look):  <a title="Mobile Device Browser " href="http://www.mobiledevicebrowser.com" target="_blank">http://www.mobiledevicebrowser.com</a></p>
<p>So there it is.</p>
<p>&nbsp;</p>
<div class="fb-like" data-href="http://www.ditherandbicker.com/uncategorized/wurfl-capability-browser-mobile-device-browser-dot-com/" style="" data-send="false" data-layout="standard" data-width="260" data-show-faces="true" data-action="like" data-colorscheme="light"></div>]]></content:encoded>
			<wfw:commentRss>http://www.ditherandbicker.com/uncategorized/wurfl-capability-browser-mobile-device-browser-dot-com/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Spoofing Those Bitly Alpha-Numeric Keys in  MySQL</title>
		<link>http://www.ditherandbicker.com/programming/spoof_alpha_numeric_keys_in_mysql/</link>
		<comments>http://www.ditherandbicker.com/programming/spoof_alpha_numeric_keys_in_mysql/#comments</comments>
		<pubDate>Sat, 26 Mar 2011 15:21:44 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[databases]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[alpha numeric keys]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://www.ditherandbicker.com/?p=126</guid>
		<description><![CDATA[Recently I was tasked with making an internal “link shortener”, a la Bit.ly’s.  For those that are unfamiliar with the concept, if you have an exceedingly long url that’s difficult to remember i.e. http://us.rd.yahoo.com/dailynews/external/ap_av/av_ap3_wl/92a15245e85f7ca01a3a65b88ede5075/39997189;_ylt=AvuGi5zx_KMlvJdMHmFncMoUewgF;_ylu=X3oDMTFhanRoYjYwBHBvcwM5BHNlYwN5bl9yXzNzbG90X3ZpZGVvBHNsawN2aWQtZWQtbGluaw&#8211;/*http://news.yahoo.com/video/world-15749633/24062366 You can use a shortener to make it more manageable.  Bitly compressed the  example URL above to: http://bit.ly/g25djH much easier to [...]]]></description>
			<content:encoded><![CDATA[<p>Recently  I was tasked with making an internal “link shortener”, a la Bit.ly’s.   For those that are unfamiliar with the concept, if you have an  exceedingly long url that’s difficult to remember i.e.</p>
<p><a href="http://us.rd.yahoo.com/dailynews/external/ap_av/av_ap3_wl/92a15245e85f7ca01a3a65b88ede5075/39997189;_ylt=AvuGi5zx_KMlvJdMHmFncMoUewgF;_ylu=X3oDMTFhanRoYjYwBHBvcwM5BHNlYwN5bl9yXzNzbG90X3ZpZGVvBHNsawN2aWQtZWQtbGluaw--/*http://news.yahoo.com/video/world-15749633/24062366">http://us.rd.yahoo.com/dailynews/external/ap_av/av_ap3_wl/92a15245e85f7ca01a3a65b88ede5075/39997189;_ylt=AvuGi5zx_KMlvJdMHmFncMoUewgF;_ylu=X3oDMTFhanRoYjYwBHBvcwM5BHNlYwN5bl9yXzNzbG90X3ZpZGVvBHNsawN2aWQtZWQtbGluaw&#8211;/*http://news.yahoo.com/video/world-15749633/24062366</a></p>
<p>You can use a shortener to make it more manageable.  Bitly compressed the  example URL above to: <a href="http://bit.ly/g25djH">http://bit.ly/g25djH</a> much easier to remember, much easier to distribute.</p>
<p>So  I wanted similar functionality.  I want to be able to generate a short,  unique key to represent a long url.  Most relational databases already  use some form of base-ten integers (i.e. 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,  11, 12, 13&#8230; so forth)  for keys on their tables.  This is pretty well  established, there are either auto increment support or sequences  depending on the database that will keep track of these values for you. I  could use these keys for shortening, but in the offshoot chance this  feature took off it wouldn’t be too long before the integer numbers  would get pretty long themselves, plus its generally advisable to mask  the real table ids from the public eye.</p>
<p>So back to that url that <a href="http://bit.ly/">bit.ly</a> generated for me: <a href="http://bit.ly/g25djH">http://bit.ly/g25djH</a>.   “g25djH” is obviously a key that translates to a row in a database  somewhere that holds the original long url. Given that databases prefer  numeric keys, what’s to make of bit.ly’s alpha numeric version?  By  using upper and lower case letters in their keys, they save a ton of  space.</p>
<p>To  wit:  with a decimal representation of a number, each digit represents  10^x.  If you add lowercase letters (a-z), each digit represents 36^x.   Much larger values can be represented with fewer digits. So the  standard ASCII character set provides for a couple hundred or so  characters with which to construct an alpha numeric key, but the ten  digits and twenty six lower-case letters are enough for my needs, and  this example.</p>
<p>But  still, how should you leverage a database to store these keys?  You  could make a varchar column a primary key and store these alpha-numeric  values, but that wouldn’t be practical as the dataset grew not to  mention if you wanted to use this value as a foreign key elsewhere.  You  could have a standard int-type primary key and a second key for the  alpha-numeric representation, this is closer to ideal but the extra  column is wasted space.</p>
<p>The  best solution, in my opinion, is to make a function that will convert  the standard base 10 integer into a base 36 value.  This is essentially  the same process as converting a decimal to hexidecimal value, but with a  whole slew of characters.  Therefore you get your condensed  alpha-numeric keys while only using the standard int-type primary key.</p>
<p>This  is functionality I’d like the db to have so I can translate keys  directly in the sql.  To accomplish this I’ve written two functions, one  to convert an int to an alpha numeric key, and the other to convert an  alpha numeric key to an int:</p>

<pre class="sql" name="code">DELIMITER $$
DROP FUNCTION IF EXISTS ConvertIntToKey$$
CREATE FUNCTION ConvertIntToKey(intval INT )
RETURNS VARCHAR(100)
DETERMINISTIC
BEGIN
DECLARE i INT;
DECLARE d INT;
DECLARE r INT;
DECLARE dMoinsR INT;
DECLARE ch CHAR(1);
DECLARE result VARCHAR(200);

SET result = '';
SET d = intval;
REPEAT
SET r = MOD(d, 36);
SET ch = SUBSTR("0123456789abcdefghijklmnopqrstuvwxyz", (r+1), 1);
SET result = CONCAT( ch, result);
SET dMoinsR = d - r;
SET d = (dMoinsR / 36);
UNTIL (dMoinsR = 0)
END REPEAT;

RETURN result;
END$$

DELIMITER ;

DELIMITER $$
DROP FUNCTION IF EXISTS ConvertKeyToInt$$
CREATE FUNCTION ConvertKeyToInt( keyval VARCHAR(100) )
RETURNS INT
DETERMINISTIC
BEGIN
DECLARE backwards VARCHAR(100);
DECLARE keylen INT;
DECLARE intval INT;
DECLARE i INT;
DECLARE rootval INT;

SET backwards = REVERSE(keyval);
SET keylen = CHAR_LENGTH(keyval);
SET i = 0;
SET intval = 0;
SET rootval = 0;

WHILE i &lt; keylen DO
SET rootval = POW(36, i) * (LOCATE(SUBSTR(backwards, (i+1), 1), "0123456789abcdefghijklmnopqrstuvwxyz") - 1);
SET intval = intval + rootval;
SET i = i + 1;
END WHILE;

RETURN intval;
END$$
DELIMITER ;</pre>
<p>Because these are functions&#8211;not procedures&#8211;you can slot these right into a SQL query.</p>
<p>So the user types in <a href="http://your.bitly.clone/aba1">http://your.bitly.clone/aba1</a></p>
<p>“aba1” is the key.</p>
<p>Your SQL query would look like:</p>

<pre class="sql" name="code">SELECT su.id, ConvertIntToKey(su.id), su.full_url
FROM stored_urls su
WHERE su.id = ConvertKeyToInt(“aba1”);</pre>
<p>Also, credit where credit&#8217;s due, I basically modified the hex to decimal conversion up on wikipedia: <a href="http://en.wikipedia.org/wiki/Hexadecimal#Converting_from_other_bases" target="_blank">http://en.wikipedia.org/wiki/Hexadecimal#Converting_from_other_bases </a></p>
<div class="fb-like" data-href="http://www.ditherandbicker.com/programming/spoof_alpha_numeric_keys_in_mysql/" style="" data-send="false" data-layout="standard" data-width="260" data-show-faces="true" data-action="like" data-colorscheme="light"></div>]]></content:encoded>
			<wfw:commentRss>http://www.ditherandbicker.com/programming/spoof_alpha_numeric_keys_in_mysql/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Python vs the 7th Guest</title>
		<link>http://www.ditherandbicker.com/programming/python-vs-the-7th-guest/</link>
		<comments>http://www.ditherandbicker.com/programming/python-vs-the-7th-guest/#comments</comments>
		<pubDate>Sat, 12 Mar 2011 15:47:22 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[7th guest]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.ditherandbicker.com/?p=117</guid>
		<description><![CDATA[&#160; Recently I&#8217;ve been catching up on all the games I missed back in the late eighties and nineties.  Thanks to Steam, the Mac Games Store (﻿http://www.macgamestore.com/), Good Old Games (http://gog.com), iTunes, and of course the random altruistic blog poster. So I&#8217;ve finally started on the 7th guest.   I won&#8217;t lie, I&#8217;ve never been very [...]]]></description>
			<content:encoded><![CDATA[<p>&nbsp;</p>
<p>Recently I&#8217;ve been catching up on all the games I missed back in the late eighties and nineties.  Thanks to Steam, the Mac Games Store (﻿http://www.macgamestore.com/), Good Old Games (http://gog.com), iTunes, and of course the random altruistic blog poster. So I&#8217;ve finally started on the 7th guest.   I won&#8217;t lie, I&#8217;ve never been very good at pure puzzlers, but the main difference between myself today and fifteen odd years ago is that I&#8217;m more comfortable with letting computers solve these damn things for me. I&#8217;ve also been looking for excuses to practice python, so its two bird with one stone&#8230;</p>
<p>&nbsp;</p>
<p>The puzzle in question is the queens problem:  arrange eight queens on a chessboard such that none would &#8220;attack&#8221; each other in chess rules.  That&#8217;s to say that one queen cannot be on the same vertical, horizontal, or diagonal path as another.</p>
<div align="center">
<a href="http://www.ditherandbicker.com/wp-content/uploads/2011/03/7th_guest-copy.jpg"><img class="aligncenter size-full wp-image-118" title="7th guest queen puzzle" src="http://www.ditherandbicker.com/wp-content/uploads/2011/03/7th_guest-copy.jpg" alt="" width="512" height="384" /></a>
</div>
<p>&nbsp;</p>
<p>So first off what are a few rules:</p>
<ul>
<li>There can be only one queen per row, per column.  Because of this I only need a one dimensional array to store the values. My array will track the column of a queen, each index will correspond to a different row. A chessboard is 8&#215;8, so the array will have eight indexes, counted 0-7</li>
<li>A vertical mismatch can then be determined if any of the &#8220;column&#8221; values occur more than once in the array.</li>
<li>A diagonal mismatch is a little trickier.  For my purposes, two points (x<sub>i</sub>, y<sub>i</sub> and x<sub>j</sub>, y<sub>j</sub>) are diagonal to each other if |x<sub>i</sub> &#8211; x<sub>j</sub>| == |y<sub>i</sub> -y<sub>j</sub>|</li>
</ul>
<p>So those rules being determined, there&#8217;s a matter of how to feed in the various board configurations to test.  I could nest eight loops and run through each, but that&#8217;d take forever.</p>
<p>Since I&#8217;m using a one dimensional array to track this, a sample line would look like:</p>
<p>[0,1,2,3,4,5,6,7] or [0,2,1,3,5,4,6,7]</p>
<p>Every index could only hold a value from zero to seven. The starting array would look like [0,0,0,0,0,0,0,0] and the ending array would look like [7,7,7,7,7,7,7,7].   Well I want this to be in a single loop, I thought what if I just looped through a set number from 0 to the final value.  My math&#8217;s a bit shaky, and statistics were never a strong suit, but looking at these numbers again, the question became very simple.  Finding the maximum number of loops is pretty tricky in decimal (base ten) logic, but all these indexes could only go up to eight.  Fortunately Python supports base eight (aka octal) arithmetic right out of the box.  If counted in octal, converted the counter to a string and then sliced the resulting characters into an array, I could find all possible combinations in one loop and then process accordingly.</p>
<p>&nbsp;</p>

<pre name="code" class="python">
def printBoard( board ):
    for row in range(0, 8):
        rowstring = ''

        for col in range(0, 8):
            if(board[row] == col):
                rowstring += 'q'
            else :
                rowstring += '_'
            rowstring += ' '
        
        print rowstring
        
    print '\n\n'
    return


success_count = 0

for i in range (0, 0100000000):
    octa = int( oct(i) )
    mask = '%(#)09d' % { "#" : octa }
    
    board = [ int(mask[1]), int(mask[2]), int(mask[3]), int(mask[4]), int(mask[5]), int(mask[6]), int(mask[7]), int(mask[8]) ];
    
    works = 1
    
    for rowindex in range(0, 8):

        for testindex in range(0, 8):
            
            if(testindex != rowindex):
                
                #check for horizontal
                if( board[testindex] == board[rowindex] ):                    
                    works = 0
                    break
                
                # check for diagonal
                if( abs(testindex - rowindex) == abs(board[testindex] - board[rowindex]) ):
                    works = 0
                    break
        
        if(works == 0):
            break
        
    if(works == 1) :
        success_count = success_count + 1
        print "Board ", success_count
        printBoard( board )

</pre>
</pre>
<p>&nbsp;</p>
<p>As it turns out, there&#8217;s ninety two solutions to this puzzle, meaning I probably would&#8217;ve guessed the answer faster than coding had I stuck with it but c&#8217;est la vie.</p>
<p>And not to keep you in suspense, here&#8217;s one of the valid solutions to the puzzle:</p>

<pre>
_ _ _ _ _ q _ _ 
_ _ _ q _ _ _ _ 
q _ _ _ _ _ _ _ 
_ _ _ _ q _ _ _ 
_ _ _ _ _ _ _ q 
_ q _ _ _ _ _ _ 
_ _ _ _ _ _ q _ 
_ _ q _ _ _ _ _ 
</pre>
<div class="fb-like" data-href="http://www.ditherandbicker.com/programming/python-vs-the-7th-guest/" style="" data-send="false" data-layout="standard" data-width="260" data-show-faces="true" data-action="like" data-colorscheme="light"></div>]]></content:encoded>
			<wfw:commentRss>http://www.ditherandbicker.com/programming/python-vs-the-7th-guest/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Wurfl Capability Browser: Major Update</title>
		<link>http://www.ditherandbicker.com/wurfl-capability-browser/wurfl-capability-browser-major-update/</link>
		<comments>http://www.ditherandbicker.com/wurfl-capability-browser/wurfl-capability-browser-major-update/#comments</comments>
		<pubDate>Thu, 24 Feb 2011 04:31:27 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[site updates]]></category>
		<category><![CDATA[Wurfl Capability Browser]]></category>

		<guid isPermaLink="false">http://www.ditherandbicker.com/?p=108</guid>
		<description><![CDATA[So today marks the release of the newest version of the Wurfl browser (http://wurfl.ditherandbicker.com).  In brief the changes encapsulate: Moved db to MySQL from Postgress.  I&#8217;ve written about the issues with Postgres before (http://www.ditherandbicker.com/wurfl-capability-browser/postgres-initial-impressions/) and finally decided it was in my best interests to make the switch. Added a fancy dhtmlx (http://www.dhtmlx.com) grid to allow [...]]]></description>
			<content:encoded><![CDATA[<p>So today marks the release of the newest version of the Wurfl browser (<a href="http://wurfl.ditherandbicker.com">http://wurfl.ditherandbicker.com</a>).  In brief the changes encapsulate:</p>
<ul>
<li>Moved db to MySQL from Postgress.  I&#8217;ve written about the issues with Postgres before (<a href="http://www.ditherandbicker.com/wurfl-capability-browser/postgres-initial-impressions/">http://www.ditherandbicker.com/wurfl-capability-browser/postgres-initial-impressions/</a>) and finally decided it was in my best interests to make the switch.</li>
<li>Added a fancy dhtmlx (<a href="http://www.dhtmlx.com" target="_blank">http://www.dhtmlx.com</a>) grid to allow dynamic sorting and filtering of result sets.</li>
<li>Limited searches to devices released in the past five years (all in the name of improving speed, I assure you).</li>
<li>Updated to the Wurfl file released Feb 3, 2011</li>
<li>Added a group/capability tree browser.</li>
<li>Capabilities will generally have some descriptive info about what they represent.  These were ripped from: <a href="http://wurfl.sourceforge.net/help_doc.php" target="_blank">http://wurfl.sourceforge.net/help_doc.php</a></li>
<li>You won&#8217;t have to specify search criteria for a capability to see it in the final output.</li>
<li>The capabilities that can be searched against or returned are now limited to five, down from ten.</li>
<li>The &#8220;describe device&#8221; ain&#8217;t there anymore.</li>
<li>XML exporting is also gone.</li>
</ul>
<p>As before, I haven&#8217;t put much focus on IE compatibility, given that I don&#8217;t have easy access to a Windows computer outside of the workplace.  IE fixes will probably be forthcoming.</p>
<p>This will probably be the last &#8220;major&#8221; revision to the tool.  Here on out I&#8217;ll try to update the underlying db a few times a year and may play with the styling some more.</p>
<div class="fb-like" data-href="http://www.ditherandbicker.com/wurfl-capability-browser/wurfl-capability-browser-major-update/" style="" data-send="false" data-layout="standard" data-width="260" data-show-faces="true" data-action="like" data-colorscheme="light"></div>]]></content:encoded>
			<wfw:commentRss>http://www.ditherandbicker.com/wurfl-capability-browser/wurfl-capability-browser-major-update/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

