<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
 
 <title>Claus Witt</title>
 <link href="http://www.clauswitt.com/atom.xml" rel="self"/>
 <link href="http://www.clauswitt.com/"/>
 <updated>2012-02-20T00:16:37+01:00</updated>
 <id>http://www.clauswitt.com/</id>
 <author>
   <name>Claus Witt</name>
   <email>wittnezz@gmaik.com</email>
 </author>

 
 <entry>
   <title>Quick Local Branch Removal Script</title>
   <link href="http://www.clauswitt.com/Quick-Local-Branch-Removal-Script.html"/>
   <updated>2012-02-20T00:00:00+01:00</updated>
   <id>http://www.clauswitt.com/Quick-Local-Branch-Removal-Script</id>
   <content type="html">&lt;p&gt;A couple of weeks ago I wrote a post about a bash script I used to clean up remote branches. I have just created its brother (and have plans to combine them to one script at one point).&lt;/p&gt;

&lt;p&gt;In both scripts I check if the branch about to be removed is one i expect I want to keep. (In my cases master and live branches are off limits to deleting).&lt;/p&gt;

&lt;p&gt;As always the script is located as a gist on github. (Embedded here, to make it seem I have worked on this post for more than a couple of minutes.)&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/1866409.js&quot;&gt; &lt;/script&gt;


&lt;p&gt;If you have a better way to check for the branches, I would love to hear from you, since I find my &quot;solution&quot; too much of a hack.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>How to do a Regular Expression Search Replace with Case Shifting In TextMate</title>
   <link href="http://www.clauswitt.com/How-to-do-a-Regular-Expression-Search-Replace-with-Case-Shifting-In-TextMate.html"/>
   <updated>2012-02-07T00:00:00+01:00</updated>
   <id>http://www.clauswitt.com/How-to-do-a-Regular-Expression-Search-Replace-with-Case-Shifting-In-TextMate</id>
   <content type="html">&lt;p&gt;Recently I had to clone a lot of repositories from BitBucket into a FLOW3 installation. But since FLOW3 expects that packages are named with camelcase, and bitbucket insists on saving all names as lowercase, I need to set the name of the cloned repository manually (instead of just using the last part of the repo url).&lt;/p&gt;

&lt;p&gt;This is off course as easy as:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;git clone git@bitbucket.org:username/packagename.git PackageName
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;But since I am lazy, and like to have my software do most of my work, this is what I did.&lt;/p&gt;

&lt;p&gt;Locally I created a list of all packages in the FLOW3/Packages/Application directory (which should all be cloned on the remote server).&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;ls files.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Then opened the file list in TextMate, and ran the follow search/replace (as a regular expression)&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;#Search
(.*)\n
#Replace
git clone git@bitbucket.org:USERNAME/\L$1\E.git $1\n
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;\L lowercases everything until \E, between those I just pass the directoryname, which is also the name of the repo.&lt;/p&gt;

&lt;p&gt;Finally I pasted the lines to the console on the remote server, and presto! All repos were cloned with the correct naming.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>JavaScript Module with Global Scope Removal</title>
   <link href="http://www.clauswitt.com/JavaScript-Module-with-Global-Scope-Removal.html"/>
   <updated>2012-01-26T00:00:00+01:00</updated>
   <id>http://www.clauswitt.com/JavaScript-Module-with-Global-Scope-Removal</id>
   <content type="html">&lt;p&gt;Even though I regularly rant about not including jQuery as a default, without ensuring that you actually need it, I have done so myself. However I have done it in a special way (at the time of writing, this is only a proof of concept, and not really used for anything...)&lt;/p&gt;

&lt;p&gt;I have a global scope module called &quot;clauswitt&quot;, that gets session.js and jQuery added through parameters to the module pattern. This module then removes session.js and jQuery from the global scope, thus making the jQuery code visible only from inside the module, and not callable from the outside.&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/1684302.js&quot;&gt; &lt;/script&gt;


&lt;h2&gt;UPDATE:&lt;/h2&gt;

&lt;p&gt;As &lt;a href=&quot;https://twitter.com/#!/andrewcobby&quot;&gt;Andrew Cobby&lt;/a&gt; pointed out in the comments (see below), you do not need to check if a global variable exists, before deleting it.&lt;/p&gt;

&lt;p&gt;And just to clarify - this may not have a valid use case. The reason I created this, was because I got a question about wether it was possible, and how. (A friend of mine had a colleague who always created inline eventhandlers, using jQuery dollar notation directly in the onclick attribute of a button, for instance. This code forces him to - at least - create the code within the scope where jQuery is available).&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Removing Unused git branches Automatically</title>
   <link href="http://www.clauswitt.com/Removing-Unused-git-branches-Automatically.html"/>
   <updated>2012-01-23T00:00:00+01:00</updated>
   <id>http://www.clauswitt.com/Removing-Unused-git-branches-Automatically</id>
   <content type="html">&lt;p&gt;At work, our git workflow forces every issue in jira to be created in a new tracking branch. The naming convention then makes sure that the release manager can identify issue and code, and their relation.&lt;/p&gt;

&lt;p&gt;However this means that either the release manager needs to remove unused tracking branches, or the branche count on our remote repo goes through the roof. Until now, it has been a chore that has been postponed, until today.&lt;/p&gt;

&lt;p&gt;My colleague &lt;a href=&quot;http://jesperrasmussen.com/&quot;&gt;Jesper Rasmussen&lt;/a&gt; created an issue in Jira today about creating an automatizeable process to remove unused tracking branches. I jumped on the idea as soon as I saw it, since it has been bothering me for some time.&lt;/p&gt;

&lt;p&gt;Google, git and bash to the rescue.&lt;/p&gt;

&lt;p&gt;My idea was to create a bash script, make it list all tracking branches which is already merged to master, and then go through that list, and remove all the tracking branches.&lt;/p&gt;

&lt;p&gt;The resulting script looks like this&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/1662029.js&quot;&gt; &lt;/script&gt;


&lt;p&gt;I have a alias for the script and can call it from any git repo I have with cleanupBranches&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>How to Easily Remove a Prefix from 1800+ Files</title>
   <link href="http://www.clauswitt.com/How-to-Easily-Remove-a-Prefix-from-1800plus-Files.html"/>
   <updated>2012-01-22T00:00:00+01:00</updated>
   <id>http://www.clauswitt.com/How-to-Easily-Remove-a-Prefix-from-1800plus-Files</id>
   <content type="html">&lt;p&gt;Today I had an easy job of renaming 1800+ wave files which by my own fault had been uploaded to cloud storage with a prefix of 5 digits and an underscore before the correct filename. And since the filename maps directly to a matching objects id in a database, it was imperative that they be renamed, and fast.&lt;/p&gt;

&lt;p&gt;I am - as you may know - not one for manuable labour when it can be automatized. So once again I found myself with a simple shell script in bash/zsh&lt;/p&gt;

&lt;p&gt;It uses a simple sed regex, with a backreference to the final part of the file name.&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/1658777.js&quot;&gt; &lt;/script&gt;



</content>
 </entry>
 
 <entry>
   <title>Simple node.js Module to Get Distance Between two coordinates</title>
   <link href="http://www.clauswitt.com/Simple-node.js-Module-to-Get-Distance-Between-two-coordinates.html"/>
   <updated>2012-01-13T00:00:00+01:00</updated>
   <id>http://www.clauswitt.com/Simple-node.js-Module-to-Get-Distance-Between-two-coordinates</id>
   <content type="html">&lt;p&gt;In one of our latest projects at work, we need to calculate two world coordinates. Instead of going into details about how the calculations is made, I will just refer to &lt;a href=&quot;http://www.movable-type.co.uk/scripts/latlong.html&quot;&gt;this page&lt;/a&gt;. This explains all details of math involved in getting distances and/or bearings from lat/long pairs.&lt;/p&gt;

&lt;p&gt;I have implemented this calculation in several languages in the last couple of months - both for work, but also for learning details about a language through implementing a known algorithm in it.&lt;/p&gt;

&lt;p&gt;Here is a simple nodejs module extracted from the javascript code on that page. The module has one public method called getDistance.&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/1604972.js&quot;&gt; &lt;/script&gt;


&lt;p&gt;My changes are released licensed under the &lt;a href=&quot;http://en.wikipedia.org/wiki/WTFPL&quot;&gt;WTFPL&lt;/a&gt;&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>A zsh function to Add Last Parameter of Last Command to git</title>
   <link href="http://www.clauswitt.com/A-zsh-function-to-Add-Last-Parameter-of-Last-Command-to-git.html"/>
   <updated>2012-01-09T00:00:00+01:00</updated>
   <id>http://www.clauswitt.com/A-zsh-function-to-Add-Last-Parameter-of-Last-Command-to-git</id>
   <content type="html">&lt;p&gt;My git worflow often has me changing several files, and testing the changes before I commit anything to any of the files. I find the easiest way to do a commit per file is to ensure that I review the code of each file just before I commit. That way I can also ensure that the commit message is just a bit accurate, as I make no assumptions to what the change was before commiting. (Admit it, it has happened to you too!).&lt;/p&gt;

&lt;p&gt;Lazy as I am however, I was tired of writing pretty much the same command twice, or going back in history and changing diff to add before my commit.&lt;/p&gt;

&lt;pre&gt;
git diff Some/Path/To/File.ext
git add Some/Path/To/File.ext
git commit -m &quot;Commit message here&quot;
&lt;/pre&gt;


&lt;p&gt;(Yes, I know I can specify the file in the commit directly, for some reason - I never have). I created a minor zsh function to take the last parameter of the last command, and adding that parameter to the git add command.&lt;/p&gt;

&lt;pre&gt;
gd Some/Path/To/File.ext
gal
c -m &quot;Commit message here&quot;
&lt;/pre&gt;




&lt;script src=&quot;https://gist.github.com/1582827.js&quot;&gt; &lt;/script&gt;



</content>
 </entry>
 
 <entry>
   <title>A Simple Create New Blogpost Script</title>
   <link href="http://www.clauswitt.com/A-Simple-Create-New-Blogpost-Script.html"/>
   <updated>2012-01-07T00:00:00+01:00</updated>
   <id>http://www.clauswitt.com/A-Simple-Create-New-Blogpost-Script</id>
   <content type="html">&lt;p&gt;As I wrote yesterday I just &lt;a href=&quot;/the-how-and-why-of-my-move-to-jekyll.html&quot;&gt;changed my blog platform from Wordpress to Jekyll&lt;/a&gt;. Today I have created some minor tweaks in my setup to allow me to easier create a post, and deploy the blog live. Now I call a simple command in the terminal, with the blog post name as a parameter, and the file is created in the correct place, and opened in TextMate.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/terminal-new-blog-post.png?1&quot; /&gt;&lt;/p&gt;

&lt;p&gt;And this is how that looks in textmate:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/textmate-new-blog-post.png?1&quot; /&gt;&lt;/p&gt;

&lt;p&gt;I did a quick search on google - figuring someone else had solved this problem before me - and found &lt;a href=&quot;http://minhajuddin.com/2010/10/01/helper-script-to-create-new-posts-using-jekyll/&quot;&gt;this post&lt;/a&gt; which was (mostly) what I needed. I have done two minor tweaks to my forked version of the gist he links to.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Changed the template file to _template.markdown&lt;/li&gt;
&lt;li&gt;Instead of outputting the filename, open it in textmat&lt;/li&gt;
&lt;/ul&gt;


&lt;script src=&quot;https://gist.github.com/1574298.js&quot;&gt; &lt;/script&gt;


&lt;p&gt;Then I created two small zsh functions to ensure that I can start a blogpost (and deploy my blog) from any directory on my machine.&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/1574360.js&quot;&gt; &lt;/script&gt;


&lt;p&gt;And finally I fixed a minor thing, where my ruby scripts and, the deploy.sh file was deployed to the website. The following line was added to _config.yml&lt;/p&gt;

&lt;pre&gt;
exclude: deploy.sh new.rb _template.markdown
&lt;/pre&gt;


