<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
	<channel>
		<title>Claus Witt</title>
		<description>Software and web developer</description>
		<link>http://www.clauswitt.com</link>
		
			<item>
				<title>How to do a Regular Expression Search Replace with Case Shifting In TextMate</title>
				<description>&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;
</description>
				<published>Tue Feb 07 00:00:00 +0100 2012</published>
				<link>http://www.clauswitt.com/How-to-do-a-Regular-Expression-Search-Replace-with-Case-Shifting-In-TextMate.html</link>
			</item>
		
			<item>
				<title>JavaScript Module with Global Scope Removal</title>
				<description>&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;
</description>
				<published>Thu Jan 26 00:00:00 +0100 2012</published>
				<link>http://www.clauswitt.com/JavaScript-Module-with-Global-Scope-Removal.html</link>
			</item>
		
			<item>
				<title>Removing Unused git branches Automatically</title>
				<description>&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;
</description>
				<published>Mon Jan 23 00:00:00 +0100 2012</published>
				<link>http://www.clauswitt.com/Removing-Unused-git-branches-Automatically.html</link>
			</item>
		
			<item>
				<title>How to Easily Remove a Prefix from 1800+ Files</title>
				<description>&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;



</description>
				<published>Sun Jan 22 00:00:00 +0100 2012</published>
				<link>http://www.clauswitt.com/How-to-Easily-Remove-a-Prefix-from-1800plus-Files.html</link>
			</item>
		
			<item>
				<title>Simple node.js Module to Get Distance Between two coordinates</title>
				<description>&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;
</description>
				<published>Fri Jan 13 00:00:00 +0100 2012</published>
				<link>http://www.clauswitt.com/Simple-node.js-Module-to-Get-Distance-Between-two-coordinates.html</link>
			</item>
		
			<item>
				<title>A zsh function to Add Last Parameter of Last Command to git</title>
				<description>&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;



</description>
				<published>Mon Jan 09 00:00:00 +0100 2012</published>
				<link>http://www.clauswitt.com/A-zsh-function-to-Add-Last-Parameter-of-Last-Command-to-git.html</link>
			</item>
		
			<item>
				<title>A Simple Create New Blogpost Script</title>
				<description>&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;
</description>
				<published>Sat Jan 07 00:00:00 +0100 2012</published>
				<link>http://www.clauswitt.com/A-Simple-Create-New-Blogpost-Script.html</link>
			</item>
		
			<item>
				<title>The How and Why of my Move to Jekyll</title>
				<description>&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;
</description>
				<published>Fri Jan 06 20:45:00 +0100 2012</published>
				<link>http://www.clauswitt.com/the-how-and-why-of-my-move-to-jekyll.html</link>
			</item>
		
			<item>
				<title>Per Package Unit Testing in FLOW3 using PhpStorm</title>
				<description>&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;
</description>
				<published>Thu Nov 24 08:37:09 +0100 2011</published>
				<link>http://www.clauswitt.com/per-package-unit-testing-in-flow3-using-phpstorm.html</link>
			</item>
		
			<item>
				<title>A Simple ViewHelper For FLOW3</title>
				<description>&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;
</description>
				<published>Tue Nov 15 14:56:22 +0100 2011</published>
				<link>http://www.clauswitt.com/a-simple-viewhelper-for-flow3.html</link>
			</item>
		
	</channel>
</rss>
