<?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>tgreenaway.com &#187; Programming</title>
	<atom:link href="http://tgreenaway.com/tag/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://tgreenaway.com</link>
	<description>Creatively engineered.</description>
	<lastBuildDate>Sat, 30 May 2009 06:06:07 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>jQuery list insertion sort plugin</title>
		<link>http://tgreenaway.com/2009/01/jquery-list-insertion-sort-plugin/</link>
		<comments>http://tgreenaway.com/2009/01/jquery-list-insertion-sort-plugin/#comments</comments>
		<pubDate>Thu, 22 Jan 2009 00:56:42 +0000</pubDate>
		<dc:creator>TCMG</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://tgreenaway.com/?p=221</guid>
		<description><![CDATA[Here&#8217;s a basic jQuery sorting plugin for generic parent child relationships I wrote.
Wherein &#8216;element&#8217; is the html you wish to insert and &#8216;value&#8217; is what the associated weight of the element I&#8217;m inserting. For now it compares the weight value to the DOM text within the other children.


$.fn.insertSort = function(element, value) {
  selector = [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a basic jQuery sorting plugin for generic parent child relationships I wrote.</p>
<p>Wherein &#8216;element&#8217; is the html you wish to insert and &#8216;value&#8217; is what the associated weight of the element I&#8217;m inserting. For now it compares the weight value to the DOM text within the other children.</p>
<pre>
<pre class="brush: jscript;">
$.fn.insertSort = function(element, value) {
  selector = this;
  if ($(selector).length &gt; 0) {
    $(selector).attr(&quot;inserted&quot;, &quot;false&quot;);
    $(selector).children().each(function() {
      if (parseInt($(this).text()) &gt; parseInt(value)) {
        $(this).before(element);
        $(selector).attr(&quot;inserted&quot;, &quot;true&quot;);
        return false;
      }
    });
    if ($(selector).attr(&quot;inserted&quot;) == &quot;false&quot;) {
      $(selector).append(element);
    }
  } else {
    $(selector).append(element);
  }
  $(selector).removeAttr(&quot;inserted&quot;);
};
</pre>
</pre>
<p>It should be noted that this is an <strong>insertion sort</strong>. It&#8217;d be good to extend the plugin to be able to sort an existing piece of html for any parent/child relationship. Possibly with the ability to specify a particular level of depth?</p>
]]></content:encoded>
			<wfw:commentRss>http://tgreenaway.com/2009/01/jquery-list-insertion-sort-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Magento: Listing regions from a country code</title>
		<link>http://tgreenaway.com/2009/01/magento-listing-regions-from-a-country-code/</link>
		<comments>http://tgreenaway.com/2009/01/magento-listing-regions-from-a-country-code/#comments</comments>
		<pubDate>Thu, 15 Jan 2009 02:36:51 +0000</pubDate>
		<dc:creator>TCMG</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[magento]]></category>

		<guid isPermaLink="false">http://tgreenaway.com/?p=212</guid>
		<description><![CDATA[Once and a while you may want to get a collection of the regions that are associated with a country in Magento. For example, the United States is of course a collection of&#8230; states. In Magento these are referred to as regions (Japan&#8217;s prefectures would hence be referred to as regions as well.)
So for a [...]]]></description>
			<content:encoded><![CDATA[<p>Once and a while you may want to get a collection of the regions that are associated with a country in Magento. For example, the United States is of course a collection of&#8230; states. In Magento these are referred to as regions (Japan&#8217;s prefectures would hence be referred to as regions as well.)</p>
<p>So for a given country (and that country&#8217;s ID or country code) you might want to find all the regions in that country. Which are usually used to populate a dropdown menu on the address selection pages or shipping tax pages.</p>
<pre class="brush: php;">

$collection = Mage::getModel('directory/region')-&gt;getResourceCollection()
-&gt;addCountryFilter($this-&gt;getCountryId())
-&gt;load();
</pre>
<p>It&#8217;s great when ORM works for a developer. The problem with Magento I find is the complete lack of documentation. I only discovered the above technique after 20 minutes of grepping the app/code/core directory&#8230; <img src='http://tgreenaway.com/wp-includes/images/smilies/icon_neutral.gif' alt=':|' class='wp-smiley' /> </p>
<p>And remember to use Magento&#8217;s log method:</p>
<pre class="brush: php;">

foreach($collection as $region) {

Mage::log(print_r($region, true));

}
</pre>
<p>Note some of the more useful attributes of that $region object are:</p>
<ul>
<li>$region-&gt;default_name</li>
<li>$region-&gt;code</li>
</ul>
<p>Which give responses along the lines of South Australia and SA, respectively.</p>
]]></content:encoded>
			<wfw:commentRss>http://tgreenaway.com/2009/01/magento-listing-regions-from-a-country-code/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Embedded data extraction</title>
		<link>http://tgreenaway.com/2008/08/embeded-data-extraction/</link>
		<comments>http://tgreenaway.com/2008/08/embeded-data-extraction/#comments</comments>
		<pubDate>Mon, 04 Aug 2008 09:26:49 +0000</pubDate>
		<dc:creator>TCMG</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://tgreenaway.com/?p=10</guid>
		<description><![CDATA[I recently developed a small website that allowed users to add students to a database and then allow them to be assigned software license keys. Part of the problem that the website aimed to solve was that previously students were purchasing the license keys when they weren&#8217;t necessarily entitled to them. Even after writing instructions [...]]]></description>
			<content:encoded><![CDATA[<p>I recently developed a small website that allowed users to add students to a database and then allow them to be assigned software license keys. Part of the problem that the website aimed to solve was that previously students were purchasing the license keys when they weren&#8217;t necessarily entitled to them. Even after writing instructions for those selling the keys there was a failure of the students&#8217; details being checked.</p>
<p>To check the details we required the student&#8217;s surname and access to the <a href="http://www.unimelb.edu.au/cgi-bin/mail/email.pl">University of Melbourne email directory</a>. Not terribly difficult but it did require those selling the keys to open a bookmarked page, enter the surname, browse the search results.</p>
<p>In order to improve accountability and the tracking of the purchases I decided to develop the website to allow the sellers (i.e. the users of the system) to more effectively manage the selling of keys to students. This improved management would hopefully:</p>
<ul>
<li>Stop students from purchasing multiple keys wherein not entitled.</li>
<li>Make sure only eligible students were purchasing keys.</li>
</ul>
<p>The first problem was easily solved by uniquely identifying the students and using the database. I won&#8217;t go into how this was solved as it is fairly trivial. The cool part was the checking of student&#8217;s eligibility for the keys.</p>
<p>Students are only eligible if they are enrolled in certain courses (Computer Science, Software Engineering, Information Science, Melbourne Model IT degrees). At first I linked to the Unimelb email directory on the student creation page. However, I decided I&#8217;d like a solution wherein the user did not even need to leave the website.</p>
<p>Hence, I developed the following Javascript (with <a href="http://jquery.com">jQuery</a> support) to enable an embedded extraction of the Unimelb email directory&#8217;s data:</p>
<pre>
<pre class="brush: jscript;">
\\ A small anchor element with id 'email_check' sits next to the surname input field on the page:
$(&quot;#email_check&quot;).click(function()
{
  \\ The embedded results from the extraction are placed in a div with id 'check_list':
  $(&quot;#check_list&quot;).html(&quot;&quot;);

  \\ The surname input field has id 'surname_field', jQuery allows us to access the value attribute:
  var surname = $(&quot;#surname_field&quot;).attr(&quot;value&quot;);

  \\ .get is a jQuery Ajax function. We're going to invoke another page on the site, parse.php
  \\ and give it the surname we're interested in. The function argument is a callback for when
  \\ the Ajax call is complete. The returned page data is a string called 'page_data'.
  $.get(&quot;./parse.php?surname=&quot; + surname, function(page_data)
  {
    \\ From the page_data we want to look at each of the results. The data is luckily
    \\ grouped within &lt;tr&gt; elements with the class 'vcard':
    $(&quot;tr.vcard&quot;, page_data).each(function ()
    {
      \\ Within these &lt;tr&gt; elements are the full names of the students and their courses,
      \\ kept in &lt;td&gt; elements with classes 'fn' and 'org', respectively.
      var fullname = $(&quot;td.fn&quot;, this).text();
      var course = $(&quot;td.org&quot;, this).text();

      \\ Finally we want return this data to the actual page of our website.
      \\ Using the append function we can drop new HTML into the existing dom:
      $(&quot;#check_list&quot;).append(&quot;&lt;li&gt;&lt;label&gt;&quot; + fullname + &quot;&lt;/label&gt;&quot; + course + &quot;&lt;/li&gt;&quot;);
    });
  });
});</pre>
</pre>
<p>Accessing the off-site web page (the Unimelb email directory) was achieved via the parse.php page on my site, which took the form of:</p>
<pre>
<pre class="brush: php;">
&lt;?php
  $surname = $_GET['surname'];

  $file = fopen(&quot;http://www.unimelb.edu.au/cgi-bin/mail/email.pl?name=&quot;.$surname, &quot;r&quot;);

  while(!feof($file))
  {
    echo fgets($file);
  }
  fclose($file);
?&gt;</pre>
</pre>
<p>The results work quite well. Users of the system are able to easily search for a student&#8217;s surname without having to leave the comforts of our website!</p>
<p>Now if anyone is caught selling keys inappropriately there are absolutely no excuses <img src='http://tgreenaway.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://tgreenaway.com/2008/08/embeded-data-extraction/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