&lt;p&gt;The last entry in that file is actually redundant. The reason I changed template.markdown to _template.markdown was actually that it rendered a file on the website called template.html which was empty - the fix to change the name could not be used for the script files (well, it could, but I did not want to do that).&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>The How and Why of my Move to Jekyll</title>
   <link href="http://www.clauswitt.com/the-how-and-why-of-my-move-to-jekyll.html"/>
   <updated>2012-01-06T20:45:00+01:00</updated>
   <id>http://www.clauswitt.com/the-how-and-why-of-my-move-to-jekyll</id>
   <content type="html">&lt;p&gt;Today I decided to move my blog from &lt;a href=&quot;http://www.wordpress.org&quot;&gt;Wordpress&lt;/a&gt; to static html files. These files are generated via &lt;a href=&quot;https://github.com/mojombo/jekyll&quot;&gt;Jekyll&lt;/a&gt;. The first version of this new blog, contains (most) blog posts from the wordpress installation. The included &lt;a href=&quot;https://github.com/mojombo/jekyll/wiki/blog-migrations&quot;&gt;migration script&lt;/a&gt; in the jekyll package was used to move all posts to markdown format. All absolute urls to images was changed to relative urls, and all [gist]-shortcodes was changed (via a simple regular expression search and replace in Textmate2) to the standard script-include.&lt;/p&gt;

&lt;pre&gt;
Search: \[gist id=([0-9]*)\]
Replace: script tag with the src: https://gist.github.com/$1.js
&lt;/pre&gt;


&lt;p&gt;I have had this move planned for some time actually. I was tired of the constant surveilance and updating of wordpress (and plugins). And I was tired of the tedious creation and editing of posts. Now, whenever I want to create a new post, I just create a new &lt;a href=&quot;http://daringfireball.net/projects/markdown/&quot;&gt;markdown-file&lt;/a&gt; in the _posts folder - all content are also stored in a git-repo instead of in databases. All unnecessary software has been removed from my blog - and only a simple &lt;a href=&quot;http://nginx.org/&quot;&gt;nginx&lt;/a&gt; server is used for serving the content. The downsides are simply outweighed by the upsides.&lt;/p&gt;

