<?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>19clicks &#187; code</title>
	<atom:link href="http://blog.19clicks.com/articles/category/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.19clicks.com</link>
	<description></description>
	<lastBuildDate>Fri, 06 Mar 2009 23:08:44 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>MailChimp Merge Tag Reference</title>
		<link>http://blog.19clicks.com/2009/03/06/mailchimp-merge-tag-reference/</link>
		<comments>http://blog.19clicks.com/2009/03/06/mailchimp-merge-tag-reference/#comments</comments>
		<pubDate>Fri, 06 Mar 2009 19:08:36 +0000</pubDate>
		<dc:creator>sam</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[work]]></category>

		<guid isPermaLink="false">http://blog.19clicks.com/?p=183</guid>
		<description><![CDATA[Let's face it, the documentation on the MailChimp site is paltry, at best.  I'm going to add things here as I come across them.

First up, full documentation for the DATE merge tag.]]></description>
			<content:encoded><![CDATA[<p>Let&#8217;s face it, the documentation on the MailChimp site is paltry, at best.  I&#8217;m going to add things here as I come across them.</p>
<p>First up, full documentation for the DATE merge tag.</p>
<p><strong>Usage</strong><br />
*|DATE:FORMAT|*<br />
<strong>Format Options</strong><br />
See the <a href="http://us2.php.net/manual/en/function.date.php">PHP Documentation</a> for all the character codes you can use in the FORMAT string. (Thanks for the tip, Chad!)<br />
<strong>Examples</strong><br />
*|DATE:l F jS, Y|* = Monday January 15th, 2009<br />
*|DATE:m/d/y|* = 01/05/09<br />
*|DATE:D j M Y H:ia|* = Mon 15 Jan 2009 05:53pm</p>
<p>Please let me know in the comments if you discover anything is not as documented here (or figure out anything that I haven&#8217;t!)</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.19clicks.com/2009/03/06/mailchimp-merge-tag-reference/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>IE Javascript Peculiarity (likely the first of many posts)</title>
		<link>http://blog.19clicks.com/2007/04/02/ie-javascript-peculiarity-likely-the-first-of-many-posts/</link>
		<comments>http://blog.19clicks.com/2007/04/02/ie-javascript-peculiarity-likely-the-first-of-many-posts/#comments</comments>
		<pubDate>Mon, 02 Apr 2007 20:27:47 +0000</pubDate>
		<dc:creator>sam</dc:creator>
				<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://blog.19clicks.com/2007/04/02/ie-javascript-peculiarity-likely-the-first-of-many-posts/</guid>
		<description><![CDATA[Today I was merrily (for at least the first 2 minutes) trying to get a little script to run correctly in Internet Explorer. Naturally, I had done all of my development on my trusty MacBook, testing it in Firefox. I&#8217;d played with it a bit in Safari and Camino, both nice browsers that ran it [...]]]></description>
			<content:encoded><![CDATA[<p>Today I was merrily (for at least the first 2 minutes) trying to get a little script to run correctly in Internet Explorer. Naturally, I had done all of my development on my trusty MacBook, testing it in Firefox. I&#8217;d played with it a bit in Safari and Camino, both nice browsers that ran it absolutely fine. I hadn&#8217;t bothered to fire up Parallels to test it out in Internet Explorer, mostly because I was a little scared.</p>
<p>Yesterday, I bit the bullet. Thankfully, there weren&#8217;t excessively many issues. The first thing I stumbled upon was that Internet Explorer doesn&#8217;t like the DOM element.getAttribute(&#8217;class&#8217;) method very much (it returns null regardless of whether your element actually has a class.) I was forced to use the less pleasing direct DOM alternative (i.e. element.className.) Similar logic applied to the &#8216;name&#8217; attribute (element.setAttribute(&#8217;name&#8217;, &#8216;x&#8217;) throws an error; element.name = &#8216;x&#8217; doesn&#8217;t.)</p>
<p>The second issue was significantly more irksome, only because it took quite a lot longer to figure out what the hell was going on. This is partly because of the way my script was structured, which only made it more annoying. When creating a form input element dynamically, I was consistently getting the error: &#8216;Could not get the type property.&#8217; This was not good, as there seemed to be no way to create, say, a radio button without setting its type.</p>
<p>To clarify: I wanted to end up with some HTML that looked like &lt;input type=&#8221;radio&#8221; name=&#8221;my_name&#8221; class=&#8221;my_class&#8221; id=&#8221;my_id&#8221; /&gt;. I was using Javascript that looked like this:</p>
<blockquote><p>function createElt(parent_elt, elt_type, elt_id, elt_class) {<br />
var new_elt = document.createElement(elt_type.toUpperCase());<br />
if (elt_id) { new_elt.setAttribute(&#8217;id&#8217;, elt_id); }<br />
if (elt_class) { new_elt.setAttribute(&#8217;class&#8217;, elt_class); }<br />
parent_elt.appendChild(new_elt);<br />
return new_elt;<br />
}</p>
<p>function createFormElt(parent_elt, elt_type, elt_id, elt_class, elt_formtype, elt_name, elt_value, elt_onclick, elt_onfocus, elt_onblur) {<br />
var new_elt = createElt(parent_elt, elt_type, elt_id, elt_class);<br />
if (elt_name) { new_elt.name = elt_name; }<br />
if (elt_formtype) { new_elt.setAttribute(&#8217;type&#8217;, elt_formtype); }<br />
if (elt_value) { new_elt.setAttribute(&#8217;value&#8217;, elt_value); }<br />
if (elt_onclick) { new_elt.onclick = elt_onclick; }<br />
if (elt_onfocus) { new_elt.onfocus = elt_onfocus; }<br />
if (elt_onblur) { new_elt.onblur = elt_onblur; }<br />
return new_elt;<br />
}</p>
<p>createFormElt(parent_elt, &#8216;input&#8217;, &#8216;my_id&#8217;, &#8216;my_class&#8217;, &#8216;radio&#8217;, &#8216;my_name, &#8216;my_value&#8217;, clickMethod, focusMethod, blurMethod);</p></blockquote>
<p>The problem was that Internet Explorer wasn&#8217;t gettin&#8217; down with the idea of setting the &#8216;type&#8217; attribute *after* appending the element to its parent. Never mind that, in theory, I still had a perfectly valid reference to the element in question, nor that setting any other attribute worked just fine. In any case, the solution was just to set the type element before appending. In this case I decided not to use the createElt method for form elements, but I could just as easily have added a parameter for type to createElt.</p>
<p>The code that worked:</p>
<blockquote><p>function createFormElt(parent_elt, elt_type, elt_id, elt_class, elt_formtype, elt_name, elt_value, elt_onclick, elt_onfocus, elt_onblur) {<br />
var new_elt = document.createElement(elt_type);<br />
if (elt_name) { new_elt.name = elt_name; }<br />
if (elt_formtype) { new_elt.setAttribute(&#8217;type&#8217;, elt_formtype); }<br />
if (elt_id) { new_elt.setAttribute(&#8217;id&#8217;, elt_id); }<br />
if (elt_class) { new_elt.setAttribute(&#8217;class&#8217;, elt_class); }<br />
if (elt_value) { new_elt.setAttribute(&#8217;value&#8217;, elt_value); }<br />
if (elt_onclick) { new_elt.onclick = elt_onclick; }<br />
if (elt_onfocus) { new_elt.onfocus = elt_onfocus; }<br />
if (elt_onblur) { new_elt.onblur = elt_onblur; }<br />
parent_elt.appendChild(new_elt);<br />
return new_elt;<br />
}</p>
<p>createFormElt(parent_elt, &#8216;input&#8217;, &#8216;my_id&#8217;, &#8216;my_class&#8217;, &#8216;radio&#8217;, &#8216;my_name, &#8216;my_value&#8217;, clickMethod, focusMethod, blurMethod);</p></blockquote>
<p>Now I just have to get the CSS working&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.19clicks.com/2007/04/02/ie-javascript-peculiarity-likely-the-first-of-many-posts/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>How To Set Up Java, Eclipse, Tomcat, Ant, WTP, Subversion, Subclipse, MySQL, Spring, and GreenUML in OS X (10.4)</title>
		<link>http://blog.19clicks.com/2007/02/07/how-to-set-up-eclipse-3-tomcat-5-5-ant-wtp-subversion-subclipse-mysql-spring-and-greenuml-in-os-x-10-4/</link>
		<comments>http://blog.19clicks.com/2007/02/07/how-to-set-up-eclipse-3-tomcat-5-5-ant-wtp-subversion-subclipse-mysql-spring-and-greenuml-in-os-x-10-4/#comments</comments>
		<pubDate>Wed, 07 Feb 2007 17:25:00 +0000</pubDate>
		<dc:creator>sam</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[work]]></category>

		<guid isPermaLink="false">http://blog.19clicks.com/2007/02/07/how-to-set-up-eclipse-3-tomcat-5-5-ant-wtp-subversion-subclipse-mysql-spring-and-greenuml-in-os-x-10-4/</guid>
		<description><![CDATA[This is how I pulled together my Java dev environment in Tiger.  I started off pretty clueless, and what guidance I could find via Google was fragmented and/or out of date.  So here’s my setup.  If any of you experts out there have suggestions / corrections, please send ‘em my way.
For reference, [...]]]></description>
			<content:encoded><![CDATA[<p>This is how I pulled together my Java dev environment in Tiger.  I started off pretty clueless, and what guidance I could find via Google was fragmented and/or out of date.  So here’s my setup.  If any of you experts out there have suggestions / corrections, please send ‘em my way.</p>
<p>For reference, here are the versions I installed:</p>
<ul>
<li>Java 1.5</li>
<li>Eclipse 3.2</li>
<li>Tomcat 5.5</li>
<li>Ant 1.7</li>
<li><span class="caps">WTP 1</span>.5.2</li>
<li>Subversion 1.3</li>
<li>Subclipse 1.0.5</li>
<li>MySQL 5</li>
<li>Spring 2.0.1</li>
<li>GreenUML 2.5.0</li>
</ul>
<p>1. Install <span class="caps">OS X</span> developer tools</p>
<p>2. Run software update and install all updates (esp. Java—this will update from 1.4 to 1.5)</p>
<p>3. Install MySQL</p>
<ul>
<li>There’s a nice <span class="caps">OS X</span> package at <a href="http://dev.mysql.com/downloads/mysql/5.0.html#downloads">http://dev.mysql.com/downloads/mysql/5.0.html#downloads</a></li>
<li>If desired, install the startup item and preference pane that come along in the install package</li>
</ul>
<p>4. Install Tomcat 5.x</p>
<ul>
<li>Download the Core Binary Distro .tar.gz from <a href="http://tomcat.apache.org/download-55.cgi">http://tomcat.apache.org/download-55.cgi</a></li>
<li>Run the following (in Terminal):</li>
</ul>
<blockquote><p>&gt; sudo su –<br />
&gt; mv /Users/{username}/Desktop/apache-tomcat-5.5.20.tar.gz /usr/local/<br />
&gt; cd /usr/local<br />
&gt; gnutar -xzvf apache-tomcat-5.5.20.tar.gz<br />
&gt; ln -s apache-tomcat-5.5.20 tomcat<br />
&gt; rm apache-tomcat-5.5.20.tar.gz<br />
&gt; chown -R {username}:{username} apache-tomcat-5.5.20</p></blockquote>
<p>5. Install Ant 1.7</p>
<ul>
<li>Download from <a href="http://ant.apache.org/bindownload.cgi">http://ant.apache.org/bindownload.cgi</a></li>
<li>Run the following (in Terminal):</li>
</ul>
<blockquote><p>&gt; mv /Users/{username}/Desktop/apache-ant-1.7.0-bin.tar.gz /usr/local/<br />
&gt; cd /usr/local<br />
&gt; gnutar -xzvf apache-ant-1.7.0-bin.tar.gz<br />
&gt; ln -s apache-ant-1.7.0 ant<br />
&gt; rm apache-ant-1.7.0-bin.tar.gz<br />
&gt; exit</p></blockquote>
<p>6. Install Subversion 1.3</p>
<ul>
<li>Download nice <span class="caps">OS X</span> package from <a href="http://metissian.com/projects/macosx/subversion">http://metissian.com/projects/macosx/subversion</a></li>
</ul>
<p>7. Set <span class="caps">JAVA</span>_HOME / <span class="caps">CATALINA</span>_HOME / <span class="caps">ANT</span>_HOME / <span class="caps">PATH </span></p>
<ul>
<li>Create /Users/{your_username}/.bash_profile if it doesn’t already exist</li>
<li>Add the following to it (using vim, emacs, or your text editor of choice):</li>
</ul>
<blockquote><p>export <span class="caps">JAVA</span>_HOME=”/Library/Java/Home”<br />
export <span class="caps">CATALINA</span>_HOME=”/usr/local/tomcat”<br />
export <span class="caps">ANT</span>_HOME=”/usr/local/ant”<br />
export <span class="caps">PATH</span>=”$PATH:/usr/local/bin:/usr/local/subversion/bin: \<br />
/usr/local/mysql/bin:$ANT_HOME/bin”</p></blockquote>
<p>8. Create a MySQL database and a user for your project</p>
<blockquote><p>&gt; mysql -u root<br />
mysql&gt; <span class="caps">CREATE DATABASE</span> projectdb;<br />
mysql&gt; <span class="caps">GRANT ALL PRIVILEGES ON</span> projectdb.* <span class="caps">TO </span>\<br />
‘projectuser’@’localhost’;<br />
mysql&gt; exit</p></blockquote>
<p>9. Install Eclipse 3.2.1</p>
<ul>
<li>Download from <a href="http://www.eclipse.org/downloads/">http://www.eclipse.org/downloads/</a></li>
<li>Copy to Applications folder</li>
</ul>
<p>10. Install Spring <span class="caps">IDE</span></p>
<ul>
<li>Follow instructions at <a href="http://springide.org/project/wiki/SpringideCallistoInstall">http://springide.org/project/wiki/SpringideCallistoInstall</a></li>
</ul>
<p>11. Install Eclipse Web Tools Project (WTP)</p>
<ul>
<li>As for Spring <span class="caps">IDE</span>, go to Help &gt; Software Updates &gt; Find and Install</li>
<li>Select “Search for new features to install”</li>
<li>Select Callisto Discovery Site, and Web Tools Platform Updates</li>
<li>In the Search Results window, select <span class="caps">WTP </span>Updates &gt; Web Tools Platform and <span class="caps">WTP </span>Patches</li>
<li>Expand Callisto Discovery Site, and click “Select Required”</li>
<li>Click Next, Accept (Next), Finish, (files download) Install All</li>
<li>Restart Eclipse as prompted</li>
<li>Open Eclipse &gt; Preferences</li>
<li>Go to Server &gt; Installed Runtimes</li>
<li>Click “Add”</li>
<li>Find Apache &gt; Apache Tomcat v5.5</li>
<li>Enter /usr/local/tomcat as the Tomcat installation directory</li>
<li>Click Finish, then OK.</li>
</ul>
<p>12. Install Subclipse</p>
<ul>
<li>Download from <a href="http://subclipse.tigris.org">http://subclipse.tigris.org</a></li>
<li>As for Spring <span class="caps">IDE</span>, go to Help &gt; Software Updates &gt; Find and Install</li>
<li>Select “Search for new features to install”</li>
<li>Click “New Remote Site…”</li>
<li>Name the site “Subclipse”; <span class="caps">URL</span>: http://subclipse.tigris.org/update_1.0.x</li>
<li>Click OK</li>
<li>Make sure Subclipse is selected; hit Finish</li>
<li>In Search Results, expand Subclipse and select it</li>
<li>Click Next, Accept (Next), Finish, (files download) Install All</li>
<li>Restart Eclipse as prompted</li>
<li>Open the <span class="caps">SVN </span>Repository perspective and define your repository</li>
</ul>
<p>13. Install GreenUML</p>
<ul>
<li>Download from <a href="http://sourceforge.net/project/showfiles.php?group_id=132685">http://sourceforge.net/project/showfiles.php?group_id=132685</a></li>
<li>Unzip and copy everything in the green_x.x.x/plugins folder to /Applications/eclipse/plugins</li>
<li>Restart Eclipse</li>
</ul>
<p>14a. If you have an existing project, check it out from subversion.</p>
<p>14b. If you need to create a new Spring project, download spring-framework-2.0.1-with-dependencies.zip from <a href="http://www.springframework.org/download">http://www.springframework.org/download</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.19clicks.com/2007/02/07/how-to-set-up-eclipse-3-tomcat-5-5-ant-wtp-subversion-subclipse-mysql-spring-and-greenuml-in-os-x-10-4/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>ASP Blues</title>
		<link>http://blog.19clicks.com/2006/05/08/asp-blues/</link>
		<comments>http://blog.19clicks.com/2006/05/08/asp-blues/#comments</comments>
		<pubDate>Mon, 08 May 2006 11:30:00 +0000</pubDate>
		<dc:creator>sam</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[work]]></category>

		<guid isPermaLink="false">http://blog.19clicks.com/2006/05/08/asp-blues/</guid>
		<description><![CDATA[Warning: this post is pretty boring (so unlike my other musings, which are fascinating without exception). I&#8217;m putting it up here so that anyone else who runs into this problem will find something about it when they search for &#8216;VBScript query string parameter order&#8217; (or somesuch).
Last week, I ran into a bug in a simple [...]]]></description>
			<content:encoded><![CDATA[<p><em>Warning: this post is pretty boring (so unlike my other musings, which are fascinating without exception). I&#8217;m putting it up here so that anyone else who runs into this problem will find something about it when they search for &#8216;VBScript query string parameter order&#8217; (or somesuch).</em></p>
<p>Last week, I ran into a bug in a simple little <span class="caps">ASP</span>/VBScript application I wrote relatively recently. The application does basic routing&#8212;URLs take the form http://www.xyz.com/a/b/c, where &#8216;a/b/c&#8217; means page &#8216;c&#8217; which is a child of page &#8216;b&#8217;, itself a child of page &#8216;a&#8217;. For extensibility’s sake, there is no particular limit on the depth of the page (i.e., http://www.xyz.com/a/b/c/d/e/f/g would also be valid).</p>
<p>Since we&#8217;re an all-M$ shop, we use <span class="caps">IIS</span> with <span class="caps">ISAPI </span>ReWrite to rewrite our URLs. For this particular application, the URLs are rewritten to http://www.xyz.com/index.asp?a=&#38;b=&#38;c (ad nauseum).</p>
<p>My bug, which was noticed months after the application launched, boiled down to this: when a page was opened as the first page in a browser session—e.g. when someone clicked on a link to the page from an e-mail client, and their default browser was not already open—the application would load the page as if the query string parameters were inverted. So, if the page loaded were http://www.xyz.com/index.asp?a=&#38;b=&#38;c, the application would behave as though the query string were &#8216;a=&#38;c=&#38;b&#8217;. All other load methods resulted in the application behaving as expected (&#8216;a=&#38;b=&#38;c&#8217;).</p>
<p>The problem with this was: by design, the application parses the query string left-to-right (i.e. for &#8216;a=&#38;b=&#38;c&#8217;, it checks to see if it can find page &#8216;a&#8217;; then checks for page &#8216;b&#8217; in pages that are stored as children of page &#8216;a&#8217;, then checks for page &#8216;c&#8217; in pages that are children of page &#8216;b&#8217;). If at any point the page isn’t found, the application stops, and returns the latest page as it&#8217;s best guess. This means that inverted query string parameters are quite a problem—&#8217;a=&#38;c=&#38;b&#8217; will check for page &#8216;a&#8217;, find it, then try and look for page &#8216;c&#8217; in the children of page &#8216;a&#8217;. This will fail, since page &#8216;c&#8217; is marked only as a child of page &#8216;b&#8217;. Therefore, the application will return page &#8216;a&#8217;, instead of page &#8216;c&#8217;.</p>
<p>To begin getting to the bottom of things, I printed out the value of the current query string key inside the for each loop I was using to iterate. Sure enough, the first time the link was opened, in any browser, the printout read &#8220;a, c, b&#8221;. After hitting refresh, or loading the page in any way after browser initialization, the printout read &#8220;a, b, c&#8221;.</p>
<p>Obviously, I was at fault here for assuming that the internal representation of a query string maintained order. What I find odd about it is that the order on initial browser load would differ from the order on any other load.</p>
<p>Apparently, this is just one of the vaguaries of the VBScript Collection object (which is really more or less the same thing as a Scripting.Dictionary object). The fix was to change my method of iterating through the query string—instead of using:</p>
<p><code>for each item in querystring</code></p>
<p>I now use:</p>
<p><code>for i = 1 to querystring.count</code></p>
<p>All of this just serves to remind me: I really like a language to call a hash a hash.  You know&#8212;if it is, in fact, a hash.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.19clicks.com/2006/05/08/asp-blues/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
