<?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/"
	>

<channel>
	<title>unitstep.net &#187; guides</title>
	<atom:link href="http://unitstep.net/blog/category/guides/feed/" rel="self" type="application/rss+xml" />
	<link>http://unitstep.net</link>
	<description>the home of peter chng</description>
	<pubDate>Tue, 30 Dec 2008 19:37:22 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Extracting X509 Extensions from a CSR using the Bouncy Castle APIs</title>
		<link>http://unitstep.net/blog/2008/10/27/extracting-x509-extensions-from-a-csr-using-the-bouncy-castle-apis/</link>
		<comments>http://unitstep.net/blog/2008/10/27/extracting-x509-extensions-from-a-csr-using-the-bouncy-castle-apis/#comments</comments>
		<pubDate>Tue, 28 Oct 2008 02:01:07 +0000</pubDate>
		<dc:creator>Peter Chng</dc:creator>
		
		<category><![CDATA[X.509]]></category>

		<category><![CDATA[certificates]]></category>

		<category><![CDATA[cryptography]]></category>

		<category><![CDATA[guides]]></category>

		<category><![CDATA[java]]></category>

		<category><![CDATA[pki]]></category>

		<category><![CDATA[programming]]></category>

		<category><![CDATA[tutorials]]></category>

		<category><![CDATA[ca]]></category>

		<category><![CDATA[certificate]]></category>

		<category><![CDATA[certificate request]]></category>

		<category><![CDATA[csr]]></category>

		<category><![CDATA[guide]]></category>

		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://unitstep.net/?p=407</guid>
		<description><![CDATA[The Bouncy Castle Cryptography Java APIs are an excellent set of APIs that act as a provider for JCE and JCA.  Additionally, they take care of the mundane and tedious (some would say overly complicated) details involved in reading and creating the data structures associated with the X.500 and PKCS standards. (The APIs are [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://bouncycastle.org/">Bouncy Castle Cryptography Java APIs</a> are an excellent set of APIs that act as a provider for JCE and JCA.  Additionally, they take care of the mundane and tedious (some would say overly complicated) details involved in reading and creating the data structures associated with the X.500 and PKCS standards. (The APIs are also available in C#, for .NET developers out there)</p>
<p>One thing they handle well is the concept of certificate extensions.  X.509 v3 certificates introduced the concept of these extensions, which are basically additional (potentially optional) fields containing information not contained in the older original X.509 specifications.  Each extension is specified by an OID (Object Identifier); a good <a href="http://www.alvestrand.no/objectid/2.5.29.html">list of these extensions</a> is available.</p>
<p>While it&#8217;s easy to read these extensions from an existing X.509 v3 certificate using the Bouncy Castle APIs it is a bit more involved to read these extensions from a <a href="http://en.wikipedia.org/wiki/Certificate_signing_request">Certificate Signing Request</a>, or CSR; this is the data structure that is sent to a CA to request a certificate.  The CA then reads the data from this and creates a signed certificate issued to the requester.  In this guide I&#8217;ll present a brief way to extract X.509 <a href="http://www.alvestrand.no/objectid/submissions/1.2.840.113549.1.9.14.html">extensions request</a> from a CSR so that they may be included in the resulting issued certificate.</p>
<h3>Code: The good stuff</h3>
<p>Assuming you have added the Bouncy Castle JARs to your classpath, you should have access to the classes used here.  </p>
<p>You must first have the CSR in the format of a Bouncy Castle data object, namely the <a href="http://www.cs.berkeley.edu/~jonah/bc/org/bouncycastle/jce/PKCS10CertificationRequest.html"><code>PKCS10CertificationRequest</code></a>. If all you have is the PEM-format of the CSR (i.e. Base64-encoded contents delimited by headers like <code>----- BEGIN CERTIFICATE REQUEST -----</code> and <code>----- END CERTIFICATE REQUEST -----</code>) then you will need to convert  this to the proper data structure using something like<br />
<a href="http://juliusdavies.ca/commons-ssl/javadocs/org/apache/commons/ssl/PEMUtil.html">PEMUtil</a> from Commons-SSL like I have done below.  (BC has a <a href="http://www.eecs.berkeley.edu/~jonah/javadoc/org/bouncycastle/jce/provider/PEMUtil.html">PEMUtil</a> class as well, but it appears to be only for internal use)</p>
<pre><code>// NOTE: Commons-SSL doesn't support generics.
final List pemItems = PEMUtil.decode( csrContent.getBytes() );

// Verify list isn't empty - uses Apache Commons Lang.
Validate.isTrue( !pemItems.isEmpty() );

// No support for generics, so have to cast. (Could have cast the entire List)
final PEMItem csrPemFormat = (PEMItem) pemItems.get( 0 );

// Verify the type.
Validate.isTrue( csrPemFormat.pemType.equals( "CERTIFICATE REQUEST" ),
  "This is not a CSR" );

final PKCS10CertificationRequest csr = new PKCS10CertificationRequest(
  csrPemFormat.getDerBytes() );</code></pre>
<p>We first decode the PEM (Base64) CSR into <code>List</code> of <a href="http://juliusdavies.ca/commons-ssl/javadocs/org/apache/commons/ssl/PEMItem.html"><code>PEMItem</code></a>s. Note that Commons-SSL doesn&#8217;t support <a href="http://java.sun.com/j2se/1.5.0/docs/guide/language/generics.html">generics</a>, so you are going to get a cast warning somewhere in the code, no matter what.  When calling <code>getBytes()</code> on the CSR string, you may want to specify the <code>US-ASCII</code> character set, since the no-arg method uses the platform default character set, which might give inconsistent results across different systems when converting from characters to bytes. </p>
<p>We then grab the first entry in the list, checking if it is a CSR.  We can now convert this into the proper data structure by supplying the raw bytes (i.e. the DER-encoded format) to the constructor of <code>PKCS10CertificationRequest</code>.</p>
<p>The method to extract the <a href="http://www.cs.berkeley.edu/~jonah/bc/org/bouncycastle/asn1/x509/X509Extensions.html"><code>X509Extensions</code></a> structure from the <code>PKCS10CertificationRequest</code> is shown below.</p>
<pre><code>   /**
    * Gets the X509 Extensions contained in a CSR (Certificate Signing Request).
    *
    * @param certificateSigningRequest the CSR.
    * @return the X509 Extensions in the request.
    * @throws CertificateException if the extensions could not be found.
    */
   X509Extensions getX509ExtensionsFromCsr(
         final PKCS10CertificationRequest certificateSigningRequest ) throws CertificateException
   {
      final CertificationRequestInfo certificationRequestInfo = certificateSigningRequest
            .getCertificationRequestInfo();

      final ASN1Set attributesAsn1Set = certificationRequestInfo.getAttributes();

      // The `Extension Request` attribute is contained within an ASN.1 Set,
      // usually as the first element.
      X509Extensions certificateRequestExtensions = null;
      for (int i = 0; i &lt; attributesAsn1Set.size(); ++i)
      {
         // There should be only only one attribute in the set. (that is, only
         // the `Extension Request`, but loop through to find it properly)
         final DEREncodable derEncodable = attributesAsn1Set.getObjectAt( i );
         if (derEncodable instanceof DERSequence)
         {
            final Attribute attribute = new Attribute( (DERSequence) attributesAsn1Set
                  .getObjectAt( i ) );

            if (attribute.getAttrType().equals( PKCSObjectIdentifiers.pkcs_9_at_extensionRequest ))
            {
               // The `Extension Request` attribute is present.
               final ASN1Set attributeValues = attribute.getAttrValues();

               // The X509Extensions are contained as a value of the ASN.1 Set.
               // Assume that it is the first value of the set.
               if (attributeValues.size() &gt;= 1)
               {
                  certificateRequestExtensions = new X509Extensions( (ASN1Sequence) attributeValues
                        .getObjectAt( 0 ) );

                  // No need to search any more.
                  break;
               }
            }
         }
      }

      if (null == certificateRequestExtensions)
      {
         throw new CertificateException( "Could not obtain X509 Extensions from the CSR" );
      }

      return certificateRequestExtensions;
   }</code></pre>
<p>Basically, we get the certificate request info from the CSR structure and then extract attributes from it.  Then, we loop through to find the attribute with the <a href="http://www.alvestrand.no/objectid/submissions/1.2.840.113549.1.9.14.html">&#8220;Extension Request&#8221; OID</a>.</p>
<p>After that, I make an assumption that the actual extensions are contained in the first value of the place of the ASN.1 Set that makes up the &#8220;Extensions Request&#8221; structure - not a big assumption, and in my testing I haven&#8217;t encountered a situation where this wasn&#8217;t the case.  It&#8217;s worthwhile to keep in mind that ASN.1 often prescribes Set or multi-value structures in places where the underlying data can  only be single-valued. </p>
<p>After running through that code, we&#8217;ll have either found the extensions, and be returning them in a <a href="http://www.cs.berkeley.edu/~jonah/bc/org/bouncycastle/asn1/x509/X509Extensions.html"><code>X509Extensions</code></a> structure, or an exception will be thrown.  You could modify the code to return <code>null</code> if that suits your style or purpose better.</p>
<h3>A few more notes</h3>
<p>Once you have the <code>X509Extensions</code> structure you can use the extensions contained within to create/issue a certificate with them.  Check out the <a href="http://www.bouncycastle.org/wiki/display/JA1/X.509+Public+Key+Certificate+and+Certification+Request+Generation">Bouncy Castle Guide on Certificate Generation</a> for more details.</p>
<p>Note that a CA is <em>not required</em> to use any of the extension requests present in a CSR - hence the name &#8220;requests&#8221;.  It is entirely up to the CA to decide what extensions are appropriate, along with their values, for the certificates that it issues.  </p>
<h3>Code Review</h3>
<p>The code is a little complicated and could probably benefit from some refactoring.  However, a lot of the complexity derives from the fact that the X.509 and associated standards are quite complex themselves.  This is a reflection on the vision that the designers of X.509 had for the future of the standard.  However, the <a href="http://www.cs.auckland.ac.nz/~pgut001/pubs/x509guide.txt">complexity of X.509</a> is another topic for another article.  </p>
<p>I hope you found this article useful, as while I found lots of information for <a href="http://www.bouncycastle.org/wiki/display/JA1/X.509+Public+Key+Certificate+and+Certification+Request+Generation">generating CSRs</a>, information on parsing and working with them was a little sparse.  Please feel free to leave your comments below!</p>
<hr/>Copyright &copy; 2009 <strong><a href="http://unitstep.net">unitstep.net</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please contact <strong><a href="mailto:webmaster@unitstep.net">webmaster@unitstep.net</a></strong> for more information.<br/><span style="float: right;font-size: 7pt"><a href="http://blog.taragana.com/index.php/archive/wordpress-plugins-provided-by-taraganacom/">Plugin</a> by <a href="http://www.taragana.com/">Taragana</a></span>]]></content:encoded>
			<wfw:commentRss>http://unitstep.net/blog/2008/10/27/extracting-x509-extensions-from-a-csr-using-the-bouncy-castle-apis/feed/</wfw:commentRss>
		</item>
		<item>
		<title>JavaScript and inheritance</title>
		<link>http://unitstep.net/blog/2008/01/24/javascript-and-inheritance/</link>
		<comments>http://unitstep.net/blog/2008/01/24/javascript-and-inheritance/#comments</comments>
		<pubDate>Fri, 25 Jan 2008 03:22:35 +0000</pubDate>
		<dc:creator>Peter Chng</dc:creator>
		
		<category><![CDATA[JavaScript]]></category>

		<category><![CDATA[guides]]></category>

		<category><![CDATA[inheritance]]></category>

		<category><![CDATA[programming]]></category>

		<category><![CDATA[prototype]]></category>

		<guid isPermaLink="false">http://unitstep.net/blog/2008/01/24/javascript-and-inheritance/</guid>
		<description><![CDATA[JavaScript has a complicated history.  The name itself seems to indicate a relationship to Java, when in fact, the two languages share little in common except for a common syntax relationship by way of C.  Add to this the myriad of browser incompatibilities and numerous examples of bad usage, and you have what [...]]]></description>
			<content:encoded><![CDATA[<p>JavaScript has a complicated history.  The <a href="http://en.wikipedia.org/wiki/Javascript#History_and_naming">name itself</a> seems to indicate a relationship to Java, when in fact, the two languages share little in common except for a common syntax relationship by way of C.  Add to this the myriad of browser incompatibilities and numerous examples of bad usage, and you have what is perhaps the world&#8217;s least understood popular programming language.  (I had to add the &#8216;popular&#8217; qualifier, since I am sure there are some esoteric languages out there that only a handful of people know)</p>
<p>This is why inheritance in JavaScript is probably one of the least understood concepts.  While languages like Java have well-defined constructs for inheritance, the topic is of less importance with JavaScript.  In many situations, you&#8217;ll never have to deal with these aspects when programming in JavaScript, simply because it isn&#8217;t required for a lot of client side scripts.  However, for larger-scale web applications, applying object-oriented principles to your code may make it easier to design, improve and maintain.</p>
<p>There have been <a href="http://javascript.crockford.com/inheritance.html">many</a> <a href="http://javascript.crockford.com/prototypal.html">articles</a> <a href="http://20bits.com/2007/03/08/the-philosophy-of-javascript/">written</a> about inheritance in JavaScript and how it can and should be done.  You really don&#8217;t need to read mine to gain an understanding.  Rather, I&#8217;m just going to write about what I&#8217;ve learned, the process I went through and the experience I&#8217;ve gained along the way. </p>
<h3>It&#8217;s all new(s) to me</h3>
<p>If you come from a Java background, you&#8217;ll be no stranger to the <code>new</code> keyword.  Using it allows you to instantiate a new instance of an object from its class by calling its constructor.  The keyword also makes a lot of sense, since you&#8217;re creating a &#8216;new&#8217; object.</p>
<p>JavaScript also has a <code>new</code> keyword, but it doesn&#8217;t do quite the same thing as its Java counterpart, though at first the effects might seem similar.  This is one of the main reasons why JavaScript inheritance tends to be poorly understood.  </p>
<p>Consider the following example.</p>
<pre><code>function Foo(name)
{
  this.name = name;
}

var fooObject = new Foo('I am foo');</code></pre>
<p>If you&#8217;re familiar with Java or JavaScript, this example is fairly straightforward.  In the prototype-based JavaScript, <a href="http://en.wikipedia.org/wiki/Javascript#Prototype-based_features">functions can serve as object constructors</a> in somewhat the same manner as a constructor in Java.  However, <code>Foo</code> in the above example is not a class, since classes do not exist in JavaScript.  So, if <code>Foo</code> is not a class, what exactly happens when the statement <code>var fooObject = new Foo('I am foo')</code> is executed?</p>
<h3>Taking a step back</h3>
<p>Before we dive into the details, I&#8217;ll explain the concepts of a prototype-based language as it applies to JavaScript.  I mentioned above that JavaScript does not use classes like Java does.  This basically means that new objects are not created from instantiation of classes, but rather inherit from existing objects.  Thus, there is no &#8220;class hierarchy&#8221; but rather just an object hierarchy.  </p>
<p>In JavaScript, all objects are descended from the built-in <a href="http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Object"><code>Object</code></a> type.  This is similar to how all Java classes implicitly have the Object class as a superclass.  In JavaScript, instead of extending classes, you can inherit by manipulating the <code>prototype</code> property on a type; that is, the <code>prototype</code> property on the function you are using to create an object.  Let&#8217;s see some code to straighten things out.</p>
<pre><code>function Foo(name)
{
  this.name = name;
}
<strong>Foo.prototype.getName = function()
{
  alert(this.name);
}</strong>

var fooObject = new Foo('I am foo');
<strong>fooObject.getName(); // Will alert with 'I am foo'</strong></code></pre>
<p>This example is identical to the first one, except for the lines that are emphasized.  Here, I&#8217;ve set the <code>getName</code> property on the <code>prototype</code> property of <code>Foo</code> equal to a reference to a Function object.  This is effectively the same as defining a method for a class, since any object created from that type can call the method <code>getName()</code> on itself to return the proper value.  But what exactly is happening, and what&#8217;s the deal with the <code>prototype</code> property?</p>
<h3>More new(s)</h3>
<p>In JavaScript, the <code>new</code> keyword actually accomplishes a few things.  When you execute an expression such as <code>var fooObject = new Foo('I am foo')</code>, here&#8217;s exactly what happens.</p>
<ol>
<li>
First, a new generic object is created.  This object is the same as if you created the object using the statement <code>new Object()</code>, using JavaScript&#8217;s <a href="http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Object">built in Object type</a>.
</li>
<li>
The constructor function, that is, the function <code>Foo()</code>, is then called with the <code>this</code> keyword set to reference the newly-created object.  The parameters supplied are also passed to the constructor function, in this case, the string &#8220;I am foo&#8221;.  If you&#8217;re familiar with <a href="/blog/2007/12/18/using-the-call-and-apply-methods-to-change-the-context-of-a-function-in-javascript/">context</a>, this is equivalent to:</p>
<pre><code>var fooObject = new Object();
Foo.call(fooObject, 'I am foo');</code></pre>
<p>Thus, the code in <code>Foo()</code> sets a property called <code>name</code> equal to the supplied string.  Up to this point, things are the same as if you had created a new object and then manually set the <code>name</code> property yourself.  The next step is where things change.
</li>
<li>
The last step is where inheritance takes effect.  The constructor function, in addition to executing the specified code above, also sets an internal property called <code>__proto__</code> equal to the value of <code>Foo.prototype</code>.  This is how the new object inherits from the old one.</p>
<p>When you call a property on <code>fooObject</code> now, JavaScript will first check to see if the object has a local value for it.  In this case, the only local property is <code>name</code>. (Besides the internal and implicitly set <code>__proto__</code> property.  However, if it does not exist locally, it will check to see if the property exists under the object referenced by the <code>__proto__</code> property.  In this case, the <code>getName()</code> method exists under here.
</li>
</ol>
<p>Where things get confusing is because of how the <code>new</code> keyword is used.  Perhaps the designers of JavaScript wanted to use a keyword familiar to Java programmers so as to ease the transition to a new language that sounded so similar.  While it accomplishes a similar goal and for the most part you can consider the action to be almost the same, the use of the <code>new</code> keyword conceals the true meaning of prototype-based inheritance in JavaScript.  This ends up causing more confusion when you start digging into code.</p>
<h3>We&#8217;re all the same</h3>
<p>Suppose you created multiple objects from the <code>Foo()</code> constructor, called <code>fooObject1</code>, <code>fooObject2</code> and <code>fooObject3</code>,   In one fell swoop, you could add a new method to all of these objects without having to recreate them.  This is because of the <code>prototype</code> property.  Because each object contains a reference to <code>Foo.prototype</code>, adding a new method here will allow all objects access to it.  For example:</p>
<pre><code>Foo.prototype.yellName = function()
{
  alert(this.name.toUpperCase());
}
var fooObject3 = new Foo('I am Foo 3!');
fooObject3.yellName(); // alerts 'I AM FOO 3!'</code></pre>
<p>This adds another method to all <code>Foo</code>-constructed objects allowing them to &#8220;yell&#8221; their names.</p>
<h3>Extending Types</h3>
<p>I mentioned inheritance above but with just one type definition, the principles weren&#8217;t too clear.  Suppose we decided to extend our <code>Foo</code> &#8220;class&#8221; - how exactly would this work?  First, you need to define the child type and then set its <code>prototype</code> value to a new object of the parent type.  An example:</p>
<pre><code>function FooChild(childName)
{
  Foo.call(this, 'I am a child of Foo and my name is ' + childName);
}
FooChild.prototype = new Foo('');

var fooChildObject = new FooChild('Barbar');
fooChildObject.getName(); // Will alert with 'I am a child of Foo and my name is Barbar'</code></pre>
<p>Let&#8217;s break down what&#8217;s going on here.</p>
<ol>
<li>
First, we define a new constructor called <code>FooChild</code>.  In it, we <code>call</code> the parent constructor function with the context set to the current object.  This allows the <code>name</code> property to be set on the object during creation since that&#8217;s what the parent does.
</li>
<li>
Then, we set the <code>prototype</code> property equal to a new object that&#8217;s an instance of <code>Foo</code>.  This is what allows all of the child objects to have access to the parent&#8217;s properties, such as the <code>getName()</code> method.
</li>
</ol>
<h3>A few more details</h3>
<p>JavaScript provides two special operators for dealing with types and objects.  One is called <code>instanceof</code> and the other is <code>typeof</code>.  The latter, <code>typeof</code>, is less useful since it only deals with built-in JavaScript types.</p>
<p>The <code>typeof</code> operator returns the current variable&#8217;s type, but is limited to predefined types.  For example, <code>typeof fooChildObject</code> or <code>typeof fooObject</code> both return a string with the contents of &#8220;object&#8221;.  Thus, differentiating between the two is impossible.  More information can be found <a href="http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Operators:Special_Operators:typeof_Operator">at the Mozilla Developer Center</a>.</p>
<p>The <code>instanceof</code> operator is more interesting.  It takes two arguments and tests whether the first is an instance of the second.  (I guess I didn&#8217;t need to explain that) For example:</p>
<pre><code>function Foo(name)
{
  this.name = name;
}
Foo.prototype.getName = function()
{
  alert(this.name);
}

function FooChild(childName)
{
  Foo.call(this, 'I am a child of Foo and my name is ' + childName);
}
FooChild.prototype = new Foo('');

var fooObject = new Foo('I am foo');
var fooChildObject = new FooChild('Barbar');

alert(fooChildObject instanceof Foo); // true
alert(fooObject instanceof Foo); // true
alert(fooChildObject instanceof FooChild); // true
alert(fooObject instanceof FooChild); // false;</code></pre>
<p>In the above code, it is clear that <code>fooChildObject</code> is an instance of <code>FooChild</code>, and <code>fooObject</code>is an instance of <code>Foo</code>.  However, <code>fooChildObject</code> <strong>is also</strong> an instance of <code>Foo</code>, since its type was inherited from it through the <code>prototype</code> property.  However, <code>fooObject</code> <strong>is not</strong> an instance of <code>FooChild</code> since that type is a child of <code>Foo</code>.</p>
<p>I hope I haven&#8217;t said &#8220;foo&#8221; one too many times for you.</p>
<p>More information about <a href="http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Guide:Property_Inheritance_Revisited:Determining_Instance_Relationships"><code>instanceof</code> is again available</a> from the excellent Mozilla Developer Center.</p>
<h3>Concluding remarks</h3>
<p>I hope this has helped you to understand the nature of JavaScript&#8217;s built-in inheritance features.  I know I found it very convoluted at first, coming from a class-inheritance background.  I read everything I could find on the subject, and I believe it&#8217;s made me a better JavaScript programmer by understanding some of the &#8220;inner workings&#8221; of the language.  I encourage you to check out some of the references I&#8217;ve provided below.</p>
<h3>References</h3>
<ol class="note less">
<li><a href="http://javascript.crockford.com/prototypal.html">Prototypal Inheritance in JavaScript</a> - Douglas Crockford</li>
<li><a href="http://20bits.com/2007/03/08/the-philosophy-of-javascript/">The Philosophy of JavaScript</a> - Jesse of 20bits</li>
<li><a href="http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Guide:Property_Inheritance_Revisited">Prototype Inheritance Revisited</a> - Mozilla Developer Center</li>
<li><a href="http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Guide:The_Employee_Example">The Employee Example</a> - Mozilla Developer Center</li>
</ol>
<hr/>Copyright &copy; 2009 <strong><a href="http://unitstep.net">unitstep.net</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please contact <strong><a href="mailto:webmaster@unitstep.net">webmaster@unitstep.net</a></strong> for more information.<br/><span style="float: right;font-size: 7pt"><a href="http://blog.taragana.com/index.php/archive/wordpress-plugins-provided-by-taraganacom/">Plugin</a> by <a href="http://www.taragana.com/">Taragana</a></span>]]></content:encoded>
			<wfw:commentRss>http://unitstep.net/blog/2008/01/24/javascript-and-inheritance/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Using Assembla&#8217;s Trac with Eclipse Mylyn XML-RPC access</title>
		<link>http://unitstep.net/blog/2008/01/19/using-assemblas-trac-with-eclipse-mylyn-xml-rpc-access/</link>
		<comments>http://unitstep.net/blog/2008/01/19/using-assemblas-trac-with-eclipse-mylyn-xml-rpc-access/#comments</comments>
		<pubDate>Sun, 20 Jan 2008 02:16:42 +0000</pubDate>
		<dc:creator>Peter Chng</dc:creator>
		
		<category><![CDATA[assembla]]></category>

		<category><![CDATA[eclipse]]></category>

		<category><![CDATA[guides]]></category>

		<category><![CDATA[mylyn]]></category>

		<category><![CDATA[programming]]></category>

		<category><![CDATA[trac]]></category>

		<guid isPermaLink="false">http://unitstep.net/blog/2008/01/19/using-assemblas-trac-with-eclipse-mylyn-xml-rpc-access/</guid>
		<description><![CDATA[I recently found out about Assembla, an awesome service for managing software development projects.  It provides free SVN hosting (like other sites such as SourceForge and Google Code) but also provides tools like Trac, a Wiki, Scrum reporting, public or private access and up to 500 MB of disk space. (Additional features/space are available [...]]]></description>
			<content:encoded><![CDATA[<p>I recently found out about <a href="http://www.assembla.com/">Assembla</a>, an awesome service for managing software development projects.  It provides free SVN hosting (like other sites such as <a href="http://sourceforge.net/">SourceForge</a> and <a href="http://code.google.com/">Google Code</a>) but also provides tools like <a href="http://trac.edgewall.org">Trac</a>, a Wiki, Scrum reporting, public or private access and up to 500 MB of disk space. (Additional features/space are available for a cost)  For many, setting up services like Trac can be <a href="http://natmaster.com/articles/installing_trac.php">notoriously difficult</a>, so with <em>free</em> services like this, it&#8217;s hard to find any nits to pick.  </p>
<p>I won&#8217;t go into too much detail about the <a href="http://www.assembla.com/tour">features</a> since I wanted to talk about integrating the Eclipse plugin Mylyn with a Trac setup on Assembla.  There can be some issues getting things to work so I&#8217;ve outlined what I did to get everything running nicely.</p>
<h3>Background: Mylyn</h3>
<p><a href="http://www.eclipse.org/mylyn/">Mylyn</a> is an excellent task-management plugin for the ultimate IDE, Eclipse.  I have been trying it out for a variety of things, since I was trying to find something better than just text files for managing various tasks lists.  However, Mylyn does much <a href="http://www.ibm.com/developerworks/java/library/j-mylyn1/?ca=dgr-eclipse-1">more than just task management</a> as it helps to streamline your work environment with &#8220;context&#8221;.  I haven&#8217;t started using these advanced features though, but what really caught my eye was the integration Mylyn offers with various issue-tracking services such as Bugzilla and the aforementioned Trac.  This is accomplished by various &#8220;connectors&#8221;, with each connector being specific to one of the issue-tracking systems. </p>
<h3>The Problem: <a href="http://www.w3.org/XML/" class="ubernym uttInitialism"><acronym class="uttInitialism" title="eXtensible Markup Language">XML</acronym></a>-RPC Integration</h3>
<p>Integration of Mylyn with Trac allows you to view, create and edit tickets in a Trac repository from within Eclipse.  To accomplish this, there are two levels of integration, the first being simple web-based access.  This is the more primitive of the two and has been around for longer.  Basically, items are still edited from a web browser; the only difference is the web browser is spawned within Eclipse.  This isn&#8217;t really ideal and doesn&#8217;t offer a real integration.</p>
<p>The second uses an <a href="http://www.w3.org/XML/" class="ubernym uttInitialism"><acronym class="uttInitialism" title="eXtensible Markup Language">XML</acronym></a>-RPC interface to send/receive data and thus offers proper integration with the Eclipse environment.  However, when trying to connect to my Trac setup on Assembla with this choice, I ran into a lot of intermittent 404 (not found) errors.  Basically, synchronization was very flaky and by no means usable.  </p>
<h3>The Fix</h3>
<p>I did some searching and found <a href="http://www.assembla.com/flows/show_comment/cm_YtanJqr3lL8abIlDkbG?parent_id=cm_YtanJqr3lL8abIlDkbG&#038;space_id=c8A2BGQEWr2RUvaaeP0Qfc">this page</a> on the Assembla site where other users had experienced the same problem.  Scrolling through the comments brought me to <a href="http://vitaliel.blogspot.com/2007/08/mylyn-with-assembla-trac-hosting.html">this nice fellow&#8217;s explanation</a> of the problem, where a screencast was provided showing how it had been fixed.</p>
<p>Basically, these are the steps I did to get Mylyn <a href="http://www.w3.org/XML/" class="ubernym uttInitialism"><acronym class="uttInitialism" title="eXtensible Markup Language">XML</acronym></a>-RPC integration with Trac working.</p>
<ol>
<li>
<h4>Enable the <a href="http://www.w3.org/XML/" class="ubernym uttInitialism"><acronym class="uttInitialism" title="eXtensible Markup Language">XML</acronym></a>-RPC plugin</h4>
<p>Go to your Trac site, then click on Admin.  On the left sidebar go to <strong>General > Plugins</strong>.  There should be a section called <strong>TracXMLRPC</strong>; click to expand it.  You might as well enable RPC access for all of the options provided, though I&#8217;m not sure if this is necessary.  Here&#8217;s a screenshot.</p>
<p class="image">
<a rel="lightbox" href='http://unitstep.net/wordpress/wp-content/uploads/2008/01/assembla-mylyn-trac-01.png' title='Enable the XML-RPC plugin'><img src='http://unitstep.net/wordpress/wp-content/uploads/2008/01/assembla-mylyn-trac-01.png' alt='Enable the XML-RPC plugin' /></a></p>
</li>
<li>
<h4>Enable <a href="http://www.w3.org/XML/" class="ubernym uttInitialism"><acronym class="uttInitialism" title="eXtensible Markup Language">XML</acronym></a>-RPC permissions</h4>
<p>After that, you need to enable permissions for <a href="http://www.w3.org/XML/" class="ubernym uttInitialism"><acronym class="uttInitialism" title="eXtensible Markup Language">XML</acronym></a>-RPC access.  Go to <strong>General > Permissions</strong> on the sidebar.  In the &#8220;<strong>Grant Permissions</strong>&#8221; area, add a permission for &#8220;<strong>XML_RPC</strong>&#8221; for &#8220;<strong>@editors</strong>&#8220;.  Using &#8220;@managers&#8221; for the subject might also work/be needed if you&#8217;ve setup access for those users.  This is the basically what it should be:</p>
<p class="image">
<a rel="lightbox" href='http://unitstep.net/wordpress/wp-content/uploads/2008/01/assembla-mylyn-trac-02.png' title='Enable XML-RPC permissions'><img src='http://unitstep.net/wordpress/wp-content/uploads/2008/01/assembla-mylyn-trac-02.png' alt='Enable XML-RPC permissions' /></a></p>
</li>
<li>
<h4>Ensure there is at least one ticket in the system</h4>
<p>For some reason, I had weird errors when trying to synchronize/connect to a Trac repository with no tickets.  This was corroborated by <a href="http://vitaliel.blogspot.com/2007/08/mylyn-with-assembla-trac-hosting.html">the fellow who originally found the solution</a> to this problem.  It&#8217;s a minor issue though, just click &#8220;New Ticket&#8221; and create a placeholder.
</li>
<li>
<h4>Add Trac to Mylyn</h4>
<p>This step&#8217;s simply enough; though some suggestions recommended using <code>http://&lt;domain_name_to_assembla_trac&gt;/&lt;space_url_name&gt;/login/xmlrpc</code> as the <acronym class="uttInitialism" title="Uniform Resource Locator">URL</acronym>, I simply used <strong><code>http://&lt;domain_name_to_assembla_trac&gt;/&lt;space_url_name&gt;</code></strong> and it worked fine.  Remember to use <a href="http://www.w3.org/XML/" class="ubernym uttInitialism"><acronym class="uttInitialism" title="eXtensible Markup Language">XML</acronym></a>-RPC as your access type or you won&#8217;t get proper integration.</p>
<p class="image">
<a rel="lightbox" href='http://unitstep.net/wordpress/wp-content/uploads/2008/01/assembla-mylyn-trac-03.png' title='Setting up Mylyn to work with Trac'><img src='http://unitstep.net/wordpress/wp-content/uploads/2008/01/assembla-mylyn-trac-03.png' alt='Setting up Mylyn to work with Trac' /></a>
</p>
</li>
</ol>
<p>After that, you should be able to properly connect to your Trac repository using the <a href="http://www.w3.org/XML/" class="ubernym uttInitialism"><acronym class="uttInitialism" title="eXtensible Markup Language">XML</acronym></a>-RPC option of Mylyn.  Then, you can finally enjoy proper Trac integration in Eclipse!</p>
<hr/>Copyright &copy; 2009 <strong><a href="http://unitstep.net">unitstep.net</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please contact <strong><a href="mailto:webmaster@unitstep.net">webmaster@unitstep.net</a></strong> for more information.<br/><span style="float: right;font-size: 7pt"><a href="http://blog.taragana.com/index.php/archive/wordpress-plugins-provided-by-taraganacom/">Plugin</a> by <a href="http://www.taragana.com/">Taragana</a></span>]]></content:encoded>
			<wfw:commentRss>http://unitstep.net/blog/2008/01/19/using-assemblas-trac-with-eclipse-mylyn-xml-rpc-access/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Using the &#8220;call&#8221; and &#8220;apply&#8221; methods to change the context of a function in JavaScript</title>
		<link>http://unitstep.net/blog/2007/12/18/using-the-call-and-apply-methods-to-change-the-context-of-a-function-in-javascript/</link>
		<comments>http://unitstep.net/blog/2007/12/18/using-the-call-and-apply-methods-to-change-the-context-of-a-function-in-javascript/#comments</comments>
		<pubDate>Wed, 19 Dec 2007 01:54:04 +0000</pubDate>
		<dc:creator>Peter Chng</dc:creator>
		
		<category><![CDATA[JavaScript]]></category>

		<category><![CDATA[guides]]></category>

		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://unitstep.net/blog/2007/12/18/using-the-call-and-apply-methods-to-change-the-context-of-a-function-in-javascript/</guid>
		<description><![CDATA[In JavaScript, the context that function is executing in is very important.  What is context?  Basically, the context of a function is what object it is &#8220;attached&#8221; to - this object will be the reference of the &#8220;this&#8221; keyword within that function.  Every function has a context -that is to say, every [...]]]></description>
			<content:encoded><![CDATA[<p>In JavaScript, the context that function is executing in is very important.  What is context?  Basically, the context of a function is what object it is &#8220;attached&#8221; to - this object will be the reference of the &#8220;<code>this</code>&#8221; keyword within that function.  Every function has a context -that is to say, every function is attached to an object.  By default it is the <code>window</code> object.</p>
<p>You may have run into this particular aspect of JavaScript when working with event handlers.  For example:</p>
<pre><code>function alertId()
{
  alert (this.id);
}

document.getElementById('someId').onclick = alertId;</code></pre>
<p>This will return the &#8220;id&#8221; attribute of the element that the function has been attached to.  You could attach the same function to multiple objects and each time you called it on a different object, it would return a different value, since the context is different.  (Minor note: using <code>element.attachEvent()</code>, as part of the Microsoft event handler model, <a href="http://www.quirksmode.org/js/events_advanced.html">does not change the context</a> of the function so &#8220;<code>this</code>&#8221; will still refer to the <code>window</code> object)</p>
<p>However, there may be times when you want to change the meaning of <code>this</code> without actually having to attach that a function to an object.  Using the <code>call()</code> and <code>apply()</code> methods of the Function object can allow you to do this.</p>
<h3>Context is everything</h3>
<p>Let&#8217;s backtrack for a moment.  In JavaScript, many (but not all) variables are objects.  This includes the references to all functions as well - they are also objects.  In the example above, using &#8220;<code>alertId</code>&#8221; (<em>without</em> the parentheses) would refer to the <code>Function</code> object that represents <code>alertId</code>.  As the <code>Function</code> object is a predefined object in JavaScript, it has <a href="http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Function">methods and properties associated</a> with it.</p>
<p>Two of these methods are <code>call()</code> and <code>apply()</code>.  Using these methods on a Function object allows you to set the context of that function - that is, what the &#8220;<code>this</code>&#8221; keyword refers to.  The two only in how arguments are passed to the function whose context is being redefined.  For example <code>apply()</code> takes an array of arguments like this:</p>
<pre><code>function someFunction(arg1, arg2)
{
  this.id = arg1 + arg2;
}

var arrayOfArguments = ['valueOfArg1', 'valueOfArg2'];

someFunction.apply(objectToBeUsedAsThis, arrayOfArguments);</code></pre>
<p>The values in the second-argument array are then used as the arguments to the <code>someFunction()</code> function.  </p>
<p>The <code>call()</code> method is almost the same except it does not take an array of arguments, but rather just an indeterminate number of arguments that are all passed to the function.  For example, the above could also be accomplished with this code:</p>
<pre><code>function someFunction(arg1, arg2)
{
  this.id = arg1 + arg2;
}

someFunction.call(objectToBeUsedAsThis, 'valueOfArg1', 'valueOfArg2');</code></pre>
<p>I prefer to use <code>apply()</code> sometimes since you can directly use the <a href="http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Objects:Function:arguments"><code>arguments</code></a> variable that is local within all functions. (The variable <code>arguments</code> stores all the arguments that were passed to the function when it was called, and so this can be used in a situation with where it is desired to have a function with a variable number of arguments.)</p>
<h3>A useful example</h3>
<p>So far, the examples posed have been fairly trivial.  Let&#8217;s look at a real-world use of <code>call()</code> to illustrate its usefulness.  Remember the <a href="http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Objects:Function:arguments"><code>arguments</code></a> variable?  Basically, you have access to this object variable whenever you&#8217;re inside a function since it stores all the arguments passed to this function.  However, it&#8217;s not exactly an array (although it works like one sometimes) and thus it <em>does not</em> have access to <code>Array</code> methods such as <a href="http://www.devguru.com/Technologies/ecmaScript/quickref/join.html"><code>join()</code></a>.  </p>
<p>We could easily convert it into an array by accessing each property by its index using a loop, but there&#8217;s an easier to way to do this.  Consider the following code:</p>
<pre><code>function someFunction()
{
  var argsArray = Array.prototype.slice.call(arguments, 0);
}</code></pre>
<p>Using this one line, we have successfully converted the <code>arguments</code> into a true Array object and stored the result in the <code>argsArray</code> variable.  How?  First, we access the <a href="http://www.devguru.com/Technologies/ecmaScript/quickref/slice.html"><code>slice()</code></a> method on the <code>Array</code> object through the <code>prototype</code> property and then <code>call()</code> the method telling it to use the <code>arguments</code> object as <code>this</code>.</p>
<p>The <code>slice()</code> method allows us to extract a section of an existing array.  However, by using <code>call()</code> we are able to apply its effects on the <code>arguments</code> object that is similar to, but not exactly an <code>Array</code> object.  The second argument of &#8216;0&#8242; merely indicates that we want to extract not just a part of <code>arguments</code> but all of it.  Since <code>slice()</code> always returns an <code>Array</code> object, we thus get back a true array containing the same data as the <code>arguments</code> object.  And that&#8217;s it!</p>
<p>Note that the above example could be compacted even further.  However, it looks very cryptic and can be confusing. (As if the previous example wasn&#8217;t confusing enough!) </p>
<pre><code>function someFunction()
{
  var argsArray = [].slice.call(arguments);
}</code></pre>
<p>This example works the same as the previous one.  Instead of using <code>Array.prototype</code>, we create a &#8216;dummy&#8217; empty array to get access to the <code>slice()</code> method.  The second argument of &#8216;0&#8242; isn&#8217;t needed, as if it is left out when using <code>slice()</code> the entire contents will be returned.</p>
<h3>Contextual Conclusion</h3>
<p>In short, using these methods to change the scope of a function can allow you to do some neat things with JavaScript that aren&#8217;t possible in some other languages.  However, one should always be mindful to keep code readable and maintainable and to lessen the learning curve for those new to a language. </p>
<hr/>Copyright &copy; 2009 <strong><a href="http://unitstep.net">unitstep.net</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please contact <strong><a href="mailto:webmaster@unitstep.net">webmaster@unitstep.net</a></strong> for more information.<br/><span style="float: right;font-size: 7pt"><a href="http://blog.taragana.com/index.php/archive/wordpress-plugins-provided-by-taraganacom/">Plugin</a> by <a href="http://www.taragana.com/">Taragana</a></span>]]></content:encoded>
			<wfw:commentRss>http://unitstep.net/blog/2007/12/18/using-the-call-and-apply-methods-to-change-the-context-of-a-function-in-javascript/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Exception handling in JavaScript</title>
		<link>http://unitstep.net/blog/2007/11/25/exception-handling-in-javascript/</link>
		<comments>http://unitstep.net/blog/2007/11/25/exception-handling-in-javascript/#comments</comments>
		<pubDate>Mon, 26 Nov 2007 01:54:00 +0000</pubDate>
		<dc:creator>Peter Chng</dc:creator>
		
		<category><![CDATA[JavaScript]]></category>

		<category><![CDATA[exceptions]]></category>

		<category><![CDATA[guides]]></category>

		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://unitstep.net/blog/2007/11/25/exception-handling-in-javascript/</guid>
		<description><![CDATA[Exception handling is a topic that may not be well-understood by some web developers, depending on what languages they have the most experience in.  In particular, PHP, one of the most common server-side languages for web development, did not have support for exception handling until version 5.  In the four years between the [...]]]></description>
			<content:encoded><![CDATA[<p>Exception handling is a topic that may not be well-understood by some web developers, depending on what languages they have the most experience in.  In particular, <acronym class="uttInitialism" title="PHP: Hypertext Preprocessor">PHP</acronym>, one of the most common server-side languages for web development, did not have support for exception handling until <a href="http://www.php.net/exceptions">version 5</a>.  In the four years between the release of PHP4 and PHP5, the language became increasingly popular among developers, and as a result, a lot of code was written without exception handling in mind.  The situation did not even improve much with the release of PHP5, since PHP5 was meant to be backwards-compatible with code developed for PHP4.  Three years later, there are still <a href="http://www.gophp5.org/">movements</a> to get developers to transition to a purely-PHP5 model.</p>
<p>Some of this may have transferred over to JavaScript, a language that is already poorly understood and often implemented even worse.  It is often hard to find well-written, maintainable JavaScript code, as it is often left as an afterthought in a project or otherwise not given much consideration, having been delegated to the realm of popup scripts and mouse-overs.  While exception handling may be overkill for a lot of JavaScript applications, many do not even know of JavaScript&#8217;s exception-handling capabilities.  In this article, I&#8217;ll give a brief overview of exception handling and some recommendations on how to use it in JavaScript to improve the readability of code. </p>
<h2>Exceptional conditions</h2>
<p>I won&#8217;t go too in-depth about the <a href="http://java.sun.com/docs/books/tutorial/essential/exceptions/advantages.html">merits of using exception handling</a> but will instead just give a brief overview.  (While there are some drawbacks, these apply more to the Java language rather than JavaScript)</p>
<p>The main reason for using exceptions is to have a separate channel for communicating errors.  Without this, you must communicate error conditions using the function itself. Consider a function that performs mathematical division:</p>
<pre><code>function divide(dividend, divisor)
{
  var quotient = dividend/divisor;
  return quotient;
}</code></pre>
<p>Division is a fairly simple arithmetic operation, but of the four basic operations it is the only one that has limits on its arguments: the divisor (the term you divide by) cannot be zero, since <a href="http://en.wikipedia.org/wiki/Division_%28mathematics%29">division by zero is undefined.</a>  So, how should you handle cases where the supplied arguments result in division by zero?  (The situation is very likely in an application accepting user input)</p>
<p>Without using exceptions, you have a few options, each of which has its own weaknesses.  Firstly, you could choose not to return <em>anything</em> and just <code>alert()</code> the user of the error.  This isn&#8217;t good since when you call the <code>divide()</code> function, you expect a result, not a warning message.</p>
<p>Secondly, you could choose to return a special &#8220;error code&#8221; indicating that there was a division by zero.  But this creates another problem - what exactly <em>do</em> you return when something goes wrong?  In this case, the only error case is division by zero - since JavaScript is a weakly-typed language, you could just return <code>false</code> on this error, but then in the calling code you&#8217;d have to check if <code>divide()</code> equaled <code>false</code> before using it, probably using the <a href="http://www.webreference.com/js/column26/stricteq.html">strict equality operator</a>.  As you can see, things get messy fast. </p>
<p>Alternatively, you could just check the inputs/arguments every time before you called the function.  However this is clumsy, and adds another layer of complexity where something could go wrong.  </p>
<h2>Another way of doing things</h2>
<p>As mentioned before, exception handling adds a side channel of sorts strictly for communicating errors.  By doing this, it allows for the interruption of program flow for the purpose of dealing with the exception or error situation.  Using exceptions, you would re-write the function above like this:</p>
<pre><code>function divide(dividend, divisor)
{
  if (0 == divisor) {
    throw new Error("Bzlorg! Cannot divide by zero.");
  }

  var quotient = dividend/divisor;
  return quotient;
}</code></pre>
<p>Here we are checking if the divisor equals zero - signifying an invalid input value - and then throwing an exception if this is the case.  How is this different than returning an error code?</p>
<p>The main difference is in the <em>control flow</em> of the program; using exceptions causes a change in the program flow.  In the above example, if the divisor equals zero, the execution of the function stops there and returns to the calling code with the throw exception.  The subsequent statements calculating the quotient and returning will not be executed.  Here&#8217;s an example of how you&#8217;d call the <code>divide</code> function.</p>
<pre><code>try {
  var dividend = 3;
  var divisor = 0;

  var quotient = divide(dividend, divisor);

  alert("The answer is " + quotient);
}
catch (e) {
  alert(e.message);
}</code></pre>
<p>With exceptions, you enclose code that could throw an exception with a <code>try</code> block.  This signifies to the interpreter (in the case of JavaScript) that you will be executing code (in this case, calling a function) that <em>could</em> throw an exception as a result of some error condition.  Thus you are <code>try</code>ing to do something - but as in real life, things may go wrong.</p>
<p>In this example, everything works until the line calling <code>divide</code>.  Since <code>divide</code> throws an exception with the input values supplied, flow will be directed to the <code>catch</code> block.  All <code>try</code> blocks must be followed with a <code>catch</code> block, with the variable in the parentheses specifying the variable to hold the thrown exception object.  In the code above, we merely alert the user to the problem - the message &#8220;Bzlorg! Cannot divide by zero&#8221; is displayed - in a real program you most likely would want to do handle the error differently depending on the context - but that&#8217;s a whole different topic.</p>
<p>If, however, you executed the code with valid values and no exceptions were thrown, once the program had got to the end of the <code>try</code> block it would jump over the following <code>catch</code> block and the user would be alerted with the correct answer.  Code within a <code>catch</code> block is <em>only</em> executed in the event that an exception is thrown.</p>
<h3>Differences with Java</h3>
<p>Since Java is an extremely popular language and one that also uses a similar exception handling model, it would be prudent to discuss some of the differences and similarities with it and JavaScript.</p>
<ol>
<li>
<h4><del>No multiple catch blocks with JavaScript</del></h4>
<p><del>This is perhaps the biggest difference.  If you&#8217;re familiar with Java you&#8217;ll know that different exception objects can be thrown during execution (all subclasses of the root/parent <code>Exception</code> class defined by Java), each signifying different error conditions.  You catch each of them separately by using separate catch blocks, each specifying a particular class or parent class.  However, with JavaScript, as you might have noticed from the code above, there can only be one catch block and thus there&#8217;s no need to specify the exception class. </del></p>
<p><del>If, however, you want the granularity of working with different exception classes, you&#8217;ll have to use the <code>instanceof</code> operator within a catch block, like this:</del></p>
<pre><code>try {
  ...
}
catch (e) {
  if (e instanceof RangeError) {
    ...
  }
  else if (e instanceof TypeError) {
    ...
   }
}</code></pre>
<p><del>It&#8217;s not as elegant as having multiple catch blocks, but it&#8217;s one way to deal with multiple exception types.</del></p>
<h4>Correction:</h4>
<p>It appears I was mistaken.  In JavaScript, you can indeed have <a href="http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Guide:Exception_Handling_Statements:try...catch_Statement#The_catch_Block">multiple catch blocks</a>, as seen in the <a href="http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Guide">Core JavaScript 1.5 Guide</a> from the Mozilla Developer Center.  My initial example above is still valid syntactically, but this way may be more appealing.  An example is as follows:</p>
<pre><code>try {
  ...
}
catch (e if e instanceof RangeError) {
  ...
}
catch (e if e instanceof TypeError) {
  ...
}
catch (e) {
  // General catch-all block.
  ...
}</code></pre>
<p>It just goes to show that when you think you know something, you probably don&#8217;t!  This is part of why I like JavaScript (and by extension, programming); there&#8217;s always more to learn and experience to be gained.</p>
</li>
<li>
<h4>Exception types</h4>
<p>The discussion of exception types brings us to another point - the different exception types in JavaScript.  JavaScript defines some <a href="http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Error">built-in exception</a> types, all based off the parent <code>Error</code> object.  These should suffice for most situations where you&#8217;re checking user input (the most common use), but if you&#8217;re developing a complex application you may want to define your own.  </p>
<p>In that situation, things get a little tricky, especially if you&#8217;re coming from Java.  Despite the outward similarity, JavaScript does not uses classes like Java, but instead uses a <a href="http://en.wikipedia.org/wiki/Prototype-based_programming">prototype-based approach</a> where inheritance comes from existing objects.  In this respect, things can get complicated as there are debates on <a href="http://www.sitepoint.com/blogs/2006/01/17/javascript-inheritance/">what the best way to inherit from objects</a> is and to that degree, a few JavaScript libraries have been written to facilitate the extending of objects in JavaScript.  These points are beyond the scope of this article, but I thought I&#8217;d just point you in the right direction.</p>
<p>Interestingly, you can also <a href="http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Guide:Exception_Handling_Statements:throw_Statement">throw many different</a> types of expressions, and are not limited to the built-in exception types.  For example, <code>throw false;</code> and <code>throw "Hello World";</code> are valid statements, but in my opinion, it doesn&#8217;t make much sense to throw any type of expression just because you can.  Using the built-in exception types (or defining your own) is a better practice, though throwing just String expressions might be alright in some situations.
</li>
<li>
<h4>Runtime errors</h4>
<p>During execution, you code may trigger runtime errors within JavaScript - for example, when trying to reference a property on a non-existent object.  These will also result in a new <code>Error</code> object being thrown, even though you did not define this throw in your code.  If this happens within a try block, the exception will subsequently be caught in the following catch block, and if you&#8217;re not expecting this error you may miss it.  (If, for example, you&#8217;re only looking for specific exception object types)</p>
<p>This can create problems with some of the JavaScript debuggers out there like <a href="http://www.getfirebug.com">Firebug</a>.  Since the runtime exception is being caught, Firebug will not be able to catch it (it is prevented from &#8220;filtering&#8221; up), so you may not be able to locate the source of your error if you&#8217;re relying on the debugger.  </p>
<p>My recommendation is thus to ensure your code runs properly under normal conditions.  Only then should you start using exceptions and try-catch statements.  This will ensure that no unexpected runtime exceptions get caught.  (The runtime errors are analogous to the unchecked runtime exceptions of Java in that they are not normally caught)
</li>
</ol>
<h3>Summing it up</h3>
<p>The whole point of using exceptions is not to make your code &#8220;work&#8221; better - anything that can be accomplished with exceptions can most likely be done without it, with just the same end result.  The point is to make your code more readable, manageable and flexible.  By using exceptions you get rid of having to use cumbersome &#8220;error codes&#8221;, the values of which you may forget later.  You also get more flexibility with how you handle errors.  You need not handle the error right in the function where it occurs - you can throw an exception to the calling code and handle the error there - or, alternatively, you could let the exception bubble up to a higher-level and handle all errors there.  It really depends on your needs, but using exceptions allows for this to be implemented more readily.</p>
<p>Though exceptions may seem like overkill for JavaScript and despite the limitations of its exception handling model as compared to that of Java&#8217;s, there are still some benefits to using exceptions, especially for complex JavaScript applications that you may implement to improve the interactivity of your site. </p>
<h4>Changes/Fixes</h4>
<ul>
<li><strong>2007-12-06</strong>: Changed <code>throw new Exception(...)</code> to correct statement of <code>throw new Error(...)</code>.</li>
<li><strong>2008-01-08</strong>: Fixed incorrect assertion of &#8220;No Multiple Catch Blocks&#8221; in JavaScript; added remarks about being able to throw any type of expression.</li>
</ul>
<hr/>Copyright &copy; 2009 <strong><a href="http://unitstep.net">unitstep.net</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please contact <strong><a href="mailto:webmaster@unitstep.net">webmaster@unitstep.net</a></strong> for more information.<br/><span style="float: right;font-size: 7pt"><a href="http://blog.taragana.com/index.php/archive/wordpress-plugins-provided-by-taraganacom/">Plugin</a> by <a href="http://www.taragana.com/">Taragana</a></span>]]></content:encoded>
			<wfw:commentRss>http://unitstep.net/blog/2007/11/25/exception-handling-in-javascript/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Using SpeedFan to automatically control your PC&#8217;s fan speeds</title>
		<link>http://unitstep.net/blog/2007/11/02/using-speedfan-to-automatically-control-your-pcs-fan-speeds/</link>
		<comments>http://unitstep.net/blog/2007/11/02/using-speedfan-to-automatically-control-your-pcs-fan-speeds/#comments</comments>
		<pubDate>Sat, 03 Nov 2007 01:25:26 +0000</pubDate>
		<dc:creator>Peter Chng</dc:creator>
		
		<category><![CDATA[Hardware]]></category>

		<category><![CDATA[guides]]></category>

		<category><![CDATA[speedfan]]></category>

		<guid isPermaLink="false">http://unitstep.net/blog/2007/11/02/using-speedfan-to-automatically-control-your-pcs-fan-speeds/</guid>
		<description><![CDATA[
SpeedFan is a great utility for enthusiasts who&#8217;ve built their own PC.  Besides being able to show the temperatures inside your system (from various sensors in the CPU, motherboard and HDDs) and other vitals such as voltages and fan speeds, it can also automate the cooling cycles of your machine.  As its namesake [...]]]></description>
			<content:encoded><![CDATA[<p class="image align-right"><a href='/blog/2007/11/02/using-speedfan-to-automatically-control-your-pcs-fan-speeds' title='SpeedFan Guide'><img src='/wordpress/wp-content/uploads/2007/11/speedfan-01.thumbnail.png' alt='SpeedFan Guide' /></a></p>
<p><a href="http://www.almico.com/speedfan.php">SpeedFan</a> is a great utility for enthusiasts who&#8217;ve built their own PC.  Besides being able to show the temperatures inside your system (from various sensors in the CPU, motherboard and HDDs) and other vitals such as voltages and fan speeds, it can also automate the cooling cycles of your machine.  As its namesake implies, SpeedFan is able to automatically control your computer&#8217;s fan speeds based on the temperatures reported by various hardware sensors.  This can allow you to find the right balance between a cool system and a noisy one.   However, it does require some configuration, as I&#8217;ll attempt to show you in the following article.</p>
<h3>It&#8217;s all in the details</h3>
<p>All the material I&#8217;m about to present here is available in the help file for SpeedFan, however, since most people use the Internet for everything, myself included, I thought I&#8217;d summarize the most important points.  SpeedFan has a lot of functionality and it&#8217;s easy to get lost in all of that when all you want is something simple like automatic fan control.  (Some motherboards already support this, but SpeedFan brings this functionality to almost any motherboard that&#8217;s reasonably new)</p>
<p>First and foremost, the fans that you want to control must be plugged into one of your motherboard&#8217;s 3-pin fan headers; they cannot be plugged into 4-pin molex connectors that come straight from your power supply.  This is because SpeedFan controls fan speeds&#8217; by varying the output (using PWM) of the 3-pin fan headers on your motherboard.  If you want to control the speed of your 4-pin fans, you&#8217;ll have to use some sort of fanbus or external fan controller.</p>
<h3>Getting started</h3>
<p>On the main SpeedFan window, you may have noticed a checkbox for &#8220;Automatic fan speed&#8221;.  However, checking it is not enough to properly set it up, though it would be nice if things were this easy!  For now, you can check it, but nothing will happen - you shouldn&#8217;t notice any change in your fans&#8217; speeds. </p>
<p class="image"><img src='/wordpress/wp-content/uploads/2007/11/speedfan-01.png' alt='Main SpeedFan window' /></p>
<p>Click on &#8220;Configure&#8221; to bring up the options window.  SpeedFan is a fairly powerful program, but that means configuration is required to make it do what you want.  The assumption that SpeedFan uses is that various <strong>temperatures</strong> can be influenced by the various <strong>fan speeds</strong> in your system.  You need to define these relationships.  For example, in my system &#8220;Temp1&#8243; is the CPU temperature. (I haven&#8217;t bothered to rename the labels)  In the screenshot below, I have linked it with &#8220;Speed01&#8243; and &#8220;Speed02&#8243;, which correspond to my CPU&#8217;s fan and a case exhaust fan.</p>
<p class="image"><img src='/wordpress/wp-content/uploads/2007/11/speedfan-02.png' alt='SpeedFan temperatures' /></p>
<p>This tells SpeedFan that it should vary these fan speeds based on the temperature they&#8217;re associated with.  You also need to configure threshold temperatures; there are two, &#8220;Desired&#8221; and &#8220;Warning&#8221;.  The desired temperature tells SpeedFan what it should aim for.  Once the desired temperature is reached, SpeedFan will begin to drop fan speeds down to some minimum you specify; if the temperature is above desired fan speeds will increase by an amount related to how much the temperature is above the desired.  Once the temperature reaches the warning value, fan speeds will be set to maximum. (100%)</p>
<p>We now need to configure each of these fans.  Go to the &#8220;Speeds&#8221; tab (not the &#8220;Fans&#8221; tab) of the configuration and you&#8217;ll see a window like this:</p>
<p class="image"><img src='/wordpress/wp-content/uploads/2007/11/speedfan-03.png' alt='SpeedFan speeds' /></p>
<p>Remember that Speed01 and Speed02 are linked with the Temp1.  Here is where we define the minimum and maximum fan speed values.  When the temperature is at or below desired, the <em>lowest</em> the Speed01 will go is 30%, while the maximum I&#8217;ve specified is 100%.  This range is for temperatures up to the warning value.  When the temperature is at or above warning, the fan speeds linked to it will be set to 100% <strong>regardless of what you&#8217;ve define the maximum to be</strong>.  This is a sort of fail safe to prevent overheating - better safe and noisy than silent and sorry.  Also important to note is that you must check &#8220;Automatically variated&#8221; <strong>for each fan</strong> you want to automatically control.  (This is separate from the main automatic fan speed checkbox on the main SpeedFan window we saw earlier)</p>
<p>You may need to experiment to find out what are the best values for minimum and maximum fan speeds.  Also, some fans fail to report their rotational speed (RPM) when spinning slower, so you may get a reading of &#8220;0 RPM&#8221; within SpeedFan.  You&#8217;ll need to actually check whether this is the case.</p>
<p>One last thing you may want to configure is how fast SpeedFan will begin to adjust fan speeds when it has to respond to a temperature change.  This is accomplished by setting the &#8220;Delta value&#8221; on the Options tab of configuration:</p>
<p class="image"><img src='/wordpress/wp-content/uploads/2007/11/speedfan-04.png' alt='Delta value for fan speeds' /></p>
<p>This sets the step-size (in percent) for fan speed changes.  With a larger value, SpeedFan will adjust fan speeds more quickly since it will be increasing or decreasing by that amount each time.  Experiment to find what works best.  I&#8217;ve found that with too large a step/delta size, temperatures and fan speeds will oscillate - basically the fans will speed up too fast, causing the temperatures to drop, which in turn cause the fans to slow down too much, which then causes temperature to rise again, completing the cycle.  If you&#8217;ve taken a course in <a href="http://en.wikipedia.org/wiki/Control_theory">control theory</a> you&#8217;ll realize that this is perhaps the classic example problem in control theory.  (By adjusting the delta value I believe you&#8217;re adjusting the proportional value of the controller - though I am not sure if SpeedFan implements a full PID controller)</p>
<p>Lastly, you may want to check &#8220;Set fans to 100% on exit&#8221; just in case you accidentally shut down SpeedFan - this is another protective feature.</p>
<h3>Finishing up</h3>
<p>Click &#8220;OK&#8221; on the configuration page to save your changes, which should bring you back to the main window.  Then, make sure &#8220;Automatic Fan Speed&#8221; is checked here, and your system should now be set up for automatic fan control!  I have been using SpeedFan for a few years and wasn&#8217;t aware of this functionality until recently.  Just goes to show that you can always learn new things!</p>
<hr/>Copyright &copy; 2009 <strong><a href="http://unitstep.net">unitstep.net</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please contact <strong><a href="mailto:webmaster@unitstep.net">webmaster@unitstep.net</a></strong> for more information.<br/><span style="float: right;font-size: 7pt"><a href="http://blog.taragana.com/index.php/archive/wordpress-plugins-provided-by-taraganacom/">Plugin</a> by <a href="http://www.taragana.com/">Taragana</a></span>]]></content:encoded>
			<wfw:commentRss>http://unitstep.net/blog/2007/11/02/using-speedfan-to-automatically-control-your-pcs-fan-speeds/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Using DD-WRT to turn the Linksys WRT-54G/WRT-54GL into a wireless bridge</title>
		<link>http://unitstep.net/blog/2007/10/21/using-dd-wrt-to-turn-the-linksys-wrt-54gwrt-54gl-into-a-wireless-bridge/</link>
		<comments>http://unitstep.net/blog/2007/10/21/using-dd-wrt-to-turn-the-linksys-wrt-54gwrt-54gl-into-a-wireless-bridge/#comments</comments>
		<pubDate>Mon, 22 Oct 2007 01:17:19 +0000</pubDate>
		<dc:creator>Peter Chng</dc:creator>
		
		<category><![CDATA[dd-wrt]]></category>

		<category><![CDATA[guides]]></category>

		<category><![CDATA[linksys]]></category>

		<category><![CDATA[wifi]]></category>

		<category><![CDATA[wireless bridge]]></category>

		<category><![CDATA[wrt54g]]></category>

		<guid isPermaLink="false">http://unitstep.net/blog/2007/10/21/using-dd-wrt-to-turn-the-linksys-wrt-54gwrt-54gl-into-a-wireless-bridge/</guid>
		<description><![CDATA[
I recently got a new Wireless-N router (based on the Draft 2.0 of the 802.11n spec.) to replace my old, but trusty WRT-54GL, an 802.11g router.  I bought this router just over a year ago to replace another 802.11g router that was acting up.  I specifically bought the WRT-54GL (as opposed to the [...]]]></description>
			<content:encoded><![CDATA[<p class="image align-right"><a href='/blog/2007/10/21/using-dd-wrt-to-turn-the-linksys-wrt-54gwrt-54gl-into-a-wireless-bridge/' title='DD-WRT firmware for Linksys WRT-54G/GL'><img src='/wordpress/wp-content/uploads/2007/10/ddwrt-wrt54gl.jpg' alt='DD-WRT firmware for Linksys WRT-54G/GL' /></a></p>
<p>I recently got a new Wireless-N router (based on the <a href="http://en.wikipedia.org/wiki/802.11n">Draft 2.0 of the 802.11n spec.</a>) to replace my old, but trusty WRT-54GL, an 802.11g router.  I bought this router just over a year ago to replace another 802.11g router that was acting up.  I specifically bought the WRT-54GL (as opposed to the regular WRT-54G) because I knew that I&#8217;d eventually want to flash it with third-party firmware.  (The WRT-54GL runs on Linux and has better hardware than later versions of the WRT-54G)</p>
<p>I recently got my Xbox (with <a href="http://www.xboxmediacenter.com/">XBMC</a>) setup in my living room.  This placed it far away from the wireless router in my apartment and not wanting to run an unsightly CAT-5 cable around my place, I decided that I&#8217;d need a wireless bridge since the original Xbox does not have a built-in wireless adapter. (Nor does the 360, I believe).  A quick look around the web showed that most dedicated wireless bridges were quite expensive and of dubious quality.  Since I already had the spare WRT-54GL, I decided to flash it with <a href="http://www.dd-wrt.com/">DD-WRT</a>, one of the most popular third-party firmware replacements, and see how it would function as a wireless bridge for my XBMC setup.</p>
<h3>Bridging the gap</h3>
<p>A wireless bridge (depending on your definition) is a device that allows regular wired clients access to the network over a wireless connection.  This was exactly what I needed for my XBMC-equipped Xbox.  This would give XBMC access to the network and allow me to play content/videos stored on my PC using XBMC, effectively turning it into a streaming box.  Doing a little research, I found out that wireless bridge capabilities were one of the many features that the <a href="http://www.dd-wrt.com/">DD-WRT</a> firmware added to the WRT-54GL.  </p>
<p>Mind you, DD-WRT doesn&#8217;t only work with the Linksys WRT-54G/GL.  A <a href="http://www.dd-wrt.com/wiki/index.php/Supported_Devices">full list of supported devices</a> is available on their site, and the list is quite long.  However, I believe the WRT-54G was the first, after people discovered that initial versions of the WRT-54G were running Linux, thus requiring Linksys to make the source code available and spawning a bevy of third-party development for the device.  (Some later versions of the WRT-54G unfortunately do not support the full version of DD-WRT since the newer WRT-54Gs are now being shipped with VxWorks, another embedded OS, instead of Linux and thus have different hardware configurations)</p>
<h3>Getting it to run</h3>
<p>DD-WRT has a feature list so long that covering it is outside the scope of this article.  Instead, I&#8217;ll focus on how I set it up as a wireless bridge to provide wireless access to the network for wired clients.  The DD-WRT wiki has an <a href="http://www.dd-wrt.com/wiki/index.php/Installation">installation guide</a>, and while it gets the job done, it&#8217;s unfortunately very convoluted, confusing and contradictory, on account of it being written wiki-style by many authors with evidently no editing whatsoever. </p>
<p>Basically, here&#8217;s what I did to get my WRT-54GL flashed to DD-WRT from the regular Linksys firmware: (As adapted from the <a href="http://www.dd-wrt.com/wiki/index.php/Installation">installation guide</a>, which you may want to follow as well)  If you <strong>do not</strong> have another router to use while you&#8217;re flashing, you&#8217;ll <strong>definitely</strong> want to read through the instructions thoroughly before doing anything to make sure you have all the required materials, instructions and so forth, since if anything goes wrong, you won&#8217;t have an Internet connection!</p>
<ol>
<li>Make sure you are on a wired connection to the router.</li>
<li>Reset it to factory defaults.</li>
<li>Download the latest stable MINI version of DD-WRT.  Flash using the &#8220;generic&#8221; bin over the web console.  The guide recommends using Internet Explorer instead of Firefox and while those instructions may be outdated, I followed them anyways.</li>
<li>If, after flashing, you cannot login with the default root/admin (which happened with me), do a hard reset of the router.  This is accomplished by holding down reset and plugging in the router while continuing to hold reset for 30 seconds.  (You may just have to hold reset for 30 seconds without the plug-in procedure) This should reset the login/password back to the normal defaults</li>
<li>Now, get the latest stable STANDARD version of DD-WRT.  Flash again using this version&#8217;s &#8220;generic&#8221; bin over the web console.  This adds more features over the mini version, which apparently you must first flash with when changing from the default Linksys firmware. </li>
</ol>
<p>This procedure worked for me, but I can&#8217;t be sure it&#8217;ll work the same for every router out there.</p>
<h3>Getting the wireless bridge connected</h3>
<p>The <a href="http://www.dd-wrt.com/wiki/index.php/Wireless_Bridge">documentation for this</a> over at the DD-WRT site, while long, is less confusing than the installation instructions.  I basically followed them to the letter, and within a few minutes, the WRT-54GL was online and connected over a WPA-PSK secured wireless connection.  I definitely recommend some form of WPA over WEP, as WEP is broken and cannot be considered secure for anything.</p>
<p>The guide indicates that WPA2 does not work correctly for the current version of DD-WRT (2.3 SP2 as of this writing), though it is an option in the settings for a wireless bridge.  I have not tried to get WPA2 to work myself, but reports from others seem to indicate that it does not work.  If and when I do try, I&#8217;ll update this article with my results.</p>
<p>Well, that&#8217;s about it.  I&#8217;m now happily streaming video to my XBMC setup, and so far, the wireless connection has been rock solid, without a single drop-out, freeze-up or slowdown.  In fact, it feels as zippy as a wired connection!  This is what wireless networking should be like and I&#8217;m glad it&#8217;s finally becoming a reality.</p>
<hr/>Copyright &copy; 2009 <strong><a href="http://unitstep.net">unitstep.net</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please contact <strong><a href="mailto:webmaster@unitstep.net">webmaster@unitstep.net</a></strong> for more information.<br/><span style="float: right;font-size: 7pt"><a href="http://blog.taragana.com/index.php/archive/wordpress-plugins-provided-by-taraganacom/">Plugin</a> by <a href="http://www.taragana.com/">Taragana</a></span>]]></content:encoded>
			<wfw:commentRss>http://unitstep.net/blog/2007/10/21/using-dd-wrt-to-turn-the-linksys-wrt-54gwrt-54gl-into-a-wireless-bridge/feed/</wfw:commentRss>
		</item>
		<item>
		<title>SirReal&#8217;s G15 plugin: The best and only Logitech G15 SDK applet you&#8217;ll ever need</title>
		<link>http://unitstep.net/blog/2007/10/16/sirreals-g15-plugin-the-best-and-only-logitech-g15-sdk-applet-youll-ever-need/</link>
		<comments>http://unitstep.net/blog/2007/10/16/sirreals-g15-plugin-the-best-and-only-logitech-g15-sdk-applet-youll-ever-need/#comments</comments>
		<pubDate>Wed, 17 Oct 2007 00:56:45 +0000</pubDate>
		<dc:creator>Peter Chng</dc:creator>
		
		<category><![CDATA[g15]]></category>

		<category><![CDATA[guides]]></category>

		<category><![CDATA[keyboards]]></category>

		<category><![CDATA[logitech]]></category>

		<guid isPermaLink="false">http://unitstep.net/blog/2007/10/16/sirreals-g15-plugin-the-best-and-only-logitech-g15-sdk-applet-youll-ever-need/</guid>
		<description><![CDATA[
I&#8217;ve had a Logitech G15 gaming keyboard for over a year and a half already, and it&#8217;s pretty much been the best keyboard I&#8217;ve ever used.  While it can&#8217;t compare to my old Fujitsu 4725, a &#8220;clicky&#8221; keyboard, in terms of tactile response, it&#8217;s built-in LCD and extra gaming macro keys put it on [...]]]></description>
			<content:encoded><![CDATA[<p class="image align-right"><img src="http://static.zooomr.com/images/3525874_0a75c852e0_t.jpg" width="100" height="75" alt="Logitech G15 running SirReal's applet" /></p>
<p>I&#8217;ve had a <a href="http://www.extremetech.com/article2/0,1697,1870601,00.asp">Logitech G15</a> gaming keyboard for over a year and a half already, and it&#8217;s pretty much been the best keyboard I&#8217;ve ever used.  While it can&#8217;t compare to my old <a href="http://www.epinions.com/pr-Keyboards-Fujitsu_Siemens_FKB_4725_FKB4725-501">Fujitsu 4725</a>, a &#8220;clicky&#8221; keyboard, in terms of tactile response, it&#8217;s built-in LCD and extra gaming macro keys put it on top in terms of usefulness.  The LCD even has its own set of buttons for controlling programs or applets that are running on it.</p>
<p>Logitech bundled several applets with the G15 for displaying things like volume, resource usage and a clock.  However, these things were on different screens, so if you wanted to see the clock you&#8217;d just have to wait for it to appear in the cycle, or else navigate to it using the buttons.  This was annoying, and I ended up not really utilizing the screen to its full potential.  That is, until I discovered <a href="http://forum.goteamspeak.com/showthread.php?t=32017">SirReal&#8217;s multipurpose G15 plugin</a>.  This is the <em>only</em> G15 applet you&#8217;ll ever need.  Please check out the screen shots and read more, and I guarantee you&#8217;ll love it.</p>
<h3>Searching for the killer applet</h3>
<p>I&#8217;d previously played around with G15 applets found at sites like <a href="http://g15mods.com/">G15 mods</a> and <a href="http://www.g15forums.com/">G15 Forums</a>, and while some of them were nifty, I couldn&#8217;t really find any that suited my needs.  Some of them additionally required <a href="http://www.lcdstudio.com/">LCDStudio</a>, another program, to run - which added more resource usage, something I was trying to avoid.  I never really used the LCD for games, such as viewing status/ammo/info, which I guess is the intended usage, judging from Logitech&#8217;s marketing, so this ability did not matter to me. </p>
<p>So, what I really wanted was a multipurpose applet/utility based on Logitech&#8217;s SDK, so that it would run just using Logitech&#8217;s LCD Manager.  This would eliminate the need to have separate LCD applets for each bit of info I wanted to see, and would simplify the display - no more having to cycle through multiple pages.</p>
<h3>SirReal&#8217;s G15 plugin cometh</h3>
<p><a href="http://forum.goteamspeak.com/showthread.php?t=32017">SirReal&#8217;s Multipurpose G15 plugin</a> fit the bill.  (<a href="http://icrontic.com/articles/sirreal_g15_plugin">Another link</a>)  This applet crams an astounding amount of information, almost everything you could want, into the G15&#8217;s 160 x 43-resolution LCD.  The plugin is fully-configurable so you can define what and where you want to display certain modules of information.  Here&#8217;s a shot of what mine&#8217;s currently displaying:</p>
<p class="image"><a href="http://www.zooomr.com/photos/stygiansonic/3525867/" title="Photo Sharing"><img src="http://static.zooomr.com/images/3525867_c9e2029a62_m.jpg" width="240" height="180" alt="Logitech G15 and SirReal's applet with backlight" /></a></p>
<p>Along the top, we have the full date, number of unreal e-mails (displayed as envelopes) and the 24-hr time.  The time and date format can be customized.  In the next row, resource usage (CPU/MEM) is displayed.  The CPU bar actually consists of three separate 1-pixel bars for my system: One for each core, and one for overall usage.  To the right of that, the network usage (current KiB in/out) is displayed, using bars and the numerical value.</p>
<p>On the bottom row are four &#8220;slots&#8221;.  These can be configured to display a variety of information from the supported modules of the plugin.  I won&#8217;t repeat all of the <a href="http://forum.goteamspeak.com/showthread.php?t=32017">features</a> here, but it&#8217;s safe to say that most people will be satisfied.  I have the a world-time clock in the first, the SpeedFan module (for system temperatures) in the second, speaker/volume information in the third and net-graph utilization in the fourth.  Each module itself may have multiple screens of information, and you can cycle between them by pressing the LCD button below it.  Furthermore, you can have multiple modules in each slot; just cycle between them by holding CTRL and pressing the corresponding LCD button.</p>
<h3>A Power User&#8217;s dream</h3>
<p>As if all of these features weren&#8217;t enough (everything from support of Winamp/iTunes, to SpeedFan and TeamSpeak 2, and even detecting unresponsive programs), the setup is completely customizable by editing a simple configuration file.  Instructions are in the file itself, so it&#8217;s a no-brainer.  Furthermore, the applet is small - less than 80 KiB as of version 2.5, and is taking up less than 3 MiB of RAM after several days of continuous usage.  CPU usage is similarly small. </p>
<p>There&#8217;s simply no reason <strong>not</strong> to get this applet for your G15 keyboard - it&#8217;ll easily replace every other applet you&#8217;re running and more.  SirReal&#8217;s G15 plugin seems to have been made by a true power user, who knows what other power users want from the G15 LCD - an easy to read screen that displays all the useful information you need, from the date/time, volume, CPU/Mem usage and more.  It&#8217;s truly the <a href="/blog/2006/08/03/enabling-all-options-on-logitech-mice-using-uberoptions-and-setpoint/">uberOptions</a> of the G15 LCD. </p>
<hr/>Copyright &copy; 2009 <strong><a href="http://unitstep.net">unitstep.net</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please contact <strong><a href="mailto:webmaster@unitstep.net">webmaster@unitstep.net</a></strong> for more information.<br/><span style="float: right;font-size: 7pt"><a href="http://blog.taragana.com/index.php/archive/wordpress-plugins-provided-by-taraganacom/">Plugin</a> by <a href="http://www.taragana.com/">Taragana</a></span>]]></content:encoded>
			<wfw:commentRss>http://unitstep.net/blog/2007/10/16/sirreals-g15-plugin-the-best-and-only-logitech-g15-sdk-applet-youll-ever-need/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Enabling all options on Logitech mice using uberOptions and SetPoint</title>
		<link>http://unitstep.net/blog/2006/08/03/enabling-all-options-on-logitech-mice-using-uberoptions-and-setpoint/</link>
		<comments>http://unitstep.net/blog/2006/08/03/enabling-all-options-on-logitech-mice-using-uberoptions-and-setpoint/#comments</comments>
		<pubDate>Fri, 04 Aug 2006 00:25:49 +0000</pubDate>
		<dc:creator>Peter Chng</dc:creator>
		
		<category><![CDATA[Hardware]]></category>

		<category><![CDATA[guides]]></category>

		<category><![CDATA[logitech]]></category>

		<category><![CDATA[mice]]></category>

		<category><![CDATA[setpoint]]></category>

		<guid isPermaLink="false">http://unitstep.net/blog/2006/08/03/enabling-all-options-on-logitech-mice-using-uberoptions-and-setpoint/</guid>
		<description><![CDATA[This guide is aimed at owners of Logitech mice that have extra buttons and would like to configure them for various program or application-specific settings.  By using a program called uberOptions in addition with SetPoint, Logitech&#8217;s keyboard and mouse control software, you can configure your mouse buttons to do different things in different programs, [...]]]></description>
			<content:encoded><![CDATA[<p>This guide is aimed at owners of Logitech mice that have extra buttons and would like to configure them for various program or application-specific settings.  By using a program called <a href="http://www.mstarmetro.net/~rlowens/uberOptions/">uberOptions</a> in addition with SetPoint, Logitech&#8217;s keyboard and mouse control software, you can configure your mouse buttons to do different things in different programs, without having to manually change button configurations all the time.  This is especially useful to the Logitech mice that have many extra buttons, as the buttons, being close to your finger tips, can be used for time-saving shortcut commands across multiple applications and games.</p>
<div class="notice">
<h3>Update - 2008-02-01</h3>
<p>The uberOptions site is <a href="http://www.mstarmetro.net/users/rlowens/">back online at a new URI</a>.  Please ignore any outdated or broken links in this article as I work to fix them.
</div>
<h3>Introduction</h3>
<p>I originally wrote a <a href="http://unitstep.net/blog/2006/07/14/enabling-all-options-on-your-logitech-mouse/">short blurb</a> about using uberOptions and SetPoint to get more out of your Logitech mouse, but decided to turn it into a longer guide with more information; uberOptions is a neat program that modifies some of SetPoint&#8217;s configuration files in order to allow all application-specific settings for many more Logitech mice than just a select few, and allows for almost any option or command to be assigned to any mouse button, and thus makes it possible to customize your mouse much more. </p>
<p>A lot of people might be wondering what all this fuss is about.  Most people don&#8217;t have a mouse with more than three buttons (the standard left/right and wheel configuration), and most won&#8217;t care for or need one.  But, for the rest of us, mostly tech-saavy people who enjoy and use their computer a lot, having a mouse with extra buttons can be a useful time saver, akin to learning keyboard shortcuts.  </p>
<h3>What&#8217;s wrong, then?</h3>
<p>SetPoint does an alright job of allowing customization of your mouse.  Most of the buttons can be bound to a range of options, but some buttons are limited to certain functions.  Furthermore, most Logitech mice don&#8217;t &#8220;support&#8221; application-specific settings through SetPoint - so once you bind actions to certain buttons, they persist no matter what program or game you are using, thus limiting the mouse&#8217;s functionality since different programs or games might use different keystrokes or actions.  However, this is an intentional software limitation, not a limitation of the mice themselves.  For example, the G7, G5 and MX610 mice from Logitech <strong>will have</strong> application-specific settings available, but other mice, such as the MX1000 won&#8217;t have this option available.  </p>
<p>To me, this sort of intentional limitation is mind-boggling - but perhaps it&#8217;s part of Logitech&#8217;s market strategy to set apart certain mice as having &#8220;features&#8221; that others do not.  Or, perhaps they have just forgotten to update their SetPoint software, but I find this hard to believe. </p>
<h3>Solution: <a href="http://www.mstarmetro.net/~rlowens/uberOptions/">uberOptions</a>!</h3>
<p>Thankfully, a nice fellow by the name of Richard Lowens has written a nifty program, called uberOptions, that changes the configuration files of SetPoint to enable all of the &#8220;disabled&#8221; options for almost all Logitech mice!  Since all this required was modifying some <a href="http://www.w3.org/XML/" class="ubernym uttInitialism"><acronym class="uttInitialism" title="eXtensible Markup Language">XML</acronym></a> files that stored the configuration information for each mouse (and thus determined which had application-specific settings and so forth), once the program has been installed, it doesn&#8217;t need to be run again.  Thus, you won&#8217;t have another program that must always be running in the background, which should cut down on system resource usage, if you&#8217;re concerned about that sort of thing.   It&#8217;s thus a fairly elegant solution.</p>
<p>Before beginning, you&#8217;ll need to head over to the <a href="http://www.mstarmetro.net/~rlowens/uberOptions/">uberOptions site</a> and download the program - it&#8217;s a relatively small download at only 6.3 MB and so shouldn&#8217;t take too long.  You should also check out the list of mice supported to see if yours is on the list.  Most of the Logitech mice with extra buttons are supported, including the popular MX1000 and MX518 mice.  The MX610, G7 and G5 mice are also supported, but as mentioned before, they already support application-specific settings, so all you&#8217;ll get out of uberOptions is more options for the buttons.</p>
<p>Note that the older MX700 (original Logitech cordless rechargeable) and MX500 mice <strong>are not supported</strong>, not because uberOptions doesn&#8217;t support them, but rather, <strong>SetPoint doesn&#8217;t support</strong> these mice.  Someone might be able to write a configuration file for these to enable support in SetPoint, but I&#8217;m not sure if that&#8217;s possible or whether it&#8217;ll happen - for now, you&#8217;re stuck using the older MouseWare for these and older Logitech mice.  See <a href="#mouseware">further down</a> in this guide for more information.</p>
<p>During installation, uberOptions will backup the original configuration files so that if you decide to uninstall, everything can go back to normal.  Once that&#8217;s done, you can open up SetPoint and begin setting things up.  Here&#8217;s what it&#8217;ll look like. (Using my MX1000 for reference)</p>
<p class="image">
<a href="http://unitstep.net/wordpress/wp-content/uploads/2006/08/logitech-uberoptions-1.png" title="Screenshot of SetPoint with uberOptions" rel="lightbox"><img src="http://unitstep.net/wordpress/wp-content/uploads/2006/08/logitech-uberoptions-1-small.png" alt="Screenshot of SetPoint with uberOptions" /></a>
</p>
<p>You can see that uberOptions is installed, because it appends a &#8220;Ã¼&#8221; character after the mouse&#8217;s name.  The options for each mouse button also look slightly different.  As you can see, I&#8217;ve left almost everything to the default, except for changing mouse buttons 3, 4, and 5 (the middle, back and forward buttons respectively) to &#8220;generic&#8221; buttons for &#8220;All Programs&#8221;.  As far as I know, Windows XP supports the first five buttons natively, so this is why I&#8217;ve set them to generic buttons.  This allows them to work just fine in the desktop and in web browsers.  The &#8220;Back&#8221; and &#8220;Forward&#8221; functionality is especially useful when moving through directories or browsing webpages - I don&#8217;t know how I lived without it before!</p>
<p class="image">
<a href="http://unitstep.net/wordpress/wp-content/uploads/2006/08/logitech-uberoptions-2.png" title="Button options with uberOptions" rel="lightbox"><img src="http://unitstep.net/wordpress/wp-content/uploads/2006/08/logitech-uberoptions-2.png" alt="Button options with uberOptions" /></a>
</p>
<p>As you can see, uberOptions enables almost <strong>any</strong> functionality to be assigned to any button.  The sheer number of functions available is astonishing, and almost confusing.  While it my seem daunting at first, it allows for full customization of the mouse&#8217;s buttons, which you should be able to do, since it&#8217;s your mouse anyways.  In fact, you&#8217;ll probably not want to change most of the default button assignments for &#8220;All Programs&#8221;, as things can get a little messy.  You&#8217;ll probably only want to change the button assignments for application-specific profiles, which I&#8217;ve been ranting about since the start as being the most useful ability.</p>
<p class="image">
<a href="http://unitstep.net/wordpress/wp-content/uploads/2006/08/logitech-uberoptions-3.png" title="Application specific settings" rel="lightbox"><img src="http://unitstep.net/wordpress/wp-content/uploads/2006/08/logitech-uberoptions-3-small.png" alt="Application specific settings" /></a>
</p>
<p>That little drop-down box opens up a world of options, customizability and improvements for your Logitech mouse.  Basically, you can assign profiles or configurations of buttons to specific programs or games.  You can add any EXE file to the list, and when SetPoint detects that executable as having focus (I.E, the application is in the foreground, or you&#8217;re playing the specified game), it will use the button assignments you&#8217;ve specified for that application or game!  This basically allows for infinite configuration possbilities.  In the example screenshot, I&#8217;ve added <a href="http://unitstep.net/blog/category/guild-wars/">Guild Wars</a> to the list, where for that profile, I&#8217;ve assigned a bunch of keystrokes to the extra buttons for more functionality for the mouse in that game.</p>
<p>Keystrokes are perhaps the best way to utilize the extra mouse buttons, since most games use keystrokes as input commands of some sort, and using the keyboard for hard-to-remember keystrokes can be hectic in the middle of a game.  Note that this may not be necessary for the first five buttons, since if they&#8217;re set as regular/generic buttons, they will be detected as such in a game.  The other extra buttons (beyond the fifth) cannot be detected in games as &#8220;extra buttons&#8221; (for example, the application-switch button and tilt-wheel buttons on the MX1000), and can only be used if they&#8217;re assigned keystrokes.  RPGs are notorious for having a lot of keystrokes and input commands, so using the extra buttons on the MX1000 only makes sense.  RTS games can also benefit similarly.  </p>
<p>With a properly configured SetPoint and uberOptions, and some adjustment time, your mouse can actually be programmed to do a lot in applications and games!</p>
<h3>Drawbacks and other solutions</h3>
<p>There are some behaviour quirks.  For example, when I set a button to &#8220;generic&#8221; for &#8220;All Programs&#8221; and then selected it again in the options, the ability to set a per-application setting for that button disappeared.  If the mouse button were set to something else, the application-specific settings (the &#8220;Manage Programs&#8230;&#8221; button) re-appeared.  I&#8217;m not sure this is a problem with uberOptions, as it could be a problem with the quirky behaviour of SetPoint.  I noticed this when I <a href="http://www.virtual-hideout.net/reviews/logitech_mx610_left/index.shtml">reviewed the MX610</a>, while using it with a non-uberOption&#8217;d version of SetPoint.  This doesn&#8217;t totally prevent you from configuring application-specific settings, as you just have to be careful how you go about things.  If anything, it&#8217;s a minor annoyance.  Maybe it&#8217;ll be fixed in a later version of uberOptions or SetPoint.</p>
<p id="mouseware">
An alternative to uberOptions is the <a href="http://www.logigamer.com/">LogiGamer Mouse profile utility</a>, which works with MX500, MX700, MX310, MX510, MX900 and MX1000 mice.  Like uberOptions, it allows application-specific settings for the mice, so it basically offers the same functionality and features.  However, it&#8217;s a separate program that, as far as I can tell, must be running in the background for your settings to take effect.  It also requires SetPoint to be installed, and also requires the <a href="http://msdn.microsoft.com/netframework/technologyinfo/howtoget/default.aspx">.NET 1.1 Framework</a> to be installed, so if you don&#8217;t like that idea, uberOptions is probably a better choice.  However, if you&#8217;re using a mouse that doesn&#8217;t support SetPoint, then this program might be your only option for application-specific settings.
</p>
<h3>Last thoughts</h3>
<p>I hope this guide helped in some small way.  For most people, spending extra time configuring a mouse and its extra buttons for specific use in certain applications and games is a foreign concept that doesn&#8217;t deserve any attention - I can understand that.  However, for us gearheads who get some reward from making something work better than it should, customization is something we can&#8217;t be without.  </p>
<h3>References</h3>
<ol class="note less">
<li><a href="http://www.logigamer.com/forums/viewtopic.php?t=142">[uberOptions] Enable all options on all buttons in SetPoint (Forum thread)</a></li>
<li><a href="http://www.mstarmetro.net/~rlowens/uberOptions/">uberOptions homepage</a></li>
<li><a href="http://forums.logitech.com/logitech/board/message?board.id=bluetooth_mice&#038;message.id=41">MX1000 mouse button issues (Forum thread)</a></li>
<li><a href="http://forums.logitech.com/logitech/board/message?board.id=software_mice&#038;message.id=257">Problem with uberOptions and MB 4 &#038; 5 (Forum thread)</a></li>
<li><a href="http://forums.logitech.com/logitech/board/message?board.id=software_mice&#038;message.id=187">UberOptions&#8230;wow&#8230;.just wow (Forum thread)</a></li>
<li><a href="http://www.logigamer.com/">LogiGamer Mouse profile utility homepage</a></li>
<li><a href="http://unitstep.net/blog/2006/07/14/enabling-all-options-on-your-logitech-mouse/">Enabling all options on your Logitech mouse</a></li>
</ol>
<hr/>Copyright &copy; 2009 <strong><a href="http://unitstep.net">unitstep.net</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please contact <strong><a href="mailto:webmaster@unitstep.net">webmaster@unitstep.net</a></strong> for more information.<br/><span style="float: right;font-size: 7pt"><a href="http://blog.taragana.com/index.php/archive/wordpress-plugins-provided-by-taraganacom/">Plugin</a> by <a href="http://www.taragana.com/">Taragana</a></span>]]></content:encoded>
			<wfw:commentRss>http://unitstep.net/blog/2006/08/03/enabling-all-options-on-logitech-mice-using-uberoptions-and-setpoint/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