&lt;p&gt;I use a simple two (three if you count the &lt;a href=&quot;http://en.wikipedia.org/wiki/Shebang_(Unix)&quot;&gt;shebang&lt;/a&gt; line shell script to upload the changes to my blog.&lt;/p&gt;

&lt;pre&gt;
#! /bin/bash
jekyll
rsync -avz --delete _site/ user@domain.tld:/var/www/rootDir/
&lt;/pre&gt;


&lt;p&gt;The complete installation of Jekyll, move from wordpress and first deploy took me less than one hour. And I love it already. I may need to do some design work at some point though.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Per Package Unit Testing in FLOW3 using PhpStorm</title>
   <link href="http://www.clauswitt.com/per-package-unit-testing-in-flow3-using-phpstorm.html"/>
   <updated>2011-11-24T08:37:09+01:00</updated>
   <id>http://www.clauswitt.com/per-package-unit-testing-in-flow3-using-phpstorm</id>
   <content type="html">&lt;h2&gt;UPDATE&lt;/h2&gt;


&lt;p&gt;Do not do this! &lt;a href=&quot;http://clauswitt.com/per-package-unit-testing-in-flow3-using-phpstorm.html#comment-425500463&quot;&gt;Check Karstens comment why&lt;/a&gt; - and go to &lt;a href=&quot;http://blog.k-fish.de/2011/02/unit-testing-flow3-with-phpstorm.html&quot;&gt;his blog post about setting this up correctly&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Everything below this, line is not useful for anything (except perhaps learning that you should not try to create a fix for a problem that does not exist.)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Update:&lt;/strong&gt; you may add you pear directory as a directory in the project, to ensure that you get them indexed (and get autocomplete on for instance ). On my mac, the pear package is located in /usr/local/share/pear - find where yours is by running:&lt;/p&gt;

&lt;pre&gt;
pear config-show |grep &quot;PEAR directory&quot;
&lt;/pre&gt;


&lt;p&gt;At &lt;a href=&quot;http://www.arnsbomedia.com/&quot;&gt;Arnsbo Media&lt;/a&gt; we don't do unit testing on everything. Whereas for some projects (mostly containing models, views and controllers) we feel unit testing [and tdd in generel] is overkill - other projects (or some modules/packages) are prime candidates for tdd. Typically when we are creating service integration we do it test driven. My own definition is that when all users of a given package/module are other packages/modules - and not databases, webservers, end users and so forth - unit testing is a viable way to ensure longevity of the APIs, and solidity of the implementation.&lt;/p&gt;

&lt;p&gt;At the moment we are doing several parts of a very big system in &lt;a href=&quot;http://flow3.typo3.org/&quot;&gt;FLOW3&lt;/a&gt;. Each part is an independent package, and most of them are service layers, and/or abstractions of external systems. Each of these packages should be testable without depending on other packages (apart from the ones required by flow3). Thus we use FLOW3s built-in test framework (based on phpunit), but we have placed our own configuration and bootstrap for testing a package as part of the package.&lt;/p&gt;

&lt;p&gt;It makes several assumptions however:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The package is placed in the directory FLOW3/Packages/Application&lt;/li&gt;
&lt;li&gt;The FLOW3 packages are placed in FLOW3/Packages/Framework&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/sebastianbergmann/phpunit/&quot;&gt;Phpunit&lt;/a&gt; is installed&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/mikey179/vfsStream/wiki/Install&quot;&gt;VfsStream&lt;/a&gt; is installed&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;The layout of the package is pretty standard.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/ScreenShot.png?1&quot; alt=&quot;Package contents&quot; title=&quot;ScreenShot.png&quot; border=&quot;0&quot; width=&quot;410&quot; height=&quot;348&quot; /&gt;&lt;/p&gt;

&lt;p&gt;We have created a Build/PhpUnit directory in which we place the configuration file, and the bootstrap for the package. These files a copy-paste-able to any package. The content of both are copied from the framework supplied files in FLOW3/Build/Common/PhpUnit - and tailored to be used from the packages directory. For both files the only thing changed is how to resolve the directories from the current file. Otherwise everything is left as is.&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/1390828.js&quot;&gt; &lt;/script&gt;




&lt;script src=&quot;https://gist.github.com/1390830.js&quot;&gt; &lt;/script&gt;


&lt;p&gt;After this all you have to do is setup a Run Configuration for PhpStorm.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/Screen-Shot-2011-11-24-at-08.28.54-.png?1&quot; alt=&quot;Screen Shot 2011 11 24 at 08 28 54&quot; title=&quot;Screen Shot 2011-11-24 at 08.28.54 .png&quot; border=&quot;0&quot; width=&quot;198&quot; height=&quot;288&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/Screen-Shot-2011-11-24-at-08.29.48-.png?1&quot; alt=&quot;Screen Shot 2011 11 24 at 08 29 48&quot; title=&quot;Screen Shot 2011-11-24 at 08.29.48 .png&quot; border=&quot;0&quot; width=&quot;380&quot; height=&quot;101&quot; /&gt;&lt;/p&gt;

&lt;p&gt;All tests are placed in the Tests/Unit directory, and as a rule of thumb I place them in a matching subdirectory to where the class being tested is under the Classes directory, and name it by appending Test to the class- (and subsequently the file-) name. In this case we have a single GoogleHandler class, and a test for it.&lt;/p&gt;

&lt;p&gt;Finally all you have to do is run the app using the phpunit run configuration, and you test results are ready for you.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>A Simple ViewHelper For FLOW3</title>
   <link href="http://www.clauswitt.com/a-simple-viewhelper-for-flow3.html"/>
   <updated>2011-11-15T14:56:22+01:00</updated>
   <id>http://www.clauswitt.com/a-simple-viewhelper-for-flow3</id>
   <content type="html">&lt;p&gt;For some time now I have wanted to use FLOW3 for work-projects. However it was not until it recently got out of the alpha/beta cycle that we decided to use it for a critical project.&lt;/p&gt;

&lt;p&gt;Mostly for fun, I just now finished a simple viewhelper which is a very simple version of the &lt;a href=&quot;http://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html#method-i-distance_of_time_in_words&quot;&gt;rails method distance_of_time_in_words&lt;/a&gt;. My viewhelper is much simpler than this, and were created in less than twenty minutes. I might however implement the Rails conventions since I quite like them.&lt;/p&gt;

&lt;p&gt;As always I have created a gist where you can find the code for it:&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/1367106.js&quot;&gt; &lt;/script&gt;


&lt;p&gt;The usage is as simple as all other FLOW3 view helpers. First include the namespace, and then call the viewhelper by name. Call it with either a DateTime object, or a string which it's constructor accepts, otherwise an exception will be thrown.&lt;/p&gt;

&lt;pre&gt;
{namespace c=ClausWitt\ViewHelpers}
&amp;lt;c:ago date=&quot;2011-11-15T18:15:44+01:00&quot;&amp;gt;&amp;lt;/c:ago&amp;gt;
&lt;/pre&gt;


&lt;p&gt;At the time of writing, the above outputtet: &quot;3 hours from now&quot;.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>A Simple Promises AMD Module</title>
   <link href="http://www.clauswitt.com/a-simple-promises-amd-module.html"/>
   <updated>2011-11-14T08:56:31+01:00</updated>
   <id>http://www.clauswitt.com/a-simple-promises-amd-module</id>
   <content type="html">&lt;p&gt;A week or so ago I wrote a post about &lt;a href=&quot;http://www.clauswitt.com/unique-filename-generator-amd-module/&quot;&gt;a simple AMD module&lt;/a&gt; I had created. Now I have created one more, this time a little more complex. While the latter was for a secret project, this one is (apart from also being for that project) also a part of my upcoming talk on Scaling Javascript at the &lt;a href=&quot;https://www.facebook.com/event.php?eid=171521292931689&quot;&gt;Aarhus Frontend Meetup&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This code is a very simple implementation of a Promise. It is in no way a full implementation of how futures/promises should work in javascript, there are many great implementations of that out there. This is however a simple working module, that I use for doing simple promise like calls when I need a callback when some long-running function has ended and returned.&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/1363471.js&quot;&gt; &lt;/script&gt;


&lt;p&gt;I have also written a simple test of the functionality in the module. Both the module and the test has been tested with RequireJs only. This test should first show you an alert with the text &quot;Test began&quot;, followed by a pause of one second, and then show an alert with the text &quot;test complete&quot;.&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/1363479.js&quot;&gt;&lt;/script&gt;


&lt;p&gt; &lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Unique Filename Generator AMD Module</title>
   <link href="http://www.clauswitt.com/unique-filename-generator-amd-module.html"/>
   <updated>2011-11-01T21:38:21+01:00</updated>
   <id>http://www.clauswitt.com/unique-filename-generator-amd-module</id>
   <content type="html">&lt;p&gt;I have recently begun to work a lot with AMD modules. I usually use RequireJS to load the modules - since this works both in the browser and in node. I am currently working - privately - on some exciting minor projects, in which it is possible to share modules. The most general of these will be published here, and the first one is allready here.&lt;/p&gt;

&lt;p&gt;It is a very simple module, which has one purpose. To generate filenames which will be unique in an otherwise empty (temporary) directory. It does this by using the date objects getTime method - to get the unix epoch (in milliseconds), and then if it is called two times within the same millisecond, it will append &lt;em&gt;1, &lt;/em&gt;2 .. _n to the name. It has an optional parameter to set the file extension.&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/1331802.js&quot;&gt; &lt;/script&gt;


&lt;p&gt;The usage is very simple.&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/1331826.js&quot;&gt; &lt;/script&gt;

</content>
 </entry>
 
 <entry>
   <title>Even Simpler Stats in Javascript</title>
   <link href="http://www.clauswitt.com/even-simpler-stats-in-javascript.html"/>
   <updated>2011-10-19T10:01:52+02:00</updated>
   <id>http://www.clauswitt.com/even-simpler-stats-in-javascript</id>
   <content type="html">&lt;p&gt;Last week I wrote about &lt;a href=&quot;http://www.clauswitt.com/simple-statistics-in-javascript/&quot;&gt;simple statistics in javascript&lt;/a&gt;. However it turned out I needed something else. First of all, the only values I needed was the mean (arithmetic mean) and the standard deviation - but I needed these values from a large set of large numbers. However this turned out to be a problem, because the sum of all these numbers could possibly be greater than the largest number representable by javascript.&lt;/p&gt;

&lt;p&gt;The solution was to make these values available as running calculations. Each time you add an element, the mean and standard deviation is calculated from the existing values, set size and the new value. This means for large sets, this code will use much less memory.&lt;/p&gt;

&lt;p&gt;Like last time, the complete source is embedded from a gist at github.com&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/1297704.js&quot;&gt; &lt;/script&gt;


&lt;p&gt;To check the values - I have tested with the same values as last time:&lt;/p&gt;

&lt;pre&gt;
var stat = SimpleStats([12, 13, 15, 18, 19, 4, 59, 100, 6, 129, 83, 5]);
console.log(stat.getArithmeticMean()); //38.583333333333336
console.log(stat.getStandardDeviation()); //41.27844137346058
&lt;/pre&gt;


&lt;p&gt;However now you should also be able to add a number to the set, and have the new values instantly available to you:&lt;/p&gt;

&lt;pre&gt;
stat.addValues([1,2,3,4,5,6,7]);
console.log(stat.getArithmeticMean()); //25.842105263157894
console.log(stat.getStandardDeviation()); //36.82285211214811
&lt;/pre&gt;

</content>
 </entry>
 
 <entry>
   <title>Aarhus JS Status</title>
   <link href="http://www.clauswitt.com/aarhus-js-status.html"/>
   <updated>2011-10-17T12:30:09+02:00</updated>
   <id>http://www.clauswitt.com/aarhus-js-status</id>
   <content type="html">&lt;p&gt;On Sep 13 I sent out a survey to a network of developers, to find out wether or not to start some meetups and maybe working toward making a conference related to Javascript in Aarhus. The answers were very encouraging. I have decided to wait a little with the plans for a &quot;real&quot; conference, and instead work on the meetups. This way we can get a group of dedicated people before we try to make something crazy like creating a conference from scratch.&lt;/p&gt;

&lt;p&gt;Some of the interesting answers from the survey were the following: &lt;br /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/attend-meetup.png?1&quot; alt=&quot;Attend meetup&quot; title=&quot;attend-meetup.png&quot; border=&quot;0&quot; width=&quot;500&quot; height=&quot;133&quot; /&gt;&lt;/p&gt;

&lt;br /&gt;


&lt;br /&gt;


&lt;p&gt;&lt;img src=&quot;/images/host-meetup.png?1&quot; alt=&quot;Host meetup&quot; title=&quot;host-meetup.png&quot; border=&quot;0&quot; width=&quot;500&quot; height=&quot;128&quot; /&gt;&lt;/p&gt;

&lt;br /&gt;


&lt;br /&gt;


&lt;p&gt;&lt;img src=&quot;/images/howoften-meetup.png?1&quot; alt=&quot;Howoften meetup&quot; title=&quot;howoften-meetup.png&quot; border=&quot;0&quot; width=&quot;500&quot; height=&quot;235&quot; /&gt;&lt;/p&gt;

&lt;br /&gt;


&lt;br /&gt;


&lt;p&gt;&lt;img src=&quot;/images/speak-meetup.png?1&quot; alt=&quot;Speak meetup&quot; title=&quot;speak-meetup.png&quot; border=&quot;0&quot; width=&quot;500&quot; height=&quot;133&quot; /&gt;&lt;/p&gt;

&lt;br /&gt;


&lt;br /&gt;


&lt;p&gt;In the mean time &lt;a href=&quot;http://www.webdanmark.com/&quot;&gt;Webdanmark&lt;/a&gt; decided to host a &lt;a href=&quot;https://www.facebook.com/event.php?eid=171521292931689&quot;&gt;frontend-meetup&lt;/a&gt;, which I am attending as well. Hopefully we can help eachother, since js (still) is used primarily for front-end development.&lt;/p&gt;

&lt;p&gt;In the near future we will host a Javascript Meetup - probably in the beginning of December. Join &lt;a href=&quot;https://www.facebook.com/groups/229536940433870/&quot;&gt;our group on Facebook&lt;/a&gt; to get information as soon as they are released. On this meetup I will also launch the blog of Aarhusjs.com - on which I hope we can gather blogposts, event invitations, all talks (slides, and hopefully video at some point), and other relevant stuff to the Aarhus javascript community.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Fixing Slow DNS Queries in OS X Lion</title>
   <link href="http://www.clauswitt.com/fixing-slow-dns-queries-in-os-x-lion.html"/>
   <updated>2011-10-14T21:54:59+02:00</updated>
   <id>http://www.clauswitt.com/fixing-slow-dns-queries-in-os-x-lion</id>
   <content type="html">&lt;p&gt;This post is a bit embarrasing. For a long time (from Lion got released, and until a moment ago) I thought that my hosts-file problem in Lion was unsolvable and that it was the fault of Apple.&lt;/p&gt;

&lt;p&gt;The issue I had was that when developing on my local machine (PHP 5.3 in Apache), all requests to the webserver were painfully slow. The reason was that all dns queries for my development domains (all ending with .local) went to a remote dns server, before failing, and falling back to the entry from the /etc/hosts file.&lt;/p&gt;

&lt;p&gt;Apparently it is because OS X Lion is running IPv6, and thus since my hosts file only contained IPv4 addresses, Lion decided to look up if a IPv6 entry was at the dns server, before falling back to checking the IPv4 in the hosts file.&lt;/p&gt;

&lt;h2&gt;First fix your hosts file&lt;/h2&gt;


&lt;p&gt;In your hosts file, you need to provide both IPv4 and IPv6 address for each domain you need to develop on.&lt;/p&gt;

&lt;pre&gt;
127.0.0.1 flow3.local #This was the old line
fe80::1%lo0 flow3.local #This needs to be added as well. 
&lt;/pre&gt;




&lt;h2&gt;Second fix your apache configuration&lt;/h2&gt;


&lt;p&gt;If you previously had your apache virtual hosts ip based, you need to have them only port based.&lt;/p&gt;

&lt;pre&gt;
#Before
NameVirtualHost 127.0.0.1:80

#After
NameVirtualHost *:80

#Before
&amp;lt;VirtualHost 127.0.0.1:80&amp;gt;

#After
&amp;lt;VirtualHost *:80&amp;gt;
&lt;/pre&gt;


&lt;p&gt;Page load times went from 2-3 seconds, to almost instantly.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Simple Statistics in JavaScript</title>
   <link href="http://www.clauswitt.com/simple-statistics-in-javascript.html"/>
   <updated>2011-10-13T23:05:32+02:00</updated>
   <id>http://www.clauswitt.com/simple-statistics-in-javascript</id>
   <content type="html">&lt;p&gt;I love tinkering with javascript, and working out solutions to simple little problems. Recently I had a simple statistical program in mind, that should be able to run in the browser. However while thinking about the idea, I wondered if there were any statistical functions in js allready available. Most like for instance &lt;a href=&quot;http://www.jstat.org/&quot;&gt;jStat&lt;/a&gt; were completely overkill. I just needed mean, harmonic mean, geometric mean, standard deviation and median for a simple array of values.&lt;/p&gt;

&lt;p&gt;I decided to write up a simple little &quot;class&quot; for that myself.&lt;/p&gt;

&lt;p&gt;The code should pretty much speak for itself, and all functions have a comment with a link to the description of what it is on Wikipedia.&lt;/p&gt;

&lt;p&gt;The complete source of the Stats.js file is embedded here. (Or go to &lt;a href=&quot;https://gist.github.com/1285478&quot;&gt;gist.github.com&lt;/a&gt; to fork it).&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/1285478.js&quot;&gt; &lt;/script&gt;


&lt;p&gt;The package can be used like so:&lt;/p&gt;

&lt;pre&gt;
var stat = Stats([12, 13, 15, 18, 19, 4, 59, 100, 6, 129, 83, 5]);
console.log(stat.getArithmeticMean()); //38.583333333333336
console.log(stat.getGeometricMean()); //20.66546833393584
console.log(stat.getHarmonicMean()); //12.017712168189883
console.log(stat.getStandardDeviation()); //41.27844137346058
console.log(stat.getMedian()); //18
&lt;/pre&gt;

</content>
 </entry>
 
 <entry>
   <title>Moving a Subdirectory to a Submodule in Git</title>
   <link href="http://www.clauswitt.com/moving-a-subdirectory-to-a-submodule-in-git.html"/>
   <updated>2011-09-20T10:57:18+02:00</updated>
   <id>http://www.clauswitt.com/moving-a-subdirectory-to-a-submodule-in-git</id>
   <content type="html">&lt;p&gt;Sometimes when you work on a project long enough, you find that for one reason or the other, parts of the project should be in a separate repository. Either the subdir contains reusable code, to be used on another project, or - as it was in our case today - some part of the project, was needed on many servers, and the rest only on one. We decided to create a separate module to ensure that we did not clone the entire projects for these servers.&lt;/p&gt;

&lt;p&gt;There are two steps to this procedure. 1. Get the subdir - with the complete git history into a new repo, and 2. get the new repo in to the old project as a submodule.&lt;/p&gt;

&lt;p&gt;This is how you move &quot;Application/scripts/shell&quot; from OldProject into its own repo called NewProject. And then link it as a submodule at the same location it were before.&lt;/p&gt;

&lt;h2&gt;Subdir to another repo&lt;/h2&gt;


&lt;pre&gt;
git clone --no-hardlinks OldProject NewProject
cd NewProject
git filter-branch --subdirectory-filter Application/scripts/shell HEAD
git reset --hard
rm -rf .git/refs/original/
git reflog expire --expire=now --all
git gc --aggressive --prune=now
&lt;/pre&gt;


&lt;p&gt;Next you need to set the remote (in our case origin) to the new repo's remote.&lt;/p&gt;

&lt;h2&gt;Create submodule&lt;/h2&gt;


&lt;p&gt;Back in the old project, remove the part you have extracted, and commit. Then run the following commands.&lt;/p&gt;

&lt;pre&gt;
git submodule add git@your.git.host:NewProject.git Application/scripts/shell
-- commit -- 
git submodule init
git submodule update 
-- commit again -- 
&lt;/pre&gt;


&lt;p&gt;You should now have you former subdirectory as a separate repository, at the same location.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Project Euler Problem Nine</title>
   <link href="http://www.clauswitt.com/project-euler-problem-nine.html"/>
   <updated>2011-07-13T07:00:14+02:00</updated>
   <id>http://www.clauswitt.com/project-euler-problem-nine</id>
   <content type="html">&lt;p&gt;The ninth Euler Problem is currently the one I have solved with the fewest lines of code. The problem is to find the product of the (only) pythagorean triplet for which the sum of the three numbers is 1000. Look at the &lt;a href=&quot;http://projecteuler.net/index.php?section=problems&amp;id=9&quot;&gt;problem description&lt;/a&gt; to learn what a pythagorean triplet is.&lt;/p&gt;

&lt;p&gt;The code to solve this is again a simple iteration (within an iteration). The solution is written in thirteen lines of code - five of which are closing braces.&lt;/p&gt;

&lt;p&gt;For every a and b combination c is calculated. If c is an integer, it is checked wether a+b+c equals 1000. If it does, the routine returns the product.&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/1063783.js&quot;&gt; &lt;/script&gt;


&lt;p&gt;run with nodejs.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Click to split text in the browser</title>
   <link href="http://www.clauswitt.com/click-to-split-text-in-the-browser.html"/>
   <updated>2011-07-11T07:00:10+02:00</updated>
   <id>http://www.clauswitt.com/click-to-split-text-in-the-browser</id>
   <content type="html">&lt;p&gt;Recently I had to implement a feature - running in chrome, safari and firefox - that enabled users to click in a text to split the text into two paragraphs. At first the solution eluded me, however a morning while entertaining my son before going on road trip to my wires parents house, a possible solution popped into my head. Fortunately my son let me try it - and it worked!&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/1063805.js&quot;&gt; &lt;/script&gt;


&lt;p&gt;The whole trick is to let the click event call a method that uses document.caretRangeFromPoint() (for WebKit browsers) and document.createRange() for Firefox to create a range from the clicked point, and then using the start of that range - range.startOffset as the point in the text to split. All text before the point is kept in the current paragraph, all text after the point is used for the newly created paragraph after the clicked one.&lt;/p&gt;

&lt;p&gt;I have created a &lt;a href=&quot;http://demo.clauswitt.com/testClickToSplit.html&quot;&gt;quick and dirty demo&lt;/a&gt; - only working (tested) in (the latest versions of) Safari, Chrome and Firefox.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Project Euler Problem Eight</title>
   <link href="http://www.clauswitt.com/project-euler-problem-eight.html"/>
   <updated>2011-07-09T07:00:45+02:00</updated>
   <id>http://www.clauswitt.com/project-euler-problem-eight</id>
   <content type="html">&lt;p&gt;The eighth problem of Project Euler is very simple. &lt;a href=&quot;http://projecteuler.net/index.php?section=problems&amp;id=8&quot;&gt;Find the greatest product of five consecutive digits in the 1000-digit number&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The problem at first however has a bit of a twist. You cannot represent that large a number as an integer in javascript. However, that is not needed at all. And this is an important lesson to take away from this problem, that you will definitely need later on.&lt;/p&gt;

&lt;p&gt;I decided to place the 1000 digit number in a string, then split the string into a 1000-element array. Then checking a product of 4 consecutive digits is very simple.&lt;/p&gt;

&lt;p&gt;As always the code is javascript, and can be run with nodejs.&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/1063774.js&quot;&gt; &lt;/script&gt;

</content>
 </entry>
 
 <entry>
   <title>Project Euler Problem Seven</title>
   <link href="http://www.clauswitt.com/project-euler-problem-seven.html"/>
   <updated>2011-07-07T07:00:46+02:00</updated>
   <id>http://www.clauswitt.com/project-euler-problem-seven</id>
   <content type="html">&lt;p&gt;&lt;a href=&quot;http://projecteuler.net/index.php?section=problems&amp;id=7&quot;&gt;The seventh problem&lt;/a&gt; of Project Euler is again a simple problem, which can be solved by iteration. The challenge is how to establish when a number is a prime. However, reading the definition of a prime number, you can get some help. &quot;A natural number is called a prime number (or a prime) if it is bigger than one and has no divisors other than 1 and itself.&quot; - &lt;a href=&quot;http://en.wikipedia.org/wiki/Prime_number&quot;&gt;Wikipedia&lt;/a&gt;. By knowing this we have a simple routine that exits early for all even numbers above 2 (which is the only even number that is a prime). After that all numbers up to the square root is checked as a divisor, if one is found, the number is not a prime.&lt;/p&gt;

&lt;p&gt;The reason for checking only up to the square root of number, is that if any divisor exists above the square root, one must exist below the square root as well, meaning that we already have established that the number is not a prime.&lt;/p&gt;

&lt;p&gt;The code for the problem is run with nodes… Again..&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/1063766.js&quot;&gt; &lt;/script&gt;

</content>
 </entry>
 
 <entry>
   <title>Project Euler Problem Six</title>
   <link href="http://www.clauswitt.com/project-euler-problem-six.html"/>
   <updated>2011-07-05T07:00:33+02:00</updated>
   <id>http://www.clauswitt.com/project-euler-problem-six</id>
   <content type="html">&lt;p&gt;&lt;a href=&quot;http://projecteuler.net/index.php?section=problems&amp;id=6&quot;&gt;The sixth problem&lt;/a&gt; from &lt;a href=&quot;http://projecteuler.net/&quot;&gt;Project Euler&lt;/a&gt; is about finding the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.&lt;/p&gt;

&lt;p&gt;This problem is quite simple. Both numbers (sum of squares, and square of sum) can be found through simple iterations. First we find the square of sums.&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/1063229.js&quot;&gt; &lt;/script&gt;


&lt;p&gt;Then we find the sum of squares.&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/1063232.js&quot;&gt; &lt;/script&gt;


&lt;p&gt;Simple enough. Here the total solution is wrapped in a js function called through node.js&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/1063238.js&quot;&gt; &lt;/script&gt;

</content>
 </entry>
 
 <entry>
   <title>A Simple NodeJs-based Chat Demo</title>
   <link href="http://www.clauswitt.com/a-simple-nodejs-based-chat-demo.html"/>
   <updated>2011-06-05T19:26:29+02:00</updated>
   <id>http://www.clauswitt.com/a-simple-nodejs-based-chat-demo</id>
   <content type="html">&lt;p&gt;I have written a few posts about &lt;a href=&quot;http://www.clauswitt.com/tag/nodejs/&quot;&gt;NodeJs&lt;/a&gt;. (Albeit only as a way to demo some Project Euler solutions - until now).&lt;/p&gt;

&lt;p&gt;Requirements for getting my code to run on your own machine is that you &lt;a href=&quot;http://howtonode.org/how-to-install-nodejs&quot; target=&quot;_blank&quot;&gt;install nodejs&lt;/a&gt; and &lt;a href=&quot;https://github.com/isaacs/npm&quot; target=&quot;_blank&quot;&gt;npm&lt;/a&gt;. With npm you should install express and socket.io.&lt;/p&gt;

&lt;p&gt;This simple demo is split into four parts, in three files. A static index.html page, a client side js file, and then a server.js file which includes setup for express and socket.io. Express is a great framework for http servers, and socket.io is a cross browser WebSockets implementation with fallbacks for browsers that do not implement websockets.&lt;/p&gt;

&lt;p&gt;The main part is server.js:&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/1009177.js&quot;&gt; &lt;/script&gt;


&lt;p&gt;The first part is the setup of express. The line:&lt;/p&gt;

&lt;pre&gt;
app.use(express.static(__dirname + '/../Public'));
&lt;/pre&gt;


&lt;p&gt;serves static files from the public directory, where we place our index.html file.&lt;/p&gt;

&lt;p&gt;Express uses a simple way to setup simple routes&lt;/p&gt;

&lt;pre&gt;
//A simple action to set the counter
app.get('/sentCounter/set/:count', function(req, res){
    sentCounter = req.params.count;
    res.send('ok');
});
&lt;/pre&gt;


&lt;p&gt;This route for example is used to set the sentCounter value to a value sent in as a url part. /sentCounter/set/200 would set the value to 200.&lt;/p&gt;

&lt;p&gt;To setup socket.io, simply call its listen method with the express-server as an argument. Socket io then takes over all calls to urls starting with /socket.io/&lt;/p&gt;

&lt;p&gt;The socket.io server gets an event everytime a client connects, disconnects and sends a message. The server can send messages to specific clients or broadcast to all clients (with an option to filter specific clients away).&lt;/p&gt;

&lt;p&gt;My demo implementation also has a timed event, that sends a message to all connected clients every 20 seconds.&lt;/p&gt;

&lt;p&gt;The html is all vanilla, with a script included: /socket.io/socket.io.js - this is the client side api of the socket.io library.&lt;/p&gt;

&lt;p&gt;The last part is my client side js file, which sets some event handlers for the buttons in the html, and handles connect, disconnect, incomming messages, and sending messages from the textarea.&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/1009189.js&quot;&gt; &lt;/script&gt;


&lt;p&gt;It pretty much straight forward. The interesting parts are&lt;/p&gt;

&lt;pre&gt;
socket.on('message', function(data){});
&lt;/pre&gt;


&lt;p&gt;Which is called every time the client receives a message.&lt;/p&gt;

&lt;p&gt;and&lt;/p&gt;

&lt;pre&gt;
socket.send(message);
&lt;/pre&gt;


&lt;p&gt;Which sends a message (you can send json, if you need to send objects).&lt;/p&gt;

&lt;p&gt;That's it - you can grab the complete demo at &lt;a href=&quot;https://github.com/clauswitt/NodeJs-Test-Chat&quot; target=&quot;_blank&quot;&gt;Github&lt;/a&gt;&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>A Simple Dojo Twitter Widget</title>
   <link href="http://www.clauswitt.com/a-simple-dojo-twitter-widget.html"/>
   <updated>2011-02-17T18:22:58+01:00</updated>
   <id>http://www.clauswitt.com/a-simple-dojo-twitter-widget</id>
   <content type="html">&lt;p&gt;For a simple walk through of how you can write widgets I decided to write a Twitter Widget, which shows a list of tweets for one or more people. The widget is simple to insert into a page.&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/832116.js&quot;&gt;&lt;/script&gt;


&lt;p&gt;&lt;/p&gt;

&lt;p&gt;This widget of course needs Dojo on the page, and parseOnLoad (or a manual call to parse the widgets) as well as the source of the widget of course. On top of that a lot of css is needed for it to look ok.&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/832126.js&quot;&gt;&lt;/script&gt;


&lt;p&gt;&lt;/p&gt;

&lt;p&gt;The javascript file for the widget has three parts. Some required (boilerplate) code for it to be a Dojo Widget, some public methods needed for it to interact with the page, and last but not least the actual implementation of the widget.&lt;/p&gt;

&lt;p&gt;The first part is covered many times. The second consists of using the method preamble() in which you can manipulate the parameters of the widget, before the widget is actually instantiated. In the example this is used to ensure that the class twitterTickerWidget is prefixed to any custom class the user adds to the widget, as well as ensuring that a header is set, if it is empty when before instantiating.&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/832112.js&quot;&gt; &lt;/script&gt;


&lt;p&gt;There are also some default values set - the widget will e.g. only show tweets from my twitter account, if no twitterusernames is included when inserting into a page.&lt;/p&gt;

&lt;p&gt;The main part of the widget is a jsonp call to &lt;a href=&quot;http://search.twitter.com/search.json&quot;&gt;twitters public api&lt;/a&gt;. The result of this api call is a json string representing an array of objects. One object per tweet. This array is then parsed and converted into a dom representation which is placed into the root dom node of the widget.&lt;/p&gt;

&lt;p&gt;There is used some &lt;a href=&quot;http://www.arstdesign.com/articles/autolink.html&quot; target=&quot;_blank&quot;&gt;regex magic to auto link urls in tweets&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You can see a quick demo (with some css styling) of the &lt;a href=&quot;http://clauswitt.github.com/testTickerWidget.html&quot;&gt;Dojo Twitter Widget&lt;/a&gt;. &lt;strong&gt;Note:&lt;/strong&gt; it seams the demo does not work in Safari at the moment. The error is that it cannot find the js file. It works in Firefox and Chrome though.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;UPDATE:&lt;/strong&gt; the error that made it fail in Safari (and IE -  though this last claim is untested, since I'm on a Mac without a virtual machine for testing in ie atm) was of course an error in &lt;strong&gt;my&lt;/strong&gt; code. Since class is a reserved word in javascript, you cannot reference object.class instead you should use object[&quot;class&quot;].&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/833462.js&quot;&gt; &lt;/script&gt;



</content>
 </entry>
 
 <entry>
   <title>Average CLI Script Run Time with grep, sed and awk</title>
   <link href="http://www.clauswitt.com/average-cli-script-run-time-with-grep-sed-and-awk.html"/>
   <updated>2011-02-14T06:00:28+01:00</updated>
   <id>http://www.clauswitt.com/average-cli-script-run-time-with-grep-sed-and-awk</id>
   <content type="html">&lt;p&gt;Our order processing system at &lt;a href=&quot;http://www.voicearchive.com&quot; title=&quot;voice overs&quot; target=&quot;_blank&quot;&gt;voicearchive&lt;/a&gt; has several background tasks that need to run often. For this we have a very nice cli script, written in php, from which these tasks are called. The cli runs every two minutes - first checking if the last call has finished, if not, it exists early. To make sure that this script keeps running, we have made several measures. The way we know if the cli script is already running, is by a pid-file, whose age we monitor every minute - and if it is above a certain threshhold for more than a few samples, we call some error correction actions, and delete the pid file.&lt;/p&gt;

&lt;p&gt;But since this error correction and pid deletion is potentially harmful - for instance it could stop an action from running, but mark is already run, or it could run the same action on the same object twice, both of which could have potential harmful consequences for our customers and suppliers. we have decided to also monitor the health of the cli script in another way.&lt;/p&gt;

&lt;p&gt;The script creates a log file and every (successful) run of the script logs a line with the CLI RUN TIME followed by the run time in seconds as a float. We decided to parse the average runtime of the last hours script runs from the log, and alert the appropriate people, if this value exceeds a certain threshold.&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/823650.js&quot;&gt;&lt;/script&gt;


&lt;p&gt;&lt;/p&gt;

&lt;p&gt;We use tail -630 because we have learned that this number of lines roughly equals to 30 runs which (when running normally) would give is the last hour.&lt;/p&gt;

&lt;p&gt;The grep part filters the file, so that we only get lines containing &quot;CLI RUN TIME&quot;.&lt;/p&gt;

&lt;p&gt;The sed part filters out all parts that are not a valid float value leaving only the seconds part.&lt;/p&gt;

&lt;p&gt;The awk part - which I pretty much just &lt;a target=&quot;_blank&quot; href=&quot;http://snippets.aktagon.com/snippets/15-Log-file-analysis-with-AWK-Calculating-the-sum-and-average&quot; title=&quot;Log file analysis with AWK&quot;&gt;stole from here&lt;/a&gt; -  sums all the values, and prints out the average value (the sum divided by the number of samples).&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>How to Screen 60+ RSS Feeds Every Day</title>
   <link href="http://www.clauswitt.com/how-to-screen-more-than-sixty-rss-feeds-every-day.html"/>
   <updated>2011-02-11T06:30:56+01:00</updated>
   <id>http://www.clauswitt.com/how-to-screen-more-than-sixty-rss-feeds-every-day</id>
   <content type="html">&lt;p&gt;I follow about 60+ rss feeds, which I screen every day. On weekdays I only read a couple of articles - 3 at the most. In the weekends I usually about 5-10 depending on my schedule. I spend less than 10 minutes a day screening all of these rss feeds. (However if I were to skip a couple of days, it would be an insurmountable task. At which point the &quot;mark all articles as read&quot;-button comes in handy).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Google Reader&lt;/strong&gt;
All my feeds are located in &lt;a href=&quot;http://www.google.com/reader/&quot;&gt;Google Reader&lt;/a&gt;. I never actually use google reader for reading the content. It is just a nice place to have everything located, and it has some nice features which are being used by the client programs I use. Most notable is the &quot;starred&quot;-function, which I use to mark articles that I may want to look at later.&lt;/p&gt;

&lt;h2&gt;Basic Workflow&lt;/h2&gt;


&lt;ol&gt;
    &lt;li&gt;Star interesting articles&lt;/li&gt;
    &lt;li&gt;Mark articles as read&lt;/li&gt;
    &lt;li&gt;Go through the starred items&lt;/li&gt;
    &lt;li&gt;Send actual interesting articles to Evernote&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;Star Interesting Articles&lt;/h2&gt;


&lt;p&gt;I mark all articles that strike me as maybe interesting. Either because of a headline that I cannot resist, a topic I am very interested in, or an author that I &lt;em&gt;always&lt;/em&gt; read. I do this two to three times a day. In the morning on my HTC Desire using the program &lt;a href=&quot;http://newsrob.blogspot.com/&quot;&gt;NewsRob&lt;/a&gt;, which syncs with Google Reader, and allows me to easily star, and mark articles as read. At about lunch I use the Mac program &lt;a href=&quot;http://www.grumlapp.com/&quot;&gt;Gruml&lt;/a&gt;. Sometimes I run through the list again in the evening using either of the two programs.&lt;/p&gt;

&lt;h3&gt;NewsRob&lt;/h3&gt;


&lt;p&gt;In NewsRob you star an article by pressing and holding the article in a list, and selecting &quot;Add Star&quot; - or if in single article view there is an actual star in the top right of the screen.&lt;/p&gt;

&lt;h3&gt;Gruml&lt;/h3&gt;


&lt;p&gt;In Gruml you either press &quot;F&quot; on your keyboard (my favorite way of doing it), or you right-click the article and select &quot;Starred&quot;. You can also select the article, go to the Article menu, and select &quot;Mark As Favor&quot;.&lt;/p&gt;

&lt;h2&gt;Mark Articles as Read&lt;/h2&gt;


&lt;p&gt;To avoid looking at the article more than once, I always mark an article as read, as soon as I have decided wether or not to star it.&lt;/p&gt;

&lt;h3&gt;NewsRob&lt;/h3&gt;


&lt;p&gt;In NewsRob the easiest way to do this is to swipe right (if I remember correctly this is a setting that you must enable first).&lt;/p&gt;

&lt;h3&gt;Gruml&lt;/h3&gt;


&lt;p&gt;In Gruml I go through all the post by pressing ctrl+space. This always highlights the next unread article. If it is interesting I press &quot;F&quot; if not, I just press ctrl+space again to go to the next one. The ones that have been highlighted will be marked as read automatically.&lt;/p&gt;

&lt;h2&gt;Go Through the Starred Items&lt;/h2&gt;


&lt;p&gt;A couple of times a week I go through the items I have starred. And open the article in the browser. If the article still looks good, I either send it to my &quot;Read Later&quot; notebook in &lt;a href=&quot;http://www.evernote.com&quot;&gt;Evernote&lt;/a&gt;, or I read it right then and there.&lt;/p&gt;

&lt;h2&gt;Send actual interesting articles to Evernote&lt;/h2&gt;


&lt;p&gt;For Safari (at least on mac) there is a Evernote plugin which is a button you can press, that will copy an entire webpage with design, images and all to Evernote - and set the url parameter to the source url of the page.&lt;/p&gt;

&lt;p&gt;When an article has been read in Evernote, I either delete the page, or put it in my &quot;Articles Read and Saved&quot;-notebook.&lt;/p&gt;

&lt;p&gt;How do you keep up with your favourite blogs, news-sites and other stuff?&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Fix Duplicate Content Problem in Typo3</title>
   <link href="http://www.clauswitt.com/fix-duplicate-content-problem-in-typo3.html"/>
   <updated>2011-02-10T11:00:57+01:00</updated>
   <id>http://www.clauswitt.com/fix-duplicate-content-problem-in-typo3</id>
   <content type="html">&lt;p&gt;Typo3 like many other CMS'es have a problem with url's. In Typo3 the RealUrl extension does a great job of allowing nice urls for pages which is great for seo, however the pages are still available from the &quot;old&quot; url (index.php?id=xxx). It is even worse for the home page of your website - it can be accessed by&lt;/p&gt;

&lt;ul&gt;
    &lt;li&gt;www.yourdomain.tld&lt;/li&gt;
    &lt;li&gt;www.yourdomain.tld/index.php&lt;/li&gt;
    &lt;li&gt;www.yourdomain.tld/index.php?id=&lt;/li&gt;
    &lt;li&gt;www.yourdomain.tld/index.php?id=0&lt;/li&gt;
    &lt;li&gt;www.yourdomain.tld/index.php?id=[actual page id&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;This is a problem if the search engines penalize you for duplicate content. There is, luckily, and easy fix for this. You can tell the search engines which page is the real page and subsequently which ones are copies that you know are there, but which should not be considered. The trick is to put a&lt;a href=&quot;http://www.google.com/support/webmasters/bin/answer.py?hl=en&amp;answer=139394&quot;&gt; link tag, with a rel-attribute with the value of canonical&lt;/a&gt; and then put the &quot;real&quot; url in the href-attribute. This tells google (and friends) that the referenced page is the page that should be considered for indexing.&lt;/p&gt;

&lt;p&gt;In typo3 there is a short snippet that can help you to do this automatically for all pages.&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/820227.js&quot;&gt; &lt;/script&gt;


&lt;p&gt;This creates the tag with the real url in the header of every page.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;UPDATE:&lt;/strong&gt; as Steffen points out in the comments below, this solution will only work if you have no plugins that append data to the url for their view. In these cases the &lt;a href=&quot;http://typo3.org/extensions/repository/view/canonical/current/&quot;&gt;Typo3 Extension Canonical&lt;/a&gt; is probably your best bet for a solution.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Roman Numerals in JavaScript</title>
   <link href="http://www.clauswitt.com/roman-numerals-in-javascript.html"/>
   <updated>2011-02-10T06:30:49+01:00</updated>
   <id>http://www.clauswitt.com/roman-numerals-in-javascript</id>
   <content type="html">&lt;p&gt;I know, I know. I have written enough about Roman Numerals.&lt;/p&gt;

&lt;p&gt;I have created a version of the &lt;a href=&quot;http://www.clauswitt.com/roman-numerals-a-code-kata/&quot;&gt;Roman Numerals code kata&lt;/a&gt; I did in php and &lt;a href=&quot;http://www.clauswitt.com/how-i-learned-python-in-an-hour/&quot;&gt;python&lt;/a&gt; in JavaScript. It has two public methods getRomanNumeral(number) which gets a valid roman numeral from a number and getNumber(romanNumeral) which will convert a valid roman numeral to its numeric value.&lt;/p&gt;

&lt;p&gt;I will not go into details of the implementation, since it is mostly the same as the php and python version. But I have created a small demo which is located at &lt;a href=&quot;http://clauswitt.github.com/testRomanNumerals.html&quot;&gt;http://clauswitt.github.com/testRomanNumerals.html&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You can get the source of the implementation at &lt;a href=&quot;https://github.com/clauswitt/Roman-Numerals-Kata/tree/master/javascript&quot;&gt;Github&lt;/a&gt;&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>How I Learned Python in an Hour</title>
   <link href="http://www.clauswitt.com/how-i-learned-python-in-an-hour.html"/>
   <updated>2011-02-08T10:24:41+01:00</updated>
   <id>http://www.clauswitt.com/how-i-learned-python-in-an-hour</id>
   <content type="html">&lt;p&gt;A while back I wrote about a code kata that I wrote, &lt;a href=&quot;http://www.clauswitt.com/roman-numerals-a-code-kata/&quot;&gt;Roman Numerals in PHP&lt;/a&gt;. I decided that I would try to re-implement the same algorithm in different programming languages - both some I knew, and some i did not. My first choice was python. &lt;/p&gt;




&lt;p&gt;I have written a bit of python earlier, but have never used it for anything important. I pretty much started from scratch. &lt;/p&gt;


&lt;p&gt;&lt;strong&gt;Python is very sensitive to indentation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;One of my biggest frustrations - until I found a tip that I needed to set soft-tabs as default for my python source files in Textmate. Go to Bundles-&gt;Bundle Editor-&gt;Show Bundle Editor. Find Python, and then Miscellaneous. Enter the following: &lt;/p&gt;


&lt;script src=&quot;https://gist.github.com/816152.js&quot;&gt; &lt;/script&gt;


&lt;p&gt;All python files should now use softwrap, instead of tabs. That worked for me. &lt;/p&gt;


&lt;p&gt;&lt;strong&gt;All class methods must have a self parameter&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;At first I thought the python interpreter was taunting me. When calling a method it constantly told me that I send exactly one more parameter to the method than were expected. In other languages the reference to the current object are sent transparently. In Python it is also sent transparently, but you need to define it in the method signature in your class. &lt;/p&gt;


&lt;p&gt;&lt;strong&gt;Files and classes does not match&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;My first instinct was to include my python class as a file and then instantiate it with &lt;/p&gt;


&lt;script src=&quot;https://gist.github.com/816159.js&quot;&gt; &lt;/script&gt;


&lt;p&gt;however this is wrong. The python file in which the class is placed is called a module in python, which is what I imported. This imported module can then contain functions and/or classes. From php I am used to - since I use auto loading extensively - that classnames and filenames match. This is not necessarily the case here. The correct way to instantiate the class is thus (the first three lines for a cli program to test the RomanNumerals class): &lt;/p&gt;


&lt;script src=&quot;https://gist.github.com/816161.js&quot;&gt; &lt;/script&gt;


&lt;p&gt;&lt;strong&gt;Class variables are not accessed with this or self&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;One thing I struggled with for a long time, was how to access my &quot;constants&quot;. Since python does not support class constants, I used variables instead. And they were rather hard to reference. The correct way seems to be self.__class__.VARNAME &lt;/p&gt;




&lt;p&gt;Take a look at the source for the &lt;a href=&quot;https://github.com/clauswitt/Roman-Numerals-Kata/tree/master/python&quot;&gt;python implementation of Roman Numerals on github&lt;/a&gt;. &lt;/p&gt;



</content>
 </entry>
 
 <entry>
   <title>Fullscreen a Movie in VLC from Quicksilver</title>
   <link href="http://www.clauswitt.com/fullscreen-a-movie-in-vlc-from-quicksilver.html"/>
   <updated>2011-01-07T15:13:17+01:00</updated>
   <id>http://www.clauswitt.com/fullscreen-a-movie-in-vlc-from-quicksilver</id>
   <content type="html">&lt;p&gt;I love quicksilver, and I never (well almost never) open a file by browsing in Finder. When I want to watch a movie on my mac, I usually just find the file through quicksilver, and then I have an action named &quot;Fullscreen in VLC&quot; with the follow applescript:&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/769490.js&quot;&gt; &lt;/script&gt;


&lt;p&gt;The script should be placed in ~/Library/Application Support/Quicksilver/Actions/ - named what ever you want (the filename will be the action name in quicksilver). Restart Quicksilver and you're ready to open movies in fullscreen with a minimum of keypresses (and no mouse).&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Reset ACP Opcode Cache on Deploy</title>
   <link href="http://www.clauswitt.com/reset-acp-opcode-cache-on-deploy.html"/>
   <updated>2010-12-20T20:28:01+01:00</updated>
   <id>http://www.clauswitt.com/reset-acp-opcode-cache-on-deploy</id>
   <content type="html">&lt;p&gt;Normally when deploying a php webapp, apc will automatically reset cache for changed files. However in our case we have our code hidden behind some nested symlinks. Most times when we deploy our webapplication it is while it is being used. And since much of the work our application does is related to moving large files, it is never good to restart apache when we deploy, since most file transfers will halt.&lt;/p&gt;

&lt;p&gt;In stead we have created a simple controller method with some authentication, which calls a apc api method called apc_clear_cache('opcode'); - this will clear the opcode cache.&lt;/p&gt;

&lt;p&gt;You have to call it for the web-context - and for cli context, if you have apc.enable_cli=1. Therefore you need a controller action with this code - and call it through curl. Please also remember that the url should require some sort of authentication, otherwise anybody (knowing - or being able to guess - the url) could reset your cache.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Ant plugin for Oh My Zsh</title>
   <link href="http://www.clauswitt.com/ant-plugin-for-oh-my-zsh.html"/>
   <updated>2010-11-25T21:58:43+01:00</updated>
   <id>http://www.clauswitt.com/ant-plugin-for-oh-my-zsh</id>
   <content type="html">&lt;p&gt;Pretty much a clone of the &lt;a href=&quot;http://www.clauswitt.com/a-phing-plugin-for-oh-my-zsh/&quot;&gt;phing plugin&lt;/a&gt;, I have also created a &lt;a href=&quot;https://github.com/clauswitt/oh-my-zsh/blob/master/plugins/ant/ant.plugin.zsh&quot;&gt;plugin for ant&lt;/a&gt;. It works in almost the same way, however it uses a sed one-liner for getting the targets from the build file. Like my last plugin it assumes that the build file is named build.xml. The sed command to list the ant targets could actually be used for getting the phing targets as well. It looks like this:&lt;/p&gt;

&lt;pre&gt;sed -n &amp;apos;/&amp;lt;target/s/&amp;lt;target.*name=&quot;\([^&quot;]*\).*$/\1/p&amp;apos; build.xml&lt;/pre&gt;


&lt;p&gt;Like last time, please contact me if you have changes, ideas, feature requests or ... whatever really.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>A phing plugin for Oh My Zsh</title>
   <link href="http://www.clauswitt.com/a-phing-plugin-for-oh-my-zsh.html"/>
   <updated>2010-11-25T21:29:20+01:00</updated>
   <id>http://www.clauswitt.com/a-phing-plugin-for-oh-my-zsh</id>
   <content type="html">&lt;p&gt;A long time ago (a year and a half, I just checked) my good friend &lt;a href=&quot;http://www.jesperrasmussen.com/&quot;&gt;Jesper Rasmussen&lt;/a&gt; &lt;a href=&quot;http://jesperrasmussen.com/switching-bash-with-zsh&quot;&gt;blogged about zsh&lt;/a&gt;, a shell that he had been ranting about for at least a year. About a year later I shifted to it as well, and soon thereafter I began using the setup from &lt;a href=&quot;https://github.com/robbyrussell/oh-my-zsh&quot;&gt;Oh My Zsh&lt;/a&gt;. It has some great plugins, of which I use the git support every day.&lt;/p&gt;

&lt;p&gt;A couple of weeks ago I decided to create a &lt;a href=&quot;https://github.com/clauswitt/oh-my-zsh/blob/master/plugins/phing/phing.plugin.zsh&quot;&gt;plugin of my own&lt;/a&gt;, since there was no autocomplete support for &lt;a href=&quot;http://phing.info/trac/&quot;&gt;phing&lt;/a&gt;, which I also use every day. (And I love saving a couple of keystrokes whenever I build or deploy).&lt;/p&gt;

&lt;p&gt;Creating these auto complete plugins for oh my zsh is rather simple. In my case I have assumed that the build file is allways called build.xml. This way I can get all the targets of the default file with just the command &quot;phing -l&quot;. The output of this command is then saved in a temp-file which is used to autocomplete the phing command.&lt;/p&gt;

&lt;p&gt;The only problem with this approach is that the &quot;phing -l&quot; command lists some data we cannot use. This is filtered out with grep, before the output is sent to the file. The complete command is:&lt;/p&gt;

&lt;pre&gt;phing -l |grep -v &quot;:&quot; |grep -v &quot;^$&quot;|grep -v &quot;\-&quot; &gt; .phing_targets&lt;/pre&gt;


&lt;p&gt;Please contact me if you have feedback, bugfixes, ideas, feature requests or anything else.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Roman Numerals, a Code Kata</title>
   <link href="http://www.clauswitt.com/roman-numerals-a-code-kata.html"/>
   <updated>2010-09-20T11:33:57+02:00</updated>
   <id>http://www.clauswitt.com/roman-numerals-a-code-kata</id>
   <content type="html">&lt;p&gt;Doing code katas is something I have done for about a year now. Deliberately practicing my skills as a programmer is something that I find very pleasing, and I constantly see an improvement in the way I solve problems.&lt;/p&gt;

&lt;p&gt;Initially I did these katas in the privacy of my own home, and never published anything about it. A couple of months however I published a couple of my Project Euler solutions in Javascript. And I got some great feedback from others, which helped me become a better programmer of js. Thus I decided to try to post katas every couple of weeks - but alas, the holiday disrupted my usual habit of doing these exercises. (Apparently summer holidays do that - the amount of physical exercise I get, has also plummeted).&lt;/p&gt;

&lt;p&gt;Well, back to the Kata at hand.&lt;/p&gt;

&lt;p&gt;The idea to this Kata came from the Coding Dojos &lt;a href=&quot;http://www.codingdojo.org/cgi-bin/wiki.pl?KataRomanNumerals&quot;&gt;page about Roman Numerals Kata&lt;/a&gt;. I have created a simple solution for converting numbers to roman numerals, and back again.&lt;/p&gt;

&lt;p&gt;I started by writing the tests. So I created a PhpUnit Testcase with the following methods:&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/587647.js&quot;&gt; &lt;/script&gt;


&lt;p&gt;A method to check that the roman numerals I get from my new (unimplemented) class would in fact match values I knew were correct. (Some simple values and the year I was born).&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/587650.js&quot;&gt; &lt;/script&gt;


&lt;p&gt;A method to check that the values of roman numerals I knew would also match what I knew they should.&lt;/p&gt;

&lt;p&gt;From there on it was just happy hacking. The first implementation was quite crude, but passed the tests. (&lt;a href=&quot;http://github.com/wittnezz/Roman-Numerals-Php-Kata/commit/f752d3a49c83a47a7d8592b3f1de2bce82eb6f35&quot;&gt;Take a look at the history at github&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;From then it was a mather of adding a few tests for Exception handling, and refactoring to a more elegant solution. No doubt it could have been done even better - but this works, and was done in a mather of an hour or so.&lt;/p&gt;

&lt;p&gt;Take a look at &lt;a href=&quot;http://github.com/wittnezz/Roman-Numerals-Php-Kata&quot;&gt;the source at git hub&lt;/a&gt;. And please leave a comment about how you would go about solving the problem.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Project Euler Problem Five</title>
   <link href="http://www.clauswitt.com/project-euler-problem-five.html"/>
   <updated>2010-06-07T07:30:37+02:00</updated>
   <id>http://www.clauswitt.com/project-euler-problem-five</id>
   <content type="html">&lt;p&gt;Continuing our combined &lt;a href=&quot;http://nodejs.org&quot;&gt;node.js&lt;/a&gt; and &lt;a href=&quot;http://www.clauswitt.com/tag/project-euler/&quot;&gt;project euler posts&lt;/a&gt;. We got to &lt;a href=&quot;http://projecteuler.net/index.php?section=problems&amp;id=5&quot;&gt;problem five&lt;/a&gt;, which asks us &quot;What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?&quot;.&lt;/p&gt;

&lt;p&gt;First of all we only check numbers below or equal to 20! because we know for sure that this number will satisfy the criterium of the question, we just don't know if there is a result below this number, we also know that the number must be at least 20. For this reason we check all numbers between 20 and 20! if all numbers between 1 and 20 is a divisor - if one of the numbers fail, we move on to the next candidate. As soon as a candidate proves to be correct, we exit and return the result.&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/420267.js&quot;&gt; &lt;/script&gt;



</content>
 </entry>
 
 <entry>
   <title>Project Euler Problem Four</title>
   <link href="http://www.clauswitt.com/project-euler-problem-four.html"/>
   <updated>2010-06-04T07:00:34+02:00</updated>
   <id>http://www.clauswitt.com/project-euler-problem-four</id>
   <content type="html">&lt;p&gt;Find the largest palindrome made from the product of two 3-digit numbers. This is &lt;a href=&quot;http://projecteuler.net/index.php?section=problems&amp;id=4&quot;&gt;problem four of project euler&lt;/a&gt;, and this one actually caused me some problems. The reason was that I wrongly assumed that a number with the largest divisor would also would be the largest number. But of course this is not necessarily the case.&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/418472.js&quot;&gt; &lt;/script&gt;


&lt;p&gt;As the &lt;a href=&quot;http://www.clauswitt.com/project-euler-problem-one/&quot;&gt;previous&lt;/a&gt; &lt;a href=&quot;http://www.clauswitt.com/project-euler-problem-two/&quot;&gt;three&lt;/a&gt; &lt;a href=&quot;http://www.clauswitt.com/project-euler-problem-three/&quot;&gt;problems&lt;/a&gt; I have posted about, this is written to run on &lt;a href=&quot;http://nodejs.org&quot;&gt;node.js&lt;/a&gt;.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>From Subversion to Git</title>
   <link href="http://www.clauswitt.com/from-subversion-to-git.html"/>
   <updated>2010-06-02T12:00:33+02:00</updated>
   <id>http://www.clauswitt.com/from-subversion-to-git</id>
   <content type="html">&lt;p&gt;This past weekend I moved our work repositories from Subversion to Git. I have been using Git for my private projects for a couple of months now, and really wanted the same workflow and features for my daily work at VoiceArchive.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Installing gitosis&lt;/strong&gt;
Even though I use github privately, I opted for the selfhosted version for our work-repositories. The reasoning behind this was mostly that we host our own subversion repo's today, then we could just as well host our own git repo's. (This also made the change possible without needing the company to pay more for hosting than we allready do).&lt;/p&gt;

&lt;p&gt;I will not go through the installation, but just link to &lt;a href=&quot;http://scie.nti.st/2007/11/14/hosting-git-repositories-the-easy-and-secure-way&quot;&gt;this excellent guide&lt;/a&gt; I followed to get everything up and running.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Creating repositories&lt;/strong&gt;
When all users, roles and repositories have been saved in the file gitosis.conf - you are able to create local repositories for your projects and push the to the server. (This works just as with github, btw). Again instead of showing you an example I recommend &lt;a href=&quot;http://scie.nti.st/2007/11/14/hosting-git-repositories-the-easy-and-secure-way&quot;&gt;the guide I used&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Exporting from subversion&lt;/strong&gt;
The easiest part was exporting from subversion and commiting in git. Only downside was that the repository history was lost. But I still have the subversion repos as a backup, if I need them in the future.&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/420247.js&quot;&gt; &lt;/script&gt;


&lt;p&gt;&lt;strong&gt;Final thoughts&lt;/strong&gt;
We are running Redmine and Hudson on our dev-server. Both were setup to use the git repository instead of the svn repo in just under 30 minutes. (And that included 5 projects). Apart from some splitting up of projects into minor parts this was pretty straightforward.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Project Euler Problem Three</title>
   <link href="http://www.clauswitt.com/project-euler-problem-three.html"/>
   <updated>2010-06-01T07:00:54+02:00</updated>
   <id>http://www.clauswitt.com/project-euler-problem-three</id>
   <content type="html">&lt;p&gt;Continuing my posts about &lt;a href=&quot;http://projecteuler.net/index.php?section=problems&quot;&gt;Project Euler Problems&lt;/a&gt;, this time with &lt;a href=&quot;http://projecteuler.net/index.php?section=problems&amp;id=3&quot;&gt;problem three&lt;/a&gt;, which asks us to find the &quot;the largest prime factor of the number 600851475143&quot;.&lt;/p&gt;

&lt;p&gt;This time I have decided to explain the code a bit more, through comments - since this problem is a bit more tricky than the previous two problems.&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/418464.js&quot;&gt;&lt;/script&gt;


&lt;p&gt;&lt;/p&gt;

&lt;p&gt;Once again, you will need node.js to run the code.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Project Euler Problem Two</title>
   <link href="http://www.clauswitt.com/project-euler-problem-two.html"/>
   <updated>2010-05-30T10:00:51+02:00</updated>
   <id>http://www.clauswitt.com/project-euler-problem-two</id>
   <content type="html">&lt;p&gt;Yesterday I posted &lt;a href=&quot;http://www.clauswitt.com/project-euler-problem-one/&quot;&gt;my first euler-code&lt;/a&gt;. This time we will take a look at &lt;a href=&quot;http://projecteuler.net/index.php?section=problems&amp;amp;id=2&quot;&gt;problem two&lt;/a&gt;, again with the help of some javascript running on node.js.&lt;/p&gt;

&lt;p&gt;The problem is &quot;Find the sum of all the even-valued terms in the [fibonacci] sequence which do not exceed four million.&quot;&lt;/p&gt;

&lt;p&gt;My take on the solution was to run through all fibonacci numbers below 4.000.000 and adding them to the total, if they were equal. The next fibonacci number is calculated by always saving the last two numbers found.&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/418453.js&quot;&gt; &lt;/script&gt;


&lt;p&gt;You will need node.js to run this code.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Project Euler Problem One</title>
   <link href="http://www.clauswitt.com/project-euler-problem-one.html"/>
   <updated>2010-05-29T19:55:17+02:00</updated>
   <id>http://www.clauswitt.com/project-euler-problem-one</id>
   <content type="html">&lt;p&gt;A long time ago I decided to do a couple of posts about &lt;a href=&quot;http://projecteuler.net/&quot;&gt;project euler&lt;/a&gt;. I find &lt;a href=&quot;http://projecteuler.net/index.php?section=problems&quot;&gt;the problems&lt;/a&gt; to be great excersize. It was not before I began to look into &lt;a href=&quot;http://nodejs.org/&quot;&gt;node.js&lt;/a&gt; though, that I began writing code for the problems for the purpose of publishing it.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://projecteuler.net/index.php?section=problems&amp;id=1&quot;&gt;The first problem&lt;/a&gt; on the list is very simple. &quot;Find the sum of all the multiples of 3 or 5 below 1000&quot;. The solution, then, must be to find all numbers that are multiples of 3 and 5, and then adding those...&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/418446.js&quot;&gt; &lt;/script&gt;


&lt;p&gt;This solution is pretty simple. You (probably) need nodejs to run the code.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Using Quicksilver to edit hosts file</title>
   <link href="http://www.clauswitt.com/using-quicksilver-to-edit-hosts-file.html"/>
   <updated>2009-11-04T15:38:41+01:00</updated>
   <id>http://www.clauswitt.com/using-quicksilver-to-edit-hosts-file</id>
   <content type="html">&lt;p&gt;This is mostly just a follow up for my previous post on &lt;a href=&quot;http://www.clauswitt.com/2009/11/04/319/&quot;&gt;using a shell script to add and remove test domains in the hosts file&lt;/a&gt;. I have created two small applescripts for use in Quicksilver to execute that script. If you need to use these you place them in ~/Library/Application Support/Quicksilver/Actions and set your password. (Beware this could pose a threat, since you will have your password in cleartext on your harddrive).&lt;/p&gt;

&lt;p&gt;The two scripts are almost identical. Actually the only difference is the action the shell script should call (add or remove). The rest of the scripts are completely the same.&lt;/p&gt;

&lt;p&gt;I call this file addhost.&lt;/p&gt;

&lt;pre name=&quot;code&quot; class=&quot;applescript&quot;&gt;
using terms from application &quot;Quicksilver&quot;
    on process text txt
        set the_password to &quot;YOURPASSWORD&quot;
        repeat with delimiter_position from 1 to (length of txt)
            if character delimiter_position of txt = &quot; &quot; then exit repeat
        end repeat
        if delimiter_position = (length of txt) then
            set hostname to txt as string
            set ipaddress to &quot;&quot;
        else
            set hostname to characters 1 thru (delimiter_position - 1) of txt as string
            set ipaddress to characters (delimiter_position + 1) thru (length of txt) of txt as string
            
        end if
        
        do shell script &quot;sudo hosts.sh add &quot; &amp; hostname &amp; &quot; &quot; &amp; ipaddress password the_password with administrator privileges
        
        return nothing
    end process text
end using terms from
&lt;/pre&gt;


&lt;p&gt;I call this file removehost.&lt;/p&gt;

&lt;pre name=&quot;code&quot; class=&quot;applescript&quot;&gt;
using terms from application &quot;Quicksilver&quot;
    on process text txt
        set the_password to &quot;YOURPASSWORD&quot;
        repeat with delimiter_position from 1 to (length of txt)
            if character delimiter_position of txt = &quot; &quot; then exit repeat
        end repeat
        if delimiter_position = (length of txt) then
            set hostname to txt as string
            set ipaddress to &quot;&quot;
        else
            set hostname to characters 1 thru (delimiter_position - 1) of txt as string
            set ipaddress to characters (delimiter_position + 1) thru (length of txt) of txt as string
            
        end if
        
        do shell script &quot;sudo hosts.sh remove &quot; &amp; hostname &amp; &quot; &quot; &amp; ipaddress password the_password with administrator privileges
        
        return nothing
    end process text
end using terms from
&lt;/pre&gt;


&lt;p&gt;Now I am able to create a local domain by opening Quicksilver (double-control in my case) press period, write the domain name, press tab, and select the addhost action (ad is enough in my case). Removing is just as easy - the last step is just to select the removehost action (re is enough in my case).&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Bash script for editing the hosts file</title>
   <link href="http://www.clauswitt.com/319.html"/>
   <updated>2009-11-04T10:02:46+01:00</updated>
   <id>http://www.clauswitt.com/319</id>
   <content type="html">&lt;p&gt;I just read a &lt;a href=&quot;http://jesperrasmussen.com/coding-on-the-go-setting-up-local-apache&quot;&gt;post about local development in apache&lt;/a&gt; by &lt;a href=&quot;http://jesperrasmussen.com/&quot;&gt;Jesper Rasmussen&lt;/a&gt; and thought one thing was missing. I usually test my sites and applications locally with the real domain - to ensure that functionality based on the url works as expected. However this means editing the hosts file several times a day. Now I have made a small shellscript that will add and remove lines from the hosts file.&lt;/p&gt;

&lt;pre name=&quot;code&quot; class=&quot;bash&quot;&gt;
#! /bin/bash
DEFAULT_IP=127.0.0.1
IP=${3:-$DEFAULT_IP}

case &quot;$1&quot; in
  add)
        echo &quot;$IP $2&quot;  &gt;&gt; /etc/hosts
        ;;
  remove)
        sed -ie &quot;\|^$IP $2\$|d&quot; /etc/hosts
        ;;

  *)
        echo &quot;Usage: &quot;
        echo &quot;hosts.sh [add|remove] [hostname] [ip]&quot;
        echo 
        echo &quot;Ip defaults to 127.0.0.1&quot;
        echo &quot;Examples:&quot;
        echo &quot;hosts.sh add testing.com&quot;
        echo &quot;hosts.sh remove testing.com 192.168.1.1&quot;
        exit 1
        ;;
esac

exit 0
&lt;/pre&gt;


&lt;p&gt;As you can see the script defaults the ip to 127.0.0.1 for easy creation of local domains. Next step is to create a quicksilver (and a gnome do) plugin for easy creation without ever touching the terminal. (Even though we all love the terminal, right?)&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Converting Filenames to Lowercase with Bash</title>
   <link href="http://www.clauswitt.com/converting-filenames-to-lowercase-with-bash.html"/>
   <updated>2009-06-03T08:24:36+02:00</updated>
   <id>http://www.clauswitt.com/converting-filenames-to-lowercase-with-bash</id>
   <content type="html">&lt;p&gt;Once again I have a bash-oneliner. For some reason it is all I blog about at the moment.&lt;/p&gt;

&lt;p&gt;I had an import script for importing demo files (in mp3 format) to a database used at &lt;a href=&quot;http://www.voicearchive.com/&quot;&gt;Voicearchive&lt;/a&gt;. Only problem the import script depended on the files being named precisely according to a specific rule. But for some reason some times it was named with uppercase letters, and sometimes with lowercase letters. I decided to rename all files to lowercase, and change the importscript accordingly.&lt;/p&gt;

&lt;pre name=&quot;code&quot; class=&quot;bash&quot;&gt;
find . -maxdepth 1 -type f -execdir rename 'y/A-Z/a-z/' '{}' \;
&lt;/pre&gt;



</content>
 </entry>
 
 <entry>
   <title>Resizing Itunes Window with Applescript</title>
   <link href="http://www.clauswitt.com/resizing-itunes-window-with-applescript.html"/>
   <updated>2009-05-31T07:14:43+02:00</updated>
   <id>http://www.clauswitt.com/resizing-itunes-window-with-applescript</id>
   <content type="html">&lt;p&gt;This weekend my girlfriend and I moved all the stuff I had in my private office/homestudio out, to create a room for our son. Because of this my old mac was put in the living room, and is now a primitive media center with the TV as it's only screen. The resolution as a result has changed to something significantly lower, and there are no longer two screens. As a result the Itunes window was too big, and I was not able to resize it, since the area where this is possible was outside the viewable area of the screen, no mather what I did.&lt;/p&gt;

&lt;p&gt;I decided it was time for some AppleScript to solve this problem.&lt;/p&gt;

&lt;pre name=&quot;code&quot; class=&quot;applescript&quot;&gt;
tell application &quot;iTunes&quot;
    set bounds of window 1 to {1, 1, 400, 400}
end tell
&lt;/pre&gt;


&lt;p&gt;ps - had an old cordless windows keyboard and mouse - it is a bit weird trying to figure out which keys do what...&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Bash Oneliner for Counting Files</title>
   <link href="http://www.clauswitt.com/bash-oneliner-for-counting-files.html"/>
   <updated>2009-05-14T10:56:51+02:00</updated>
   <id>http://www.clauswitt.com/bash-oneliner-for-counting-files</id>
   <content type="html">&lt;p&gt;I needed to find a way to count the number of files in a directory and only output that number. Bash is still my best friend for this sort of thing - especially with a little help from google.&lt;/p&gt;

&lt;pre name=&quot;code&quot; class=&quot;bash&quot;&gt;
ls -1 | wc -l
&lt;/pre&gt;


&lt;p&gt;by the way - the answer was 2062 files.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Renaming file extensions with bash script</title>
   <link href="http://www.clauswitt.com/renaming-file-extensions-with-bash-script.html"/>
   <updated>2009-04-30T07:58:04+02:00</updated>
   <id>http://www.clauswitt.com/renaming-file-extensions-with-bash-script</id>
   <content type="html">&lt;p&gt;A couple of weeks ago I had to rename the file extension of several view scripts from html (from my own mvc framework) to phtml (zend framework). I found, as always, bash to be my friend.&lt;/p&gt;

&lt;pre name=&quot;code&quot; class=&quot;bash&quot;&gt;
for i in *
do
  ( file $i | grep html ) &amp;&amp; mv $i $(echo $i | sed s/html$/phtml/)
done
&lt;/pre&gt;

</content>
 </entry>
 
 <entry>
   <title>OpenID and OAuth for SSO</title>
   <link href="http://www.clauswitt.com/openid-and-oauth-for-sso.html"/>
   <updated>2009-03-24T10:07:32+01:00</updated>
   <id>http://www.clauswitt.com/openid-and-oauth-for-sso</id>
   <content type="html">&lt;p&gt;In my previous post about &lt;a href=&quot;http://www.clauswitt.com/2009/03/09/sso-for-webapplications/&quot;&gt;SSO for webapplications&lt;/a&gt; I have missed the obvious - why not use OpenId and OAuth.&lt;/p&gt;

&lt;p&gt;It is important however to know the difference between the two. OpenId is used for authentication - is the user who he says he is - and OAuth is used for authorization is this specific user allowed to do this specific action. Well, in the case of OAuth i guess it is more, is this application allowed to do this action on behalf of this user. A use case described in the post &lt;a href=&quot;http://portalzone.blogspot.com/2007/12/openid-oauth-complimentary-or-competing.html&quot;&gt;OpenID  &amp;amp; OAuth &amp;#8211; complimentary or competing?&lt;/a&gt; is:&lt;/p&gt;

&lt;blockquote cite=&quot;http://portalzone.blogspot.com/2007/12/openid-oauth-complimentary-or-competing.html&quot;&gt;
Let’s say you are registering as a delegate on a conference website. With OAuth it is possible for the conference website to automatically add the event to your google calendar or yahoo calendar with your consent (assuming google and yahoo support OAuth). How does it work ? Well, once you decide to let the conference website add an event to your google calendar, you get redirected to google. On google , you explicitly authorize the conference website to modify your calendar. After this authorization, the conference website will have permission to modify your calendar data.
&lt;/blockquote&gt;


&lt;p&gt;The problem with OAuth is that you have to login to every site that you wish to give an application access to. For this reason &lt;a href=&quot;http://googledataapis.blogspot.com/2009/01/bringing-openid-and-oauth-together.html&quot;&gt;Google has published a hybrid protocol&lt;/a&gt;, and tries to make this a new standard. They &lt;a href=&quot;http://googlecodesamples.com/hybrid/&quot;&gt;created a demo&lt;/a&gt;, and &lt;a href=&quot;http://code.google.com/p/gdata-samples/source/browse/#svn/trunk/hybrid&quot;&gt;released the source for that&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;This really looks like a technique that could be used for my applications. I am looking into this, and hopefully will have a quick tutorial on the subject in the near future.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>New Application? Just Write The Damn Thing</title>
   <link href="http://www.clauswitt.com/new-application-just-write-the-damn-thing.html"/>
   <updated>2009-03-23T06:00:27+01:00</updated>
   <id>http://www.clauswitt.com/new-application-just-write-the-damn-thing</id>
   <content type="html">&lt;p&gt;I have been getting a thought into my head the last couple of days. I have been talking a lot about things surrounding web application building the last weeks. Primarily it has been about all the things that are common to most of the application ideas that I have. While reading about &lt;a href=&quot;http://highscalability.com/scaling-twitter-making-twitter-10000-percent-faster&quot;&gt;Scaling Twitter&lt;/a&gt; though, I got to thinking. I might be worrying a bit too much about things that are not even important before there are a lot of active users actually using the product on a daily basis.&lt;/p&gt;

&lt;p&gt;Maybe it is because it is easier to talk about all the things you ought to do right, instead of just writing the damn thing. It is also a lot safer for the ego in some way. You can postpone putting your idea out there - because no mather how good an idea it is, someone is bound to be of another oppinion. I will try to not let myself be blinded by all the negative what if's.&lt;/p&gt;

&lt;blockquote cite=&quot;http://highscalability.com/scaling-twitter-making-twitter-10000-percent-faster&quot;&gt;For us, it’s really about scaling horizontally - to that end, Rails and Ruby haven’t been stumbling blocks, compared to any other language or framework. The performance boosts associated with a “faster” language would give us a 10-20% improvement, but thanks to architectural changes that Ruby and Rails happily accommodated, Twitter is 10000% faster than it was in January.&lt;/blockquote&gt;


&lt;p&gt;In the near future I will be creating technical proofs of concept (because the design part is not my strong side) of several of my ideas. This way it will be easier to assemble a team, and decide what to actually do.&lt;/p&gt;

&lt;p&gt;This way, I will also have something real to write about.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Writing your own PHP Framework</title>
   <link href="http://www.clauswitt.com/writing-your-own-php-framework.html"/>
   <updated>2009-03-19T07:30:07+01:00</updated>
   <id>http://www.clauswitt.com/writing-your-own-php-framework</id>
   <content type="html">&lt;p&gt;Writing your own PHP Framework, should you do it?&lt;/p&gt;

&lt;p&gt;While I worked at &lt;a href=&quot;http://www.wildside.dk/&quot;&gt;Wildside in Århus, Denmark&lt;/a&gt;, I wrote a MVC Framework for using in Typo3 extensions. The reason for this was that we were working on an application which required such a framework to structure the project to be as maintainable as possible without loosing performance. We started looking at different options, and none of them seemed right for the job, and most of them were either not usable in the context of Typo3, or not mature enough for production use.&lt;/p&gt;

&lt;p&gt;When the project started there was a tight coupling to Typo3 since the application was pretty much just an extension to the website.&lt;/p&gt;

&lt;p&gt;Since then a lot have changed, and I am now working directly for the client, who was a customer of my old company 9iA as well. The system is now more of a standalone web application and the requirements of the framework has changed many times since its first version in may last year.&lt;/p&gt;

&lt;p&gt;The framework is, however still tight coupled to Typo3, but Typo3 is pretty much only used for templating and authentication.&lt;/p&gt;

&lt;p&gt;In the last year and a half I have worked with a lot of php frameworks - saying that I have used all of them is off course an exaggeration, but I have been using most of the top ones in some way or the other. And not one of them work in exactly the way I would want them to.&lt;/p&gt;

&lt;p&gt;Now I am wondering wether to rewrite my mvc framework to be standalone. It would not demand more than 30-50 hours of work to do that, and on top of that be able to integrate &lt;a href=&quot;http://framework.zend.com/manual/en/&quot;&gt;Zend Frameworks Components&lt;/a&gt; and an existing ORM like perhaps &lt;a href=&quot;http://www.doctrine-project.org/&quot;&gt;Doctrine&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The other possibility is to rewrite the application to use an existing well tested framework. If Flow3 had been ready for production (and working in php 5.2.x) that would probably had been the case. But now I'm just not sure.&lt;/p&gt;

&lt;p&gt;No mather what we decide to do, the current version will go live without any kind of rewrite. But the learning experience from &lt;a href=&quot;http://anantgarg.com/2009/03/13/write-your-own-php-mvc-framework-part-1/&quot;&gt;writing your own PHP MVC Framework&lt;/a&gt; might be nice to gain, at some point - even though most of it is written allready.&lt;/p&gt;

&lt;p&gt;What would you do? And if you would use an existing framework - which one would you recommend?&lt;/p&gt;

&lt;p&gt;Btw, no mather what we choose to do, the framework will be released to the public as soon as all bugs that I have found have been fixed, and some basic documentation have been written.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>How I sorted All My Mp3's With a Simple Bash Script</title>
   <link href="http://www.clauswitt.com/how-i-sorted-all-my-mp3s-with-a-simple-bash-script.html"/>
   <updated>2009-03-12T22:00:00+01:00</updated>
   <id>http://www.clauswitt.com/how-i-sorted-all-my-mp3s-with-a-simple-bash-script</id>
   <content type="html">&lt;p&gt;First of all, the headline is a lie. I am in the process of copying all mp3 files that we in our household have had on a number of different machines to one central server, which all computers talk to via webdav. But since we have had a lot of different naming schemes and ways of sorting files we needed some sort of uniform naming of files and directories. We decided on the ever so nice /Artist/Album/01_Title.mp3. But since we have a lot of mp3's, this seemed a daunting task.&lt;/p&gt;

&lt;p&gt;In comes bash. 6 lines of code is all it takes.&lt;/p&gt;

&lt;pre name=&quot;code&quot; class=&quot;bash&quot;&gt;
#!/bin/bash
end=&quot;/destination/dir/of/mp3s&quot;
find -type f -name *.mp3 -print0 | while read -d  $'\0' file; do
        mkdir --parent &quot;$end&quot;/&quot;$(mp3info -f -p %a &quot;$file&quot;)&quot;/&quot;$(mp3info -f -p %l &quot;$file&quot;)&quot;
        mv &quot;$file&quot; &quot;$end&quot;/&quot;$(mp3info -f -p %a &quot;$file&quot;)&quot;/&quot;$(mp3info -f -p %l &quot;$file&quot;)&quot;/&quot;$(mp3info -f -p %n &quot;$file&quot;)&quot;_&quot;$(mp3info -f -p %t &quot;$file&quot;)&quot;.mp3
done
&lt;/pre&gt;


&lt;p&gt;The small program mp3info is used to extract id3 tags from the files. (Fortunately they are entered for almost all files). I am not the greatest bash-hacker in the world, so there might be a better way to do this. But I have tested this, and it works, and is quite fast.&lt;/p&gt;

&lt;p&gt;If you know of a better way to do this, please comment. I would love to learn.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>5 Easy Steps to Connecting to Webdav at Login</title>
   <link href="http://www.clauswitt.com/5-easy-steps-to-connecting-to-webdav-at-login.html"/>
   <updated>2009-03-12T15:40:32+01:00</updated>
   <id>http://www.clauswitt.com/5-easy-steps-to-connecting-to-webdav-at-login</id>
   <content type="html">&lt;p&gt;I have several computers from which I access my online webdav server, where I save documents and other things, that I require to have access to at all times (when I'm online). For some reason I could not get my macs to automatically login to the webdav server when I logged on to the mac. But I found a way, here are the 5 easy steps to make it work.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Create a applescript containing&lt;/strong&gt;
try&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;mount volume &quot;http://webdav.yourserver.com&quot;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;end try&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Save it&lt;/strong&gt;
Remember to save it as the filetype application.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Test it&lt;/strong&gt;
By doubleclicking your newly created .app file you should get the login prompt from the webdav server.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Automatic login&lt;/strong&gt;
If you want this, you have to save the username/password in the keychain.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Run on startup&lt;/strong&gt;
Drag the application to System Preferences &gt;&gt; Accounts &gt;&gt; Your Account &gt;&gt; Login Items&lt;/p&gt;

&lt;p&gt;Now try and log out, and back in. You should now see your webdav connected and ready to roll.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Manifesto for Software Craftsmanship</title>
   <link href="http://www.clauswitt.com/manifesto-for-software-craftsmanship.html"/>
   <updated>2009-03-08T22:32:57+01:00</updated>
   <id>http://www.clauswitt.com/manifesto-for-software-craftsmanship</id>
   <content type="html">&lt;p&gt;This sounds to me like it should be the Mission Statement of any Software Development Company out there.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://manifesto.softwarecraftsmanship.org/&quot;&gt;Manifesto for Software Craftsmanship&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Nothing more to add there really.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Quick Textmate Productivity Tip</title>
   <link href="http://www.clauswitt.com/quick-textmate-productivity-tip.html"/>
   <updated>2009-03-03T11:15:53+01:00</updated>
   <id>http://www.clauswitt.com/quick-textmate-productivity-tip</id>
   <content type="html">&lt;p&gt;Today I found myself needing a bit of Textmate magic. I had a sql-file containing a lot of tables, from some of these I needed all fieldnames in an array. I quickly found that Textmate would be my friend. This is mostly a reminder to myself. (I tend to forget these things somehow).&lt;/p&gt;

&lt;p&gt;I Pasted all the lines with fieldnames from the sql-file to a new text-document in Textmate. Then i pressed option while using the mouse to mark the beginning of each line and then inserting a quote. (Resulting in a quote on the beginning of each line.) I did the same on the other side of the textfields and added a comma as well. The only problem now is that because not all fieldnames are the same length I now have some unwanted whitespace between the end of the fieldname and the closing quote. Enter regexp, and probably the simplest one I ever wrote.&lt;/p&gt;

&lt;pre name=&quot;code&quot; class=&quot;regexp&quot;&gt;
[ ]
&lt;/pre&gt;


&lt;p&gt;It simply matches all whitespace in the file. Thus making it easy to use find/replace, and replace the whitespace with nothing. Downside is, all the time I saved using this technique has been used to write this blog post. :-)&lt;/p&gt;
</content>
 </entry>
 
 
</feed>
