tag:blogger.com,1999:blog-19375398131347879612024-11-01T11:44:29.212+01:00Kevin on CodeI create software and lead agile software teams.Anonymoushttp://www.blogger.com/profile/04412171213630922945noreply@blogger.comBlogger38125tag:blogger.com,1999:blog-1937539813134787961.post-33143898804699691442015-08-20T15:58:00.001+02:002015-08-20T15:58:11.080+02:00Blog Retired<span style="color: #cc0000;">I am no longer posting to this blog. To see my up-to-date blog on programming, visit&nbsp;<a href="https://medium.com/kevin-on-code">https://medium.com/kevin-on-code</a></span><div> <span style="color: #cc0000;"><br /></span></div> <div> <span style="color: #cc0000;">You can also visit my personal page at&nbsp;<a href="http://www.kevinalbrecht.com/">http://www.kevinalbrecht.com</a></span></div> Anonymoushttp://www.blogger.com/profile/04412171213630922945noreply@blogger.com0tag:blogger.com,1999:blog-1937539813134787961.post-78150511493141611282013-06-02T10:51:00.001+02:002013-06-02T10:56:22.718+02:00Value Attributes Don't Always Mean What You Think They MeanI recently discovered the hard way that the "value" attributes of different HTML elements can have subtle and frustratingly different meanings.<br /> <br /> Take a look at this simple example:<br /> <pre class="code">&lt;input type="button" value="one" id="buttonX"&gt; &lt;input type="text" value="one" id="textX"&gt; &lt;script&gt; var buttonX = document.getElementById("buttonX"); var textX = document.getElementById("textX"); buttonX.value = "two"; textX.value = "two"; buttonX.setAttribute("value","three"); textX.setAttribute("value","three"); &lt;/script&gt;</pre> <i>(View this as a JSFiddle: <a href="http://jsfiddle.net/sEpMz/">http://jsfiddle.net/sEpMz/</a>)</i><br /> <br /> After running this code, you would probably guess that the text visible in the two widgets would both be "three", but in fact, the button will display "three" while the text box will display "two"!<br /> <br /> The reason behind this is that for certain input element types, the "value" attribute defines the initial text of the widget, while for other element types, the "value" attribute defines the visible text of the widget!<br /> <br /> The important distinction here is between the "value" attribute (the <code>value="something"</code> that appears in the HTML), and the "value" property (<code>elementX.value = 'something'</code> in JavaScript). The property will always reflect what is displayed in the widget on the page, while the attribute has different behavior depending on the type of the input element.Anonymoushttp://www.blogger.com/profile/04412171213630922945noreply@blogger.com0tag:blogger.com,1999:blog-1937539813134787961.post-60813143644138777152013-05-23T20:58:00.001+02:002013-05-24T07:56:07.097+02:00A Short Survey on the State of Functional Reactive Programming in ClojureScriptIn the Object-Oriented world of JavaScript, architectures like MVP, MVC, and their brethren are well established. But when I started using ClojureScript to build rich user interfaces on the web, I was naturally interested in finding ways to architect my site that are friendly to a functional programming language like Clojure. This led me to functional reactive programming, or FRP.<br /> <div> <br /></div> <div> FRP, probably the best-known user interface paradigm for functional programming, models UIs as dataflows, where changes (user actions or data source changes) propagate through the system using purely functional operations and eventually end up as visual changes back in the UI. In short, FRP is similar to how changes to a cell in a spreadsheet propagate to other dependent cells.</div> <div> <br /></div> <div> Though the ClojureScript ecosystem is still fairly immature (or perhaps because it is), there are many libraries which support the FRP style of programming. If you are looking for an alternative to faking object-oriented styles of programming in ClojureScript, jump in and give one or more a try!<br /> <br /> <i>(By the way, if you want my personal recommendation, I have had a lot of luck with the simplicity and power of&nbsp;<a href="https://github.com/Flamefork/widje">widje</a>.)</i><br /> <b><br /></b></div> <div> <h3> Native ClojureScript libraries</h3> </div> <div> C2<br /> <ul> <li><a href="https://github.com/lynaghk/todoFRP/tree/master/todo/c2" target="">todoFRP's C2 example (Github)</a></li> <ul> </ul> </ul> cljs-binding<br /> <ul> <li><a href="https://github.com/fluentsoftware/cljs-binding">cljs-binding (Github)</a></li> <ul> </ul> </ul> Javelin<br /> <ul> <li><a href="https://github.com/tailrecursion/javelin">Javelin (Github)</a></li> <li><a href="https://github.com/lynaghk/todoFRP/tree/master/todo/javelin">todoFRP's Javelin example (Github)</a></li> </ul> Pedestal<br /> <ul> <li><a href="http://pedestal.io/">Pedestal</a></li> <li><a href="http://squirrel.pl/blog/2013/05/16/getting-started-with-pedestal-on-client-side/comment-page-1/#comment-3008">"Getting Started with Pedestal on Client Side" (blog post)</a></li> </ul> <ul><ul> </ul> </ul> Reflex<br /> <ul> <li><a href="https://github.com/lynaghk/reflex">Reflex (Github)</a></li> <li><a href="https://github.com/lynaghk/reflex">todoFRP's Reflex example (Github)</a></li> </ul> <ul><ul> </ul> </ul> Shafty<br /> <ul> <li><a href="https://github.com/cmeiklejohn/shafty">Shafty (Github)</a></li> <ul> </ul> </ul> Widje<br /> <ul> <li><a href="https://github.com/Flamefork/widje">widje (Github)</a></li> <li><a href="https://github.com/lynaghk/todoFRP/tree/master/todo/widje">todoFRP's Widje example (Github)</a></li> </ul> <ul><ul> </ul> <ul> </ul> </ul> <div> <h3> ClojureScript libraries built on top of JavaScript libraries</h3> </div> </div> <div> acute (wrapper around AngularJS)<br /> <ul> <li><a href="https://github.com/dribnet/acute/">acute (Github)</a></li> <ul> </ul> </ul> rx-cljs (wrapper around RxJS)<br /> <ul> <li><a href="https://github.com/leonardoborges/rx-cljs">rx-cljs (Github)</a></li> <li><a href="https://github.com/Reactive-Extensions/RxJS">RxJS (Github)</a></li> <ul> </ul> </ul> Yolk (wrapper around Bacon.js)<br /> <ul> <li><a href="https://github.com/Cicayda/yolk">Yolk (Github)</a></li> <li><a href="http://www.youtube.com/watch?v=nket0K1RXU4">Wilkes Joiner on Yolk and FRP (YouTube video)</a></li> <li><a href="https://github.com/Cicayda/yolk-examples">Yolk Examples (Github)</a></li> <li><a href="https://github.com/raimohanska/bacon.js">Bacon.js (Github)</a></li> <ul> </ul> </ul> Clang (wrapper around AngularJS)<br /> <ul> <li><a href="https://github.com/pangloss/clang">Clang (Github)</a></li> <ul> </ul> </ul> </div> <div> <h3> Using JavaScript libraries directly</h3> </div> <div> AngularJS<br /> <ul> <li><a href="https://github.com/lynaghk/todoFRP/tree/master/todo/angular-cljs">todoFRP's AngularJS example (Github)</a></li> <li><a href="http://www.egghead.io/">Egghead AngularJS tutorial videos</a></li> <li>Explorations by Konrad Garus</li> <ul> <li><a href="http://squirrel.pl/blog/tag/angularjs/">Blog posts about ClojureScript + AngularJS</a></li> <li><a href="https://github.com/konrad-garus/hello-cljs-angular">hello-cljs-angular example (Github)</a></li> <li><a href="https://github.com/konrad-garus/angular-tutorial-cljs">Angular Tutorial in CLJS (Github)</a></li> <ul> </ul> </ul> </ul> </div> Anonymoushttp://www.blogger.com/profile/04412171213630922945noreply@blogger.com0tag:blogger.com,1999:blog-1937539813134787961.post-43255452025607456712011-12-22T21:48:00.000+01:002011-12-22T21:48:13.832+01:00My Programming Reading ListI started collecting links to reading materials for programmers recently for my own use, but I realized it could be more generally useful. Checkout my list here, and check back often for updates:<br /> <br /> <a href="https://docs.google.com/document/pub?id=1A0EVj7f4DUTjbFs4OLqkPJe-WZKG-NvIn5CTgc2F1lI">Kevin’s Programming Reading List</a>Anonymoushttp://www.blogger.com/profile/04412171213630922945noreply@blogger.com0tag:blogger.com,1999:blog-1937539813134787961.post-86987381946535468662011-12-07T13:59:00.000+01:002011-12-07T13:59:10.620+01:00My Git SetupMostly for my own personal future reference, here is how I setup my Git environment.<br /> <br /> <b>Multiple Accounts</b><br /> <br /> I love Git for source control, and it is a goal of mine to keep all of my personal projects on GitHub. That is easy enough, but for work, I also need to be able to use&nbsp;Git with two different accounts connecting to two different servers.<br /> <br /> For this example, I am going to assume there are two accounts: a GitHub account associated with a personal email, and an account hosted on an imaginary GitDude service associated with a work email.<br /> <br /> <b>Step 1: Create RSA Keys</b><br /> <ol> <li>Generate a key for GitHub:<br />ssh-keygen -t rsa -C "personal_email@example.com"</li> <li>When prompted, choose the following location for your file to go:<br />/Users/your_username/.ssh/id_rsa_github</li> <li>Follow instructions in the "Set up Git" section on&nbsp; <a href="http://help.github.com/">http://help.github.com/</a>&nbsp;to upload your public key to GitHub. On the same page, follow the instructions for setting your github.user and github.token config values.</li> <li>Generate a key for GitDude:<br />ssh-keygen -t rsa -C "work_email@example.com" </li> <li>When prompted, choose the following location for your file to go:<br />/Users/your_username/.ssh/id_rsa_gitdude</li> </ol> <div> <b>Step 2: Setup Config File</b></div> <div> <ol> <li>Create a blank file called "config" in your ~/.ssh directory.</li> <li>Edit the file, and type the following text: <br /><br /><pre class="code">Host gitdude.com HostName git.gitdude.com User git IdentityFile /Users/your_username/.ssh/id_rsa_gitdude Host github.com HostName github.com User git IdentityFile /Users/your_username/.ssh/id_rsa_github</pre> </li> </ol> </div> <div> <b>Step 3: Setup User Name and Email</b></div> <br /> When using only one account on a computer, you can use global settings for user.name and user.email. However, when using two separate accounts, you need to use local settings for each repo. If you want to still use global settings, you will still need to use local settings for the repos that don't use the global credentials.<br /> <ul> <li>See this to get a list of all global settings:<br />git config --global -l</li> <li>Use this to set global git info:<br />git config --global user.name "First Last"<br />git config --global user.email "your_email@example.com"</li> <li>Or this for local:<br />git config --local user.name "First Last"<br />git config --local user.email "your_email@example.com"</li> </ul> <div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"> Same for github.user and github.token properties, if appropriate.<br /> <br /> <b>Step 4: Setup Default Editor</b><br /> <br /> In order to write multiline commits, you will want to associate git with an editor:<br /> <br /> <pre class="code"> git config core.editor emacs</pre> <div> <br /> This allows you to make commits like "git commit". The editor will then open and allow you to enter a commit message.</div> </div> <br /> <b>References</b><br /> <ul> <li><a href="http://help.github.com/">GitHub's Help Site</a></li> <li><a href="http://net.tutsplus.com/tutorials/tools-and-tips/how-to-work-with-github-and-multiple-accounts/">How to work with GitHub and multiple accounts</a></li> <li><a href="http://sandarenu.blogspot.com/2011/09/how-to-use-multiple-git-accounts.html">How to use multiple Git accounts</a></li> </ul>Anonymoushttp://www.blogger.com/profile/04412171213630922945noreply@blogger.com2tag:blogger.com,1999:blog-1937539813134787961.post-3745677169153872662011-11-30T19:27:00.001+01:002011-11-30T19:43:58.013+01:00Non-Locking Concurrency ControlAt work this week I have been working on implementing a concurrency control strategy on a system. During the discussions, software transactional memory (STM) came up, as we want to develop a solution that does not involve locking, and since my primary experience with it is Clojure's built-in STM, I brought that up.<br /> <br /> The world seems to be helping out today with a link on Hacker News to an old discussion involving Clojure's creator Rich Hickey:&nbsp;<a class="vt-p" href="http://www.azulsystems.com/blog/cliff/2008-05-27-clojure-stms-vs-locks">Clojure: STMs vs Locks</a>.&nbsp;Good food for thought.<br /> <br /> It is great to see that my Clojure knowledge is proving to be surprisingly useful at work. Those years of being a closeted functional programming nerd are paying off!<br /> <br /> I also re-watched <a class="vt-p" href="http://www.infoq.com/presentations/Are-We-There-Yet-Rich-Hickey">Rich Hickey's talk "Are We There Yet?"</a> and reread <a class="vt-p" href="http://home.pipeline.com/~hbaker1/ObjectIdentity.html">"Equal Rights for Functional Objects" by Henry G. Baker</a>, which are both great resources for really thinking about state in a functional manner.Anonymoushttp://www.blogger.com/profile/04412171213630922945noreply@blogger.com0tag:blogger.com,1999:blog-1937539813134787961.post-38883202138824954992011-11-20T09:36:00.000+01:002011-11-20T09:36:57.848+01:00My Clojure Environment SetupMostly for my own personal future reference, here is how I setup my Clojure environment.<br /> <b><br /></b><br /> <b>Emacs</b><br /> <ol> <li>Install Emacs 24 (<a class="vt-p" href="https://github.com/technomancy/emacs-starter-kit">links to the binaries available here</a>).</li> <li>Install the <a class="vt-p" href="https://github.com/technomancy/emacs-starter-kit">Emacs Starter Kit</a>&nbsp;or the <a class="vt-p" href="https://github.com/bbatsov/emacs-prelude">Emacs Prelude</a>.</li> </ol> <b>Leiningen</b><br /> <i>B<span style="background-color: transparent;">ased on instructions from&nbsp;</span><a class="vt-p" href="https://github.com/technomancy/leiningen" style="background-color: transparent;">Leiningen (github.com)</a>.</i><br /> <ol> <li>Get the Leiningen batch script from&nbsp;<a class="vt-p" href="https://raw.github.com/technomancy/leiningen/master/bin/lein.bat">https://raw.github.com/technomancy/leiningen/master/bin/lein.bat</a>&nbsp;and edit it to fetch version 1.6.1.1 instead of 2.0.0-SNAPSHOT.</li> <li>Put lein.bat in a folder. Add that folder to your PATH.</li> <li>Download wget.exe and curl.exe and add them to your PATH.</li> <li>Run:<br /><span style="font-family: 'Courier New', Courier, monospace;">lein self.install</span></li> </ol> <div> <b>Setting Up Emacs for Clojure</b></div> <div> <ol> <li>Setup clojure-mode</li> <li>Setup swank-clojure</li> <ol> <li>Follow installation instructions from&nbsp;<a class="vt-p" href="https://github.com/technomancy/swank-clojure">swank-clojure (github.com)</a>.</li> </ol> </ol> </div> <b>References</b><br /> <ul> <li><a class="vt-p" href="http://dev.clojure.org/display/doc/Getting+Started+with+Emacs">Getting Started with Emacs for Clojure (dev.clojure.org)</a></li> <li><a class="vt-p" href="https://github.com/technomancy/leiningen">Leiningen (github.com)</a></li> </ul>Anonymoushttp://www.blogger.com/profile/04412171213630922945noreply@blogger.com0tag:blogger.com,1999:blog-1937539813134787961.post-7806548742562119272011-05-11T15:17:00.000+02:002011-05-11T15:17:09.044+02:00Mirror of the Joy Programming LanguageI have been working on a pet project recently which was greatly inspired by fascinating little programming language called Joy. If you can, imagine combining Scheme with Forth, and that is basically what Joy is. It is a wonder of minimal, yet functional, programming language design, and a mind-bender to boot.<div><br /> </div><div>In any case, a couple of days ago, the original homepage for Joy went down. Considering that the language was created by a retired professor and maintained at his old university, there are any number of reasons why it went down, and seems likely never to come back again. With the hope that this language will not disappear from the web, I have <a href="http://www.kevinalbrecht.com/code/joy-mirror/index.html">mirrored the complete contents of the original Joy programming language homepage</a> on my personal site.</div>Anonymoushttp://www.blogger.com/profile/04412171213630922945noreply@blogger.com4tag:blogger.com,1999:blog-1937539813134787961.post-29813716525980048712011-04-19T22:35:00.000+02:002011-05-16T14:19:16.388+02:00Understanding JavaScript InheritanceJavaScript is a language which can be difficult to understand deeply. As opposed to most object-oriented programming languages, JavaScript is not class-based, it is prototype-based. This means that objects inherit from other objects, not classes. But while it is prototype-based, it has a syntax and features to make it seem like it is class-based. Because JavaScript seems confused about whether it is class-based or prototype-based, it can be difficult to use it correctly in either way. However, with a little bit of information about how JavaScript works behind the scenes, it is possible to emulate class-based inheritance or take full advantage of prototype-based inheritance.<br /> <br /> My goal in this blog post is to try to get to the root of how JavaScript inheritance works in three cases: without explicitly doing it, using modern prototype-based inheritance, and using modern pseudo-class-based inheritance.<br /> <br /> (This post is definitely not for beginners to JavaScript, but for someone who already knows it and wants to understand it a little deeper.)<br /> <br /> <b>Functions</b><br /> <br /> <pre class="code">function Animal() { }</pre><br /> On the surface, this code seems to create a function called Animal. But with JavaScript, the full truth is slightly more complicated. What actually happens when this code executes is that two objects are created. The first object, called Animal, is the constructor function itself. The second object, called Animal.prototype, has a property called Animal.prototype.constructor, which points to&nbsp;Animal.&nbsp;Animal&nbsp;has a property which points back to its prototype,&nbsp;Animal.prototype. This is illustrated in this diagram:<br /> <br /> <div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgTuBohSZSL6pk4vmiUgQx3j75A8oIMoelLNc4ZIRqcfsP4kIj7bSK5YKSt0nvgvFehzhg9rnnun8J8z5aT_BYNA5VfV74r2VZFCmxM1wnFwEbtRnjmwkQTHplkpQqE1baEz94M9r6hnGto/s1600/1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="63" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgTuBohSZSL6pk4vmiUgQx3j75A8oIMoelLNc4ZIRqcfsP4kIj7bSK5YKSt0nvgvFehzhg9rnnun8J8z5aT_BYNA5VfV74r2VZFCmxM1wnFwEbtRnjmwkQTHplkpQqE1baEz94M9r6hnGto/s400/1.png" width="400" /></a></div><br /> Although not shown in the diagram above,&nbsp;Animal.prototype actually inherits from the Object.prototype object. All objects in Javascript ultimately inherit from the Object.prototype object. A link from the object to the object it inherits from is stored in the internal __proto__ property (which is not publicly available in all browsers). The __proto__ property is illustrated in this diagram with a dashed line:<br /> <br /> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgdg8Mpn81_JWmtVMY7qlbTYzS970Ojo3yDmwDhLOwLL5t_-7ikbNOfVsZ8X_9I6mbzaKBjfp9jTythoQIW5HVRtzEqS1EZ8nTe2sjYhXfC2YDu2JPAnTttxPijtpg0TMznT1d8TN89aqFc/s1600/2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgdg8Mpn81_JWmtVMY7qlbTYzS970Ojo3yDmwDhLOwLL5t_-7ikbNOfVsZ8X_9I6mbzaKBjfp9jTythoQIW5HVRtzEqS1EZ8nTe2sjYhXfC2YDu2JPAnTttxPijtpg0TMznT1d8TN89aqFc/s1600/2.png" style="cursor: move;" /></a><br /> <br /> <b>The "new" Operator</b><br /> <br /> <pre class="code">function Planet() { } var earth = new Planet();</pre><br /> JavaScript's built-in "new" operator is how JavaScript attempts to emulate class-based inheritance. The "new" operator creates a new object, in this case called "earth", calls the function "Planet" on it, then sets the __proto__ property of the new object to Planet.prototype.<br /> <br /> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgF5PNw5MvZgcr_QP9drgJRuyPQ8yBjlwct97vE7_R3iMhYAjIC9IG73s1SYLFqclr8jrf4aAQhHDdh4B8B-3-3dCS9BWRu0fus_XdqbZMscAyXuqs9numS2Cw9rWaXPLxwVvbKVObcXLqQ/s1600/3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgF5PNw5MvZgcr_QP9drgJRuyPQ8yBjlwct97vE7_R3iMhYAjIC9IG73s1SYLFqclr8jrf4aAQhHDdh4B8B-3-3dCS9BWRu0fus_XdqbZMscAyXuqs9numS2Cw9rWaXPLxwVvbKVObcXLqQ/s1600/3.png" style="cursor: move;" /></a><br /> <br /> This allows functions to act like classes in some ways, but creating a deep inheritance&nbsp;hierarchy&nbsp;is impossible using just the "new" operator. For example, how could you create a new class that inherits from the Planet "class"?<br /> <br /> <b>Using the "Object.create" Function to Implement Prototype-Based Inheritance</b><br /> <br /> Because of the fact that most browsers do not let programmers directly access the __proto__ property, it is difficult to create objects in JavaScript that directly inherit from another object--the very definition of prototype-basd inheritance. To simplify this, Douglas Crockford discovered an improved way to create new objects in JavaScript. His function, illustrated below, creates an object which inherits from the object passed to the function, thus providing a simple method of implementing prototypal inheritance.<br /> <br /> <pre class="code">function createObject(parent) { function TempClass() {} TempClass.prototype = parent; var child = new TempClass(); return child; } </pre><br /> I will walk through what this function does one line at a time with diagrams.<br /> <br /> 1. function TempClass() {}<br /> <br /> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhObjuZxWMlz-NA4HacdOw-xo__0kXT_DRBy7K-7o8hm9hq26xQ-Qkqg1uSleajwFokS3OAInrdwxNlOORiRE0FBLDy-I1DJCvVH83od5TtWqb91wvaVC_YeEXLJQ7nC4PQvPSQg79R84pZ/s1600/4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="58" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhObjuZxWMlz-NA4HacdOw-xo__0kXT_DRBy7K-7o8hm9hq26xQ-Qkqg1uSleajwFokS3OAInrdwxNlOORiRE0FBLDy-I1DJCvVH83od5TtWqb91wvaVC_YeEXLJQ7nC4PQvPSQg79R84pZ/s400/4.png" width="400" /></a><br /> <br /> 2. TempClass.prototype = parent<br /> <br /> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhJEtXdfhFMMd9r3VwHoNKNaMLG2LtmLuHxnJ1jV09dK_v3ISQdyq2qi0Jc_rLiXryj5puidGllgTElsP3blmUd2wEyPX4jEJp50_6gtwKKYPC3x8D8hE5wJAmpNBDwKIJ3JQWP7inNsQNC/s1600/5.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="37" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhJEtXdfhFMMd9r3VwHoNKNaMLG2LtmLuHxnJ1jV09dK_v3ISQdyq2qi0Jc_rLiXryj5puidGllgTElsP3blmUd2wEyPX4jEJp50_6gtwKKYPC3x8D8hE5wJAmpNBDwKIJ3JQWP7inNsQNC/s400/5.png" width="400" /></a><br /> <br /> 3. var child = new TempClass()<br /> <br /> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjq4Jrf5tFPR_sDLVEroesilw5cznHToAGOVNS-ph1mS4DoN0nGP_uo6fn6y3gz5U7uZrYDq7-2K0N24L6jYpvsCO4g_DPKou__NtSm-wIXjnq6KVeAkof2MgfJHzrWlH-BpkR0R-I7DYI_/s1600/6.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="124" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjq4Jrf5tFPR_sDLVEroesilw5cznHToAGOVNS-ph1mS4DoN0nGP_uo6fn6y3gz5U7uZrYDq7-2K0N24L6jYpvsCO4g_DPKou__NtSm-wIXjnq6KVeAkof2MgfJHzrWlH-BpkR0R-I7DYI_/s320/6.png" style="cursor: move;" width="320" /></a><br /> <br /> A version of this function is actually implemented on all the newer browsers (including Internet Explorer 9, Firefox 4, and Chrome 9) as "<a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object/create">Object.create</a>". But it is easy to implement it yourself if you need to support older browsers, using the formulation above or that described by Douglas Crockford in <a href="http://javascript.crockford.com/prototypal.html">Prototypal Inheritance in JavaScript</a>.<br /> <br /> <b>Using the Inherit Function to Emulate Class-Based Inheritance</b><br /> <br /> Imagine that you wanted to use class-based inheritance in JavaScript. You might want to do something like this:<br /> <br /> <pre class="code">function Mammal() { this.hasHair = true; } function Bear() { Mammal.call(this); // Call parent constructor this.roars = true; } inherit(Bear, Mammal); var yogi = new Bear(); alert(yogi.hasHair); // This should display 'true' </pre><br /> Note the call to "Mammal.call" in the Bear constructor. This calls the parent constructor, similar to super() in Java or base() in C#. To implement the above, you can create some version of the "inherit" function:<br /> <br /> <pre class="code">function inherit(sub, super) { var newSubPrototype = createObject(super.prototype); newSubPrototype.constructor = sub; sub.prototype = newSubPrototype; }</pre><br /> The inherit function takes two classes (functions) as parameters, and makes the first class inherit from the second one. In memory, here is how each line of the inherit function works...<br /> <br /> 1. Before the function is run, we have two classes, sub and super:<br /> <br /> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjPnZIEaby_RdSMSpMoCxhgYIzOiHkqu_2NJYolGk3yvnBPbYPhNkz6o2zE711XgQTsRqhHlghSGcw-l7bNayvPoS96QNoCyWOZrS01oSVBQY4gT9O1HxKYHRMgJMC8PPrmPjnKJ9ZlZKyD/s1600/7.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjPnZIEaby_RdSMSpMoCxhgYIzOiHkqu_2NJYolGk3yvnBPbYPhNkz6o2zE711XgQTsRqhHlghSGcw-l7bNayvPoS96QNoCyWOZrS01oSVBQY4gT9O1HxKYHRMgJMC8PPrmPjnKJ9ZlZKyD/s1600/7.png" style="cursor: move;" /></a><br /> <br /> 2. var newSubPrototype = createObject(super.prototype)<br /> <br /> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjc-THqFgoMXBd3aw0NX8VcbyZ86lSSkBUIwZcPkHAax0SacDhBJSQSr0nR-ZEoeGA0xlvyYmfY1aSLEgYdzr3CFfQUbVVlYNw_w_xgPh-FeZMMpbLGslM7PQ3hKHxQJOB7lnvPo3OdapOI/s1600/8.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjc-THqFgoMXBd3aw0NX8VcbyZ86lSSkBUIwZcPkHAax0SacDhBJSQSr0nR-ZEoeGA0xlvyYmfY1aSLEgYdzr3CFfQUbVVlYNw_w_xgPh-FeZMMpbLGslM7PQ3hKHxQJOB7lnvPo3OdapOI/s1600/8.png" style="cursor: move;" /></a><br /> <br /> 3. newSubPrototype.constructor = sub<br /> <br /> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgV3Yuvfp3sclC8L6LHL45mhi7eXqyCH6eBT-iiyeevOaQzybaDVeiIet_hCS4wWpC_0_9DH9h3cZ32BvVgOLtASmmzA13OQ6ZLs_G2dSczsVzPzX1hrflFjpwTjJAqtuLJBFEVH2PVUEEQ/s1600/9.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="147" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgV3Yuvfp3sclC8L6LHL45mhi7eXqyCH6eBT-iiyeevOaQzybaDVeiIet_hCS4wWpC_0_9DH9h3cZ32BvVgOLtASmmzA13OQ6ZLs_G2dSczsVzPzX1hrflFjpwTjJAqtuLJBFEVH2PVUEEQ/s400/9.png" width="400" /></a><br /> <br /> 4. sub.prototype = newSubPrototype<br /> <br /> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEit0YFTWEE99i7O7HGejE47blIe-ptWO0GGx5lezM5ZXsjXSsIvzyvknRZe9SX2J53cpVBtY7I2p07P7dY9zdaolkyNB08Vt8kFR24M_uLIdG3-mSgBFVm6K8BHIIYOCbrxgrmNB6AHCQtJ/s1600/10.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEit0YFTWEE99i7O7HGejE47blIe-ptWO0GGx5lezM5ZXsjXSsIvzyvknRZe9SX2J53cpVBtY7I2p07P7dY9zdaolkyNB08Vt8kFR24M_uLIdG3-mSgBFVm6K8BHIIYOCbrxgrmNB6AHCQtJ/s1600/10.png" /></a><br /> <br /> Using one of these two methods can allow you to implement whichever inheritance scheme you like, which is one of the reasons why JavaScript can be so powerful if understood correctly.<br /> <br /> <b>Related Links</b><br /> <ol><li>Tim Caswell's&nbsp;<a href="http://howtonode.org/object-graphs">Learning Javascript with Object Graphs</a>, <a href="http://howtonode.org/object-graphs-2">Part 2</a>, and <a href="http://howtonode.org/object-graphs-3">Part 3</a></li> <li>Dmitry A. Soshnikov's <a href="http://dmitrysoshnikov.com/ecmascript/javascript-the-core/">JavaScript. The core.</a><br /> (A deep understanding of scope, inheritance, closures.)</li> <li>Mozilla's <a href="https://developer.mozilla.org/en/JavaScript/Reference">JavaScript Reference</a></li> <li>Douglas Crockford's <a href="http://javascript.crockford.com/prototypal.html">Prototypal Inheritance in JavaScript</a></li> </ol><div><i>(Updated&nbsp;</i><i>2011-04-23 - Additional clarifications based on comments.)</i><br /> <i><span class="Apple-style-span" style="font-style: normal;"><i>(Updated 2011-05-16 - Added missing call to super constructor in Bear constructor.)</i></span></i></div>Anonymoushttp://www.blogger.com/profile/04412171213630922945noreply@blogger.com9tag:blogger.com,1999:blog-1937539813134787961.post-17642066466555962102011-04-04T22:57:00.000+02:002011-04-04T22:57:39.792+02:00Installing Google's Closure Linter on WindowsI am working on a JavaScript project right now, so I decided to try out <a href="http://code.google.com/closure/utilities/index.html">Closure Linter</a>, Google's relatively new JavaScript code style verification tool that is part of their Closure Tools collection. I'm using Windows 7 64-bit, and their instructions for using Closure Linter on Windows do not quite make it clear what all needs to be done to get it working.<br /> <br /> In case this is helpful to someone else in the future, here are the steps I took (modified from those found at&nbsp;<a href="http://code.google.com/closure/utilities/docs/linter_howto.html">How to Use Closure Linter</a>):<br /> <ul><li><b><span class="Apple-style-span" style="font-weight: normal;"><b>Download and install Python 2.7.x for Windows 32-bit.</b></span><span class="Apple-style-span" style="font-weight: normal;"> Note that you must choose the 32-bit version of Python from the 2.7.x branch to ensure that you can use the EasyInstaller program needed for the next step.</span></b></li> <b> <li><span class="Apple-style-span" style="font-weight: normal;"><b>Download and install&nbsp;<a href="http://pypi.python.org/pypi/setuptools#files">SetupTools/EasyInstall for Python 2.7</a>.</b></span></li> <li><span class="Apple-style-span" style="font-weight: normal;"><b>Install Closure Linter</b></span><span class="Apple-style-span" style="font-weight: normal;">:</span></li> </b> <ul><li>In a command prompt, change directory to to C:\Python27\Scripts</li> <li>Run this command:<br /> easy_install http://closure-linter.googlecode.com/files/closure_linter-latest.tar.gz</li> </ul></ul><div>Now you will be able to run Closure Linter using variations on this command:<br /> <span class="code">C:\Python27\Scripts\gjslint --nojsdoc -r DIRECTORY_TO_LINT</span></div><div><br /> </div><div>Good luck with the tool!</div>Anonymoushttp://www.blogger.com/profile/04412171213630922945noreply@blogger.com1tag:blogger.com,1999:blog-1937539813134787961.post-71330786230282067312011-01-06T22:35:00.000+01:002011-01-06T22:35:48.652+01:00Visual Studio Color ThemesWhenever I get tired of my color scheme in Visual Studio, I go to <a href="http://studiostyl.es/">Studio Styles</a> and try out a new theme. After that, I switch my font to a more readable font, like <a href="http://dejavu-fonts.org/wiki/Main_Page">Deja Vu Sans Mono</a>.Anonymoushttp://www.blogger.com/profile/04412171213630922945noreply@blogger.com0tag:blogger.com,1999:blog-1937539813134787961.post-28104991328855473262010-11-19T11:00:00.000+01:002010-11-19T11:00:05.346+01:00SAML 2.0I have been working a lot with SAML recently, which is a protocol for standardizing single sign on (SSO) between sites. A good number of sites and products use SAML as a SSO protocol, including Google Apps and Moodle, important sites to communicate with in my particular case.<br /> <br /> I'm working in .NET 3.5, which unfortunately has no built-in support for SAML 2.0, but there are many third-party libraries and references to build your own support for it.<br /> <br /> Here are some of the best links I have found for learning SAML.<br /> <br /> <b>References</b><br /> <ul><li><a href="http://code.google.com/googleapps/domain/sso/saml_reference_implementation.html">Google's introduction to SAML SSO</a></li> <li><a href="http://en.wikipedia.org/wiki/Security_Assertion_Markup_Language">SAML on Wikipedia</a></li> <li><a href="http://en.wikipedia.org/wiki/SAML_2.0">SAML 2.0 on Wikipedia</a></li> <li><a href="http://saml.xml.org/wiki/saml-wiki-knowledgebase">Official specs and documentation for SAML</a></li> </ul><b>Examples</b><br /> <ul><li><a href="http://code.google.com/p/google-apps-sso-sample/">Google App's reference implementation of SAML SSO</a></li> <li><a href="https://rnd.feide.no/saml-example-messages-2/">Example SAML requests and responses</a></li> </ul>Anonymoushttp://www.blogger.com/profile/04412171213630922945noreply@blogger.com1tag:blogger.com,1999:blog-1937539813134787961.post-18077511727109354432010-10-20T02:30:00.000+02:002010-10-20T02:30:00.582+02:00Importing GWT SDK Samples into EclipseI've recently started working with the Google Web Toolkit (GWT), which seems pretty sweet from everything I've read so far. It has great integration with an IDE, in this case Eclipse, which is absolutely essential.<br /> <br /> Unfortunately, it was hard to find a way to easily open GWT's sample projects in Eclipse, but after a little trial and error, here is what I came up with. For each sample project you want to use, do the following:<br /> <ol><li>Create a new Java project with the name of the sample project you want to use, for example, "Hello". Use all the other default settings, and press "Finish".</li> <li>Right-click on the project and choose "Import". Choose "General" -&gt; "File System", then press "Next".</li> <li>Browse to the directory of the sample project you want to import. On my computer, the project was found at something like:&nbsp;<u>C:\Program Files\eclipse\plugins\com.google.gwt.eclipse.sdkbundle...\gwt-2.0.4\samples</u>.&nbsp;Select all, then press "Finish".</li> <li>Right-click on the project and choose "Google" -&gt; "Web Toolkit Settings". Check the "Use Google Web Toolkit" check box.</li> <li>Go the the "Java Build Path" section of the project's properties. Change the default output folder to something like: "/Hello/war/WEB-INF/classes" (This will be different depending on your project name).</li> </ol><div>That's all! Good luck and have fun trying out GWT's samples.</div>Anonymoushttp://www.blogger.com/profile/04412171213630922945noreply@blogger.com7tag:blogger.com,1999:blog-1937539813134787961.post-69474282835314573642009-11-12T02:30:00.000+01:002009-11-12T02:30:00.123+01:00Best Android Apps by Category<b>Social Networking </b><br /> <ul><li>Twidroid (Twitter client)</li> <li>Facebook<br /> </li> </ul><b>Podcasts</b><br /> <ul><li><a href="http://www.snoggdoggler.com/">DoggCatcher</a></li> <ul><li>Easy control over when podcasts downloaded</li> </ul> </ul><b>Desktop Music Syncing Software</b><br /> <ul><li><a href="http://www.salling.com/MediaSync/">Salling Media Sync</a></li> <ul><li>Allows you to sync iTunes with your Android phone<br /> </li> </ul></ul><b>Music Listening</b><br /> <ul><li>Built-in Music App </li> </ul><b>Language Learning</b><br /> <ul><li>Anki</li> <ul><li>Flashcard app <br /> </li> </ul> <ul><li>Does not sync with Anki Online </li> </ul> </ul><b>Productivity</b><br /> <ul><li>Remember the Milk (Todo list w/ online sync)</li> <li>Movies by Flixster</li> <li>FeedR News Reader</li> </ul><b>Utilities </b><br /> <ul><li>WiFi OnOff</li> <li>Barcode Scanner</li> <li>Astro (File Browser)</li> </ul>Anonymoushttp://www.blogger.com/profile/04412171213630922945noreply@blogger.com0tag:blogger.com,1999:blog-1937539813134787961.post-4761928948440802732009-02-03T00:19:00.000+01:002009-02-03T19:12:45.918+01:00Creating a Clojure GUI Application with SWTIn my explorations of <a href="http://clojure.org/">Clojure</a>, I have been developing a desktop GUI application that uses <a href="http://www.eclipse.org/swt/">SWT</a>, the graphics toolkit that Eclipse uses. Once you get going, SWT is fairly intuitive to program in with Clojure, but you might need a little help to get started. Here is an example of a barebones app in SWT:<br /><pre class="code">(ns swttest<br />(:import (org.eclipse.swt.widgets Display Shell)<br /> (org.eclipse.swt.layout GridLayout)<br /> (org.eclipse.swt.events ShellAdapter)))<br /><br />(defn create-shell [display shell]<br />(let [layout (GridLayout.)]<br /> (doto shell<br /> (.setText "SWT Test")<br /> (.setLayout layout)<br /> (.addShellListener<br /> (proxy [ShellAdapter] []<br /> (shellClosed [evt]<br /> (System/exit 0)))))))<br /><br />(defn swt-loop [display shell]<br />(loop []<br /> (if (.isDisposed shell)<br /> (.dispose display)<br /> (do<br /> (if (not (.readAndDispatch display))<br /> (.sleep display))<br /> (recur)))))<br /><br />(defn begin []<br /> (let [display (Display.)<br /> shell (Shell. display)]<br /> (create-shell display shell)<br /> (.setSize shell 700 700)<br /> (.open shell)<br /> (swt-loop display shell)))<br /><br />(begin)</pre>On Mac, you will need to add the "-XstartOnFirstThread" command line option or your application will crash soon after launching.<br /><br /><span style="font-weight: bold;">Update:</span><br />I originally left out the line "(create-shell display shell)". The code above is now corrected.<br /><br /><span style="font-weight: bold;">See also:</span><br /><ul><li><a href="http://www.eclipse.org/swt/faq.php#carbonapp">SWT FAQ Entry on XstartOnFirstThread</a><br /></li><li><a href="http://groups.google.com/group/clojure/browse_thread/thread/0458ff5de09c8457/0b66104d6853e5b8?lnk=raot">Clojure forum thread with SWT example</a><br /></li></ul>Anonymoushttp://www.blogger.com/profile/04412171213630922945noreply@blogger.com6tag:blogger.com,1999:blog-1937539813134787961.post-68644596789028133222009-01-20T23:31:00.000+01:002009-01-20T23:51:08.671+01:00Google Code and SubversionI recently started using <a href="http://code.google.com/">Google Code</a> for hosting a new open source project I'm working on (written in Clojure) in my spare time. Google Code uses <a href="http://subversion.tigris.org/">Subversion</a> for version control, which <a href="http://www.webmonkey.com/blog/Is_Google_Code_Gearing_up_to_Support_Git_">some predict is going to change soon to Git</a>. While I am pretty familiar with the command line options for the <a href="http://git-scm.com/">Git</a> version control system, I'm definitely not with Subversion. Maybe Google Code will switch to Git soon, but until it does, I needed to use Subversion, so I went looking for some GUI-based Subversion clients to simplify its use.<br /><br /><span style="font-weight: bold;">Windows</span><br /><br />Finding a good Windows client was easy. <a href="http://tortoisesvn.tigris.org/"> TortoiseSVN</a> is an Explorer shell extension that is free, stable, and complete. It worked right out of the box with Google Code and I didn't have to read a single line of documentation to become proficient at it.<br /><br /><span style="font-weight: bold;">Mac</span><br /><br />The situation wasn't quite as simple for Mac. There are multiple non-free clients for Mac, but I wanted to stick with open source if possible. The closest thing to TortoiseSVN for Mac is something called <a href="http://scplugin.tigris.org/">SCPlugin</a>, but it is incomplete and development on it seems to have stalled in 2005 or 2006.<br /><br /><a href="http://code.google.com/p/svnx/">SvnX</a> is the one I ended up choosing. It is not quite as intuitive as TortoiseSVN, but it seems to get the job done. To get it working with Google Code, I had to run this command on the command line in order to accept the security certificate:<br /><pre class="code">svn list https://GOOGLE_CODE_CHECKOUT_URL</pre>That's it! Off to do some programming.Anonymoushttp://www.blogger.com/profile/04412171213630922945noreply@blogger.com3tag:blogger.com,1999:blog-1937539813134787961.post-83452410381783268592008-12-22T20:26:00.000+01:002008-12-22T20:56:54.737+01:00My Favorite MouseAs a programmer, I naturally spend a good portion of my waking hours--if not the majority--in front of a computer. This didn't seem a problem for the first quarter century of my life, but then about three years ago, I started experiencing pain in my mousing wrist. My first thought was that the beginning of carpal tunnel syndrome was setting in, which freaked me out.<br /><br />I immediately set out to try more ergonomic input devices, and I switched to a pen input device at home and a radical ergonomic mouse at work. While the pen input device worked fairly well, the ergonomic mouse I chose proved to be the single greatest purchase I've ever made. Since starting to use it, I no longer have any pain in my wrist. I now realize that with the many viable ergonomic options for mousing that are available, no computer user should be using the very dangerous standard mouse.<br /><br />Anyway, the mouse that I wholeheartedly recommend is the <a href="http://solutions.3m.com/wps/portal/3M/en_US/ergonomics/home/products/ergonomicmouse/">3M Ergonomic Optical Mouse</a>:<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhsE4DcN5JmOneq1LcrL1tq7fP8fc6XvGkAP0RW0Nf2b3mYiJAGj1iqtwZIeD4rUzfSb7azABv_sxEfWBm5qwrWc7DFddH-yREjqMqo03UVH5nMHJqBoWJhC_GBrCLzy9lSAD-VMQKxNorp/s1600-h/3m-mouse-2.jpg"><img style="cursor: pointer; width: 254px; height: 215px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhsE4DcN5JmOneq1LcrL1tq7fP8fc6XvGkAP0RW0Nf2b3mYiJAGj1iqtwZIeD4rUzfSb7azABv_sxEfWBm5qwrWc7DFddH-yREjqMqo03UVH5nMHJqBoWJhC_GBrCLzy9lSAD-VMQKxNorp/s400/3m-mouse-2.jpg" alt="" id="BLOGGER_PHOTO_ID_5282702106419552194" border="0" /></a><br /><br />It is definitely a strange looking mouse, but the strange shape is what makes it work so well. This mouse fixes two problems with traditional mice:<br /><br />1. Traditional mice force your arm to twist, causing your tendons to rub against each other, which causes inflammation and pain. By letting your arm sit in a much more natural arm-shaking position, the ergonomic mouse prevents this.<br /><br />2. When using traditional mice, your wrist, with all it's delicate parts, does all the moving. The ergonomic mouse, on the other hand, keeps the wrist straight and the arm becomes the moving part.<br /><br />So again, I highly recommend this mouse (or a pen tablet) to all computer users, and especially to programmers.<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTkVJ91fX-N_R1_ETznWlalt0n4A32w4xl9UU1f5FC_An7_iR_79FeOdv9Yp24P9NVludugJt6dlHq6krPr2pgFMXugR7UM4KnhdKtqnCYGq7vXWIi8B4XXEmfGKaWkkvUOG2voAm9rzY0/s1600-h/3m-mouse-1.jpg"><img style="cursor: pointer; width: 233px; height: 207px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTkVJ91fX-N_R1_ETznWlalt0n4A32w4xl9UU1f5FC_An7_iR_79FeOdv9Yp24P9NVludugJt6dlHq6krPr2pgFMXugR7UM4KnhdKtqnCYGq7vXWIi8B4XXEmfGKaWkkvUOG2voAm9rzY0/s400/3m-mouse-1.jpg" alt="" id="BLOGGER_PHOTO_ID_5282702102934317490" border="0" /></a><br /><br />(Note: Just in case anyone thinks I am advertising for 3M, no, I am not in any way sponsored by or affiliated with them.)Anonymoushttp://www.blogger.com/profile/04412171213630922945noreply@blogger.com2tag:blogger.com,1999:blog-1937539813134787961.post-20941885361731020892008-12-16T23:17:00.000+01:002008-12-16T23:17:26.945+01:00Industrial Strength Application Development in JavaScriptInspired by the work of <a href="http://javascript.crockford.com/">Douglas Crockford</a>, I have been developing a JavaScript application using full blown development techniques. JavaScript is definitely a misunderstood and underestimated programming language, and I have found it to be a pretty good hybrid of object-oriented and functional techniques. I have even done some cool things with it that would not be possible in a statically typed language. I have found that with proper unit testing and debugging tools, its dynamic typing has caused me few problems.<br /><br />So what tools can I recommend for industrial development in JavaScript? Everything below is an absolute must for my needs:<br /><br /><a href="http://jquery.com/"><span style="font-weight: bold;">jQuery</span></a><br /><ul><li>What it does: Ajax, DOM-modification, and general utility functions</li><li>As Jeff Atwood pointed out, there is <a href="http://www.codinghorror.com/blog/archives/001163.html">no good reason to write low-level JavaScript</a> to manipulate the DOM with today, now that there are tons of high quality JavaScript libraries to help out.<br /></li></ul><a style="font-weight: bold;" href="http://docs.jquery.com/QUnit">QUnit</a><br /><ul><li>What it does: Simple unit testing, compatible with jQuery<br /></li><li>I tried out a few other unit testing frameworks, but QUnit is the simplest one by far and just gets the job done.<br /></li></ul><a style="font-weight: bold;" href="http://www.javascriptlint.com/">JavaScript Lint</a><br /><ul><li>What it does: Identifies most textual errors in JavaScript files.</li><li>Indispensable tool to find that missing semicolon that is causing that weird error.</li><li>Note for TextMate users: Use the <a href="http://blog.macromates.com/2007/javascript-tools/">JavaScript Tools bundle</a> instead of downloading it from the official site.<br /></li></ul><a style="font-weight: bold;" href="https://addons.mozilla.org/en-US/firefox/addon/1843">Firebug</a><br /><ul><li>What it does: Firefox plugin. In addition to excellent DOM manipulation, it makes a great JavaScript debugger.<br /></li></ul>In Addition, <a href="https://developer.mozilla.org/En/Core_JavaScript_1.5_Reference">Mozilla's JavaScript Reference</a> is a must for any serious JavaScript developer.<br /><br />Well, I hope this gets you started. If you have any other suggestions, let me know!Anonymoushttp://www.blogger.com/profile/04412171213630922945noreply@blogger.com1tag:blogger.com,1999:blog-1937539813134787961.post-37762201576262987572008-12-02T20:45:00.000+01:002008-12-02T21:05:15.386+01:00Javascript's Undeclared versus UndefinedI learned the hard way that undeclared is different than undefined. If you try to test the simple way for an undeclared variable, you get an error, which in my environment means an annoying pop-up.<br /><pre class="code">/* var a; */ // undeclared<br />var b; // undefined<br /><br />// This would cause an 'object undefined' error<br />/*<br />if (a) {<br /> alert("a is defined");<br />}<br />else {<br /> alert("a is undefined");<br />}<br />*/<br /><br />if (typeof(a) == "undefined") {<br /> // this will be executed<br /> alert("a is undeclared or undefined");<br />}<br />else {<br /> alert("a is declared and defined");<br />}<br /><br />if (b) {<br /> alert("b is defined");<br />}<br />else {<br /> // this will be executed<br /> alert("b is undefined");<br />}<br /><br />if (typeof(b) == "undefined") {<br /> // this will be executed<br /> alert("b is undeclared or undefined");<br />}<br />else {<br /> alert("b is declared and defined");<br />}</pre>Anonymoushttp://www.blogger.com/profile/04412171213630922945noreply@blogger.com0tag:blogger.com,1999:blog-1937539813134787961.post-63577238638919955572008-11-24T18:53:00.001+01:002008-11-24T19:32:58.327+01:00Greasemonkey-ing with Gmail's StylesLast week, Google finally gave us some options to <a href="http://googlesystem.blogspot.com/2008/11/gmail-themes.html">customize the look of Gmail</a>. Excitedly, I went through each theme trying to find my replacement for the boring old "Classic" one. Many of them are graphically appealing, but unfortunately, most of them also have poor contrast compared to "Classic". I finally settled on the "Mountains" theme, but one thing still bugged me about it: the text color of mail titles were too light.<br /><br />Determined to fix this, I broke out <a href="http://getfirebug.com/">Firebug</a>, the trusty HTML/CSS inspection plugin for Firefox, and found the offending CSS:<br /><pre class="code">.AnqB9d {<br /> color:#3F586D;<br />}</pre>Then, I created this little <a href="https://addons.mozilla.org/en-US/firefox/addon/748">Greasemonkey</a> script:<br /><pre class="code">function addGlobalStyle(css) {<br /> var head, style;<br /> head = document.getElementsByTagName('head')[0];<br /> if (!head) { return; }<br /> style = document.createElement('style');<br /> style.type = 'text/css';<br /> style.innerHTML = css;<br /> head.appendChild(style);<br />}<br /><br />addGlobalStyle(<br /> '.AnqB9d {' +<br /> ' color: black ! important;' +<br /> '}'<br /> );</pre>Viola! Readable mailbox items! Check out before and after shots:<br /><br />Before:<br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi2E7XA2jCdViwGFec8ADWr3d8Bs5DDZaOoibEcTMMRnV6lDRIO5SI1EnAtqcJxM7WFO_ePSIQIvGpc5P_Pak5okWvbmtOFNaAS6FEwystNIO4VGRO9jg6fZvsDn6rsA6pYqoHoRAGx8cJh/s1600-h/gmail-mountains-bad.jpg"><img style="cursor: pointer; width: 400px; height: 97px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi2E7XA2jCdViwGFec8ADWr3d8Bs5DDZaOoibEcTMMRnV6lDRIO5SI1EnAtqcJxM7WFO_ePSIQIvGpc5P_Pak5okWvbmtOFNaAS6FEwystNIO4VGRO9jg6fZvsDn6rsA6pYqoHoRAGx8cJh/s400/gmail-mountains-bad.jpg" alt="" id="BLOGGER_PHOTO_ID_5272293487306955842" border="0" /></a><br /><br />After:<br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhJQycAQ76LHkq0OIiIOHl64LKMlfxI7-Vte99iTP1WY_YStPb2WuTp0MMtrBvrKZzxEEBk7dy3ZhWDexAxLDZGX9hx5qrIyABM2iIVjixBN_o4OJsvT9zorHWrRUA3qy8c0FMcAdZRkCpn/s1600-h/gmail-mountains-fixed.jpg"><img style="cursor: pointer; width: 400px; height: 97px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhJQycAQ76LHkq0OIiIOHl64LKMlfxI7-Vte99iTP1WY_YStPb2WuTp0MMtrBvrKZzxEEBk7dy3ZhWDexAxLDZGX9hx5qrIyABM2iIVjixBN_o4OJsvT9zorHWrRUA3qy8c0FMcAdZRkCpn/s400/gmail-mountains-fixed.jpg" alt="" id="BLOGGER_PHOTO_ID_5272293486966995154" border="0" /></a><br /><br />Related Links:<br /><ul><li><a href="http://www.newmediacampaigns.com/page/gmails-new-default-theme-is-a-step-backwards-for-usability">Joel Sutherland - Gmail's New Default Theme is a Step Backwards for Usability</a><br /></li></ul>Anonymoushttp://www.blogger.com/profile/04412171213630922945noreply@blogger.com2tag:blogger.com,1999:blog-1937539813134787961.post-47387264259385586952008-11-07T23:39:00.000+01:002008-11-07T23:55:49.954+01:00F# and Functional Language RespectI have been experimenting with Microsoft's <a href="http://en.wikipedia.org/wiki/F_Sharp_%28programming_language%29">F# language</a>, their version of ML / OCaml for the .NET Framework. Microsoft recently announced that F# will become an official part of Visual Studio, up there with C# and Visual Basic. I had never really used an ML-based language before, so I was not sure how big the learning curve would be, but I find that my knowledge of Haskell gets me far enough to feel comfortable writing simple programs after looking over the documentation for a few minutes. On top of that, the current pre-release version of F# has near perfect integration with Visual Studio, including an interactive REPL, debugging, and syntax completion. If you are in the market for a good functional language and are in the Microsoft developer ecosystem, F# seems like a great choice.<br /><br />I'm not sure how much I will use F# at work, if at all, but it is good to see that functional languages are being taken very seriously at Microsoft now. Not only are the developments of F# encouraging, but each new version of C# adds more functional features, and I find myself using those features daily in my work.<br /><br />Recommended Sites:<br /><ul><li><a href="http://msdn.microsoft.com/en-us/fsharp/default.aspx">Microsoft F# Development Center</a></li></ul>Anonymoushttp://www.blogger.com/profile/04412171213630922945noreply@blogger.com0tag:blogger.com,1999:blog-1937539813134787961.post-44573122808517678112008-10-30T06:41:00.000+01:002008-10-31T23:26:10.891+01:00Developing on iPhone and AndroidWhen the iPhone SDK came out early this year, I was one of the first to sign up for the beta program. I was excited by the possibility to develop on the platform and quickly started reading through the documentation and watching developer videos as I began development of what was to be my first iPhone app. Unfortunately, Apple put one too many roadblocks in place, making the iPhone an undesirable platform for me to work on:<br /><ol><li>Apple prevented all discussion of iPhone APIs by developers. I tried to ask a simple API question on an Apple developer board, and although a nice explanation why no one could answer me was sent to the board (see <a href="http://www.cocoabuilder.com/archive/message/cocoa/2008/3/23/202107">the mailing list archive</a>), I actually received obscene emails attacking me for having the audacity to break the SDK's non-disclosure agreement. The draconian NDA clause was removed a few weeks ago, but even then was long after the beta period was over.<br /><br /></li><li>Apple charged a fee just to get the developer kit working on an actual device, but then never gave many developers, including me, the unlocking codes to do so until long after the beta period ended.<br /><br /></li><li>Apple is still playing games with developers by occasionally pulling legitimate applications off the App Store.<br /></li></ol>In the end, I gave up and decided to work on <a href="http://code.google.com/android/">Google's Android</a> instead. First of all, Google got Android right by making the tools free and the restrictions few. Another nice benefit was the rich tools available to Android developers due to the Android SDK's use of Java (which has the added bonus of letting me use Scala for Android development!). So far, developing for the Android has been great-- straight-forward APIs, good tools, good documentation. Maybe someone got mobile OS development right.<br /><br />Related Links:<br /><ul><li><a href="http://www.nabble.com/-scala--mixed-scala-android-eclipse-project-works-td19726752.html#a19726752">Forum post on developing Android apps in Scala<br /></a></li><li><a href="http://www.scala-lang.org/node/160">Slightly outdated official documentation on Android apps in Scala</a></li></ul>Anonymoushttp://www.blogger.com/profile/04412171213630922945noreply@blogger.com1tag:blogger.com,1999:blog-1937539813134787961.post-16220933206060018242008-10-25T19:51:00.000+02:002008-10-27T21:56:49.514+01:00Bad CodeEvery programmer has experienced it. Code that is so bad, you have to share it with someone. Here are some recent gems I have encountered.<br /><br />Poor man's comments.<br /><pre class="code">If 1 = 0 Then<br />...<br />End If</pre>Is nameString empty?<br /><pre class="code">if (nameString + "x" != "x") {<br />...<br />}</pre>Hmm, is the comment wrong, or the code?<br /><pre class="code">// Comma-separated list of numbers<br />string configurationIds = "254:762:2:236:23:5:21";</pre>Anonymoushttp://www.blogger.com/profile/04412171213630922945noreply@blogger.com3tag:blogger.com,1999:blog-1937539813134787961.post-12062043389821439212008-10-20T18:51:00.000+02:002008-10-22T17:26:27.399+02:00JUnit Testing Scala in EclipseBeing a fairly new convert to agile development methods, including test driven development, I knew the first thing I would want to get up and running with Scala was a unit testing framework. The NetBeans plugin has built-in JUnit support which served me very well. But I also wanted to get some unit testing working with the Eclipse plugin. It took me a while to get JUnit testing setup with Eclipse, mainly due to my lack of experience in the Java ecosystem. To help future explorers down this path, here are a few lessons I learned.<br /><br /><span style="font-weight: bold;">Put the your tests in a separate source folder</span>. See this <a href="http://open.ncsu.edu/se/tutorials/junit/">tutorial on setting up JUnit in Eclipse</a> for more information.<br /><br /><span style="font-weight: bold;">Add JUnit to your project's build path</span>. Select the project and choose "Build Path" -> "Add Libraries...". Then choose the JUnit jar.<br /><br /><span style="font-weight: bold;">Add the output directory of your project to your build path</span>. See this <a href="http://code.google.com/p/specs/wiki/RunningSpecs#Run_your_specification_with_JUnit4_in_Eclipse">short guide from the makers of Spec</a>.<br /><br />To get you started, here is a simple test:<br /><pre class="code">package tests<br /><br />import junit.framework._<br />import org.junit.Assert._<br /><br />class FirstTest extends TestCase {<br /> override def setUp() = {<br /> }<br /><br /> override def tearDown() = {<br /> }<br /><br /> def testOne() = {<br /> assertEquals(1, 1)<br /> }<br />}</pre>Anonymoushttp://www.blogger.com/profile/04412171213630922945noreply@blogger.com2tag:blogger.com,1999:blog-1937539813134787961.post-43286052521918244442008-10-17T20:44:00.000+02:002008-10-18T01:03:03.468+02:00October's Bay Area Scala Enthusiasts Meetup, Part 2I promised some technical notes on the Bay Area Scala Enthusiasts meetup earlier this week, so here we go.<br /><br /><span style="font-weight: bold;">Coding Guidelines</span><br /><br />As I mentioned previously, the presentation by the Twitter folks focused on the informal guidelines they have been using internally for Scala coding (<a href="http://groups.google.com/group/scala-base/web/TwitterOct2008.pdf">PDF of their presentation</a>). I like their guidelines generally. Something that may be controversial in the guidelines is their policy not to use implicits. DSLs especially can make good use of implicits, so I would imagine that would have to be the exception to their rule. Maybe someone should take their coding guidelines as a starting point to make a coding guidelines page on the <a href="http://scala.sygneca.com/">Scala Wiki</a>?<br /><br /><span style="font-weight: bold;">Structural Types</span><br /><br />One of the topics mentioned at the meetup was structural types, which I hadn't used before, so I checked them out. Structural types seem to be a way to accomplish the same sort of "duck"-typing that you can do in Ruby and Python. Let's say you don't care about what the inheritance hierarchy of a parameter is, just that it can perform some operation. There are at least two ways to do this: traits or structural types.<br /><br />Using traits:<br /><pre class="code">trait Jumpable {<br /> def jump() : Unit { print("Jumping!") }<br />}<br /><br />class Bunny extends Jumpable { ... }<br />class PogoStick extends Jumpable { ... }<br /><br />class Controller {<br /> def makeThemJump(jumpers: List[Jumpable]) = {<br /> jumpers.foreach { jumper =><br /> jumper.jump()<br /> }<br /> }<br />}</pre>Using structural types:<br /><pre class="code">class Bunny { def jump(): Unit { print("Jumping!") } }<br />class PogoStick { def jump(): Unit { print("Jumping!") } }<br /><br />class Controller {<br /> def makeThemJump(jumpers: List[{ def jump(): Unit }]) = {<br /> jumpers.foreach { jumper =><br /> jumper.jump()<br /> }<br /> }<br />}</pre><span>The Twitter guys pointed out that it might be a good idea to avoid structural types due to their use of </span><span>reflection, which may be slow.</span><span style="font-weight: bold;"><br /><br />Dependency Injection</span><br /><br />How to use dependency injection (DI) with Scala was brought up. There was some argument on how applicable DI was in Scala, with developers coming from a Java background supporting it and those with a Ruby background questioning its relevance to Scala. Either way, this in depth <a href="http://jonasboner.com/2008/10/06/real-world-scala-dependency-injection-di/">article by Jonas Bonér</a> was brought up.<br /><br /><span style="font-weight: bold;">Development Environment</span><br /><br />There was a short discussion on what ide/editor people were using for Scala. The Twitter guys were using TextMate or Emacs, and a few people in the audience mentioned Eclipse and NetBeans. I am really curious what luck developers have had with the different environments. I am using NetBeans right now, but I am not completely happy with it. Can anyone make any recommendations?Anonymoushttp://www.blogger.com/profile/04412171213630922945noreply@blogger.com6