<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

  <title><![CDATA[Jacques Mattheij]]></title>
  <link href="http://jacquesmattheij.com/atom.xml" rel="self"/>
  <link href="http://jacquesmattheij.com/"/>
  <updated>2013-04-25T23:19:28+02:00</updated>
  <id>http://jacquesmattheij.com/</id>
  <author>
    <name><![CDATA[Jacques Mattheij]]></name>
    <email><![CDATA[j@ww.com]]></email>
  </author>
  <generator uri="http://octopress.org/">Octopress</generator>

  
  <entry>
    <title type="html"><![CDATA[How to go bankrupt]]></title>
    <link href="http://jacquesmattheij.com/how-to-go-bankrupt"/>
    <updated>2013-04-25T11:00:00+02:00</updated>
    <id>http://jacquesmattheij.com/How-to-go-bankrupt</id>
    <content type="html"><![CDATA[<p>It&#8217;s fairly rare that I can write about the jobs I take on, this one is an exception to that rule and there are some lessons here that can help any entrepreneur, even the ones that are doing well. This is a tale about trust and growth, it has a very unfortunate ending.</p>

<p>Going bankrupt is exceptionally easy if you go down one particular route. You simply buy something for about the same or more than you&#8217;re selling it for and you forget to factor in all your variable costs and/or overhead.</p>

<p>Every now and then I end up advising companies or executives of companies that have hit a rough patch. Usually these stories end quite well and everybody lives to tell the tale of a close call but in this particular case there was nothing left to be done other than to pull the plug on the patient. That hurts. Here is how it happened.</p>

<p>A services company was growing like crazy. The CEO and CFO had bought the company several years earlier using an earn-out construction and they had been growing the business revenue wise substantially, double digit growth for three consecutive years.</p>

<p>The market the company operated in is highly competitive, margins are slim and customers are using their knowledge of the market and the players to negotiate agressively in order to get the best deal. In a market like that - very price sensitive - you have to be extremely aware of what your exact position is because the difference between making money on a deal and losing money on a deal is small but very significant.</p>

<p>In 2010 the company made a substantial profit, in 2011 the profit was still there but lower, in 2012 the company lost substantial money. The reason I got called in was because there were some irregularities with one of the current accounts but as I gained more insight into the situation I realized that the company was probably doomed. We moved for a scenario where the company would get temporary relief from their obligations in order to restructure but after a few days more it turned out that that was so unlikely to be successful that they filed for bankruptcy.</p>

<p>This is a pretty tough affair, bankruptcy is a bad thing to happen to a company for many reasons, not in the least because as executives you can be held liable for mis-managing the company if there are substantial reasons to suspect this. But in this particular case it was unavoidable, the company had entered into several expensive contracts increasing its overhead, had been bidding so aggressively on various deals in order to increase their turn-over that they lost sight of the bottom line and were actually losing more money on the deals they closed than they were making in the first place, once all the variable costs and overhead were accounted for.</p>

<p>But because the CFO was asleep at the switch and the CEO did not check up on him (trust is a good thing, but verify if you value your company and if you take your responsibilities serious) and probably did not have the financial chops required to do his job properly this wasn&#8217;t noticed until it was (much) too late.</p>

<p>So, in spite of double digit growth they ran out of room to manoeuver when the cash reserves built up during the years when they were still making money on the majority of their contracts ran out.</p>

<p>The lessons you can learn from this tale are quite simple in principle but can be hard to apply in practice:</p>

<ul>
<li>Make sure you know what your counterpart is doing if you share the responsibility for the company</li>
</ul>


<p>In this particular case, the CEO is an extremely nice, somewhat overly trusting man. By keeping him out of the loop the CFO was able to hide the problems (including some irregularities involving private accounts and the corporate current account) from his partner. This allowed the situation to continue to the point where there was nothing to be done about it.</p>

<ul>
<li>Make sure you factor in <em>all</em> your costs when bidding on a contract</li>
</ul>


<p>The slimmer the margins and the more competitive the field you are operating in make sure that you know what your walk away bid is, in other words, what you <em>have</em> to make on a deal for that deal to be profitable. Turnover is meaningless if more business decreases your profitability, the whole idea is that by increasing turnover you gain some advantages due to economies of scale working to your benefit. If the economies of scale turn against you then you are killing your business by making it grow. Know your business inside out so that you can make the right decisions.</p>

<ul>
<li>If you are not able to function in a certain role, don&#8217;t take that job</li>
</ul>


<p>A CEO should at a minimum be able to read a balance sheet, work through a liquidity prognosis and to check up on other parties actions on behalf of the corporation. He or she should be able to work fairly well under pressure and should be able to read and understand basic contracts and to estimate the consequences of actions or inactions. You should also be able to understand the exact responsibilities and if applicable the rights that come with the job. Being CEO of a company with close to a 100 employees is not something you should do on a lark or as training on the job, it means that you are indirectly responsible for close to 300 people and you should take such a responsibility extremely serious.</p>

<ul>
<li>when in doubt, get professional, unbiased advice</li>
</ul>


<p>If you are in a situation where you need legal advice make sure that <em>you</em> are the person paying the lawyer and pick a lawyer that is not in any way associated with one of the other parties. A lawyer that you do not pay is <em>not</em> working for you.</p>

<ul>
<li>if you receive questionable advice then this goes double</li>
</ul>


<p>If you receive advice that you find either curious or questionable then get a second opinion immediately, igorance of the law is a very bad defense (in fact, it is no defense at all) and a lawyer that is working just for you will be able to quickly dispell any doubt about whether or not a certain activity is (a) in the interest of the company, (b) in your own interest and (c) legal. Especially the latter can get you in hot water, more so if a company should default and you were at the helm.</p>

<p>Bankruptcy is something best to avoid, make sure it does not happen to you, lest you end up being witness to an asset sale and possibly subject to a personal liability to boot.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Love To Learn]]></title>
    <link href="http://jacquesmattheij.com/Love-To-Learn"/>
    <updated>2013-04-23T11:00:00+02:00</updated>
    <id>http://jacquesmattheij.com/I-Love-To-Learn</id>
    <content type="html"><![CDATA[<p>My lucky break was not finishing my education. It&#8217;s probably hard for an outsider to see the upside in having your home situation implode just when school starts to get serious, to go to work for a boss doing some menial job in your teens, no diploma, no future as far as anybody could see. But this helped me in so many ways that I really should be grateful for it.</p>

<p>For one, the guys that I worked with in the mailroom were a pretty rough bunch, but they also were very fair and wouldn&#8217;t play favorites just because I was a scrawny kid. On my first day there - which I was pretty sure would be my last - I held them all up. Those guys were ridiculously strong, they made it look so easy. It doesn&#8217;t help when the mailbags that you need to haul around and sort weigh more than you do. But rather than doing my work for me or helping me directly the men in the mailroom helped me in a completely different way. They simply stood by chitchatting waiting patiently for me to finish my part of the shift. One memorable moment was when I really was about to give up when the shift boss (a guy that was maybe 5&#8217; tall but also just as wide) told me: &#8220;You don&#8217;t have to move that bag in one go&#8221; hinting that if I opened the bag to do it in pieces that would be fine by him as long as it got done. Those bags were so heavy that at times I was convinced they were pranking me by having one nailed to the floorboards.</p>

<p>Not a bad word, no insults. When I was finally done and the last bag was in the truck to be brought to the trainstation they all said their goodbyes and did it all over again the next day. Little by little I got faster, I really owed them that much. Running mail was the easy bit for me, hauling around bags and keeping up definitely was not. It took me 6 months to get to the point where I could say I managed to keep up with the rest, I was never threatened with being fired for being slow or anything, simply the pressure of knowing that everybody is waiting for you was enough to push me. I earned just enough for a bit of food left over after paying rent once I moved to a one-room appartment in Amsterdam. 700 guilders of income, 500 guilders of rent, 200 guilders to live off. It seemed quite luxurious in one way but in another it was very depressing, not being able to save enough for new gear and especially not enough for buying books. Fortunately public libraries were stocked well with books on all kinds of subjects, and my library card saw some pretty intensive use.</p>

<p>So not completing my education (aside from a typing diploma and grade school, later augmented with a driving license) was in a way a lucky break. It gave me a very strong motivation to claw my way out of the situation I was in, it gave me a bunch of ersatz parents that taught me the value of honest hard work and many other things besides. I got to know most of them outside of work as well, repairing their hi-fi gear and televisions, and I got to see how a bank worked from the inside. Being a mail runner has one huge advantage over any other job which is that you get to know <em>everybody</em>, from the board of directors all the way to the print shop. Little by little I started to figure out by traffic analysis how the various departments interacted with each other.</p>

<p>I really can&#8217;t help it. Give me any piece of machinery, a computer program or a corporation and I have to figure out how it works. Nothing vexes me more than to have something that I can&#8217;t understand or figure out. On my desk a very dog eared &#8216;Essentials of Genetics&#8217; by Klug &amp; Cummings (thanks Marcela!), a book on the construction of lattice grids (Makowski), a book on heat pumps and Stirling engines and yet another on fuzzy logic. By not finishing school I never had a hard line that told me that I was &#8216;done&#8217; with my education, so instead of relaxing after getting my diploma I just kept on reading and learning as much as I could. It simply never stopped, there was no &#8216;now I&#8217;m educated&#8217; feeling. Rather the opposite, with every bit of knowledge you acquire you only realize all the more how much is still missing and blank. And working for a bank gave me lots of opportunities for learning. They had a course (&#8216;NIBE&#8217;) which taught you lots more than what you could infer from moving mail from one department to another, so I worked my way (unoficially) through the course books.</p>

<p>And instead of hating it (like most people doing those courses) I just loved it. Every job I do I see as a paid opportunity to educate myself just a little bit further. What more could you wish for, learn and gain bits and pieces of knowledge, insight into how the world works and get paid for it to boot.</p>

<p>This life probably isn&#8217;t for everybody. The levels of uncertainty (other than the website income there is not much in terms of steady earnings), the lack of a safety-net (a car accident or getting ill would be a real problem) and the continuous pressure to perform have definitely taken their toll over the years, both in terms of stress and in terms of personal relationships that I have messed up. And yet, I wouldn&#8217;t trade it for anything else. I can&#8217;t imagine any other life that would give you so many opportunities to learn about so many different subjects. Another piece of luck is that I never spent a whole lot of time learning things that didn&#8217;t interest me or that did not have practical use. That kept my appetite at a healthy hungry level rather than to turn it into a dislike of learning, like I saw in so many of my school mates and co-workers.</p>

<p>Learning is an addiction, and I&#8217;m hooked on knowledge and I <em>really</em> need that next hit. So if you have any interesting books or knowledge that you intend to keep to yourself better not invite me :)</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[The API Paradox]]></title>
    <link href="http://jacquesmattheij.com/api-paradox"/>
    <updated>2013-04-11T11:00:00+02:00</updated>
    <id>http://jacquesmattheij.com/The-Api-Paradox</id>
    <content type="html"><![CDATA[<p>APIs are great, they allow companies to expose parts of their engine for inclusion into the products of others to increase adoption and to facilitate the development of features and products around a common set of data.</p>

<p>In theory APIs are a win-win, both for the party that exposes the API as well as for the party that uses it and since the mid 90&#8217;s APIs have become more and more common.</p>

<p>API is short for &#8216;application program interface&#8217;. An API defines a fairly rigid (as in, not changing on a daily basis) boundary where two pieces of software (typically, on the web a service and some client software) meet and where data is exchanged based on certain criteria.</p>

<p>In practice though, APIs are a double edged sword, both for the exposer as well as for the user. In this article I&#8217;ll try to outline what the shadowside is of exposing an API, and why this is a potential problem for any users of that API.</p>

<p>When a company first gains traction there often exists a stage where the need to develop software to meet demands greatly exceeds the ability of the company to execute. The bottle-necks are typically it&#8217;s ability to attract talent fast enough, possibly the ability to pay for that talent and/or the ability to plan and execute across a wide enough swath of the problem space to serve all those in need.</p>

<p>Enter the API. An API is then defined that allows others to apply their talent and these others are then given (limited) access to the company data in order to be able to serve a particular need.</p>

<p>So far so good, this situation can persist for quite a while. But sooner or later in the life of every company there comes a time when the bottom line starts to matter more than the interests of outsiders.</p>

<p>Now the API gets turned on its head. Instead of a synergistic device would-be competitors that have become dependant on the company for the API it exposes can be cut off at will or can be acquired for peanuts because of the hold the company has over its API clients.</p>

<p>On top of that any API customer that has created a viable niche has provided the company with free validation of some market segment and unless that API customer is extremely well entrenched in its niche it will be easy to dislodge it by cutting off access and re-implementing whatever was needed to serve that niche. Small time players can be continued to be granted access to the API since they don&#8217;t consume much in terms of resources allowing the company to claim they are more open than they really are.</p>

<p>So the API Paradox has a timing component. A company that just starts out can use an API in order to leverage the developer community to serve markets that it does not have time or resources to serve itself, with an option right of sorts to take over those markets/companies when the time is right and resources permit a change in attitude. It is not healthy to be found in competition with the sole provider of your company&#8217;s life-blood.</p>

<p>If you&#8217;re a developer or start-up and you are basing your corporate future on the data provided by some company keep in mind what the future could very well bring and try to ascertain that in the long run too your interests will be aligned. If you do not heed that then chances are that at some point you will find your precious API access cut off and you&#8217;ll go the way of many before you that thought that API access is a right, instead of a privilege granted in times of plenty, easily withdrawn in times of scarcity.</p>

<p>Warning signs that you are basing your project/product on quicksand:</p>

<ul>
<li><p>You are not paying for the API</p></li>
<li><p>The API is rate-limited and there is no paid option to exceed the limits</p></li>
<li><p>The company that exposes that API is still very young or in a phase of hyper-growth and is resource limited and addressing only a subset of the market they could theoretically serve</p></li>
<li><p>There are no terms of service or there are terms of service that allow the terms of service to be changed without notice and/or API access to be cut off for any reason at all</p></li>
<li><p>Exposing the API does not form a core part of the strategy of the business</p></li>
<li><p>It is possible to create a competing business using that very same API</p></li>
<li><p>The API offers no (or very little) prospect for being monetized in the future</p></li>
</ul>


<p>If one or more of those are true for APIs that are crucial to the operation of your (proposed) business then you had better be very careful and you&#8217;ll need to have a &#8216;plan B&#8217; in case your API access gets cut off at some point in the future.</p>

<p>If your business plan really needs access to certain data then you should at least try to negotiate a solid contract with terms that stipulate how much data you can consume, how much it will cost you and what kind of termination clauses are applicable. Then and only then would it make sense to build a business on someone else&#8217;s API.</p>

<p>If you use API exposed widgets as sugar on your cake then of course none of the above applies but for business critical API usage you have to be fully aware of the API Paradox.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[AppGratis Apple AppStore Appeal]]></title>
    <link href="http://jacquesmattheij.com/appgratis-apple-appstore-appeal"/>
    <updated>2013-04-10T20:00:00+02:00</updated>
    <id>http://jacquesmattheij.com/AppGratis-Apple-AppStore-Appeal</id>
    <content type="html"><![CDATA[<p>In a <a href='http://appgratis.com/blog/2013/04/09/appgratis-pulled-from-the-app-store-heres-the-full-story/'>heartfelt appeal to Apple</a> from AppGratis founder Simon Dawlat we gain insight into the ridiculous situation around Apple&#8217;s appstore review proces.</p>

<p>Seemingly on a whim Apple decided to toss AppGratis&#8217; app from the appstore. A new reviewer is apparently all it takes to endanger the jobs of 45 employees and to kill a product that clearly filled a niche, both on the consumers side (with millions of happy users downloading the application) and on the side of the apps that are being promoted.</p>

<p>For a very long time it looked as though AppGratis got a pass from Apple. Only a scant few days ago Apple approved their new iPad application and - one has to agree with Dawlat here - if it was &#8216;ok&#8217; a few days ago, it should be ok today.</p>

<p>If a new application gets submitted to the review process then Apple has every right to reject that application or to ask the developer to make changes. But once accepted into the AppStore, once established and approved (especially for 4+ years, in the case of AppGratis!) the barrier for a subsequent rejection should be <em>MUCH</em> higher than a simple change of personel. All it takes is for one Apple AppStore reviewer to have a bad hairday and your company could be in trouble and you too could be out of a job.</p>

<p>And even if your product passes under the rules of today Apple can - and does - introduce rules that specifically target certain segments of their ecosystem for annihilation with subsequent selective enforcement of those rules.</p>

<p>Apple handled this in a very unprofessional manner, the CEO of a multi-national corporation not being available instantly (the man was on an airplane) can&#8217;t be a reason to yank an app that has been in the AppStore as long as AppGratis has been.</p>

<p>Apple is acting in a tremendously irresponsible manner here. They are risking alienating the developers that made the AppStore into what it is. If Apple wishes to be left with nothing but hobbyist app developers that create a multitude of fart apps then they should definitely make a few more &#8216;examples&#8217; of successful applications that have carved out a niche in the eco-system. After all, bringing an App to market that has significant back-end logic, that requires the creation of unique content in several languages and that delivers a polished user experience will require a solid team, will require significant cashflow and will likely require that such dedication will be on display over the lifetime of the App. And when new devices are added to the mix they will need to display all of that all over again.</p>

<p>This is not hobbyist territory. By behaving like a schoolyard bully - we do it because we can - and yanking apps willy-nilly developers the world over working for companies in the mobile space are likely reconsidering the choices they have made. Clearly one can not depend on any kind of past approval by Apple to stick.</p>

<p>It&#8217;s like asking for a ruling from a judge, then to use that ruling to build a business on and have the judge yank the carpet out from under you a while later saying they simply changed their minds. Apple has a responsibility here and failed to meet it.</p>

<p>If Apps are rejected initially then that&#8217;s all fine and good. But once approved a subsequent rejection, especially of a popular App such as AppGratis or any other should require several levels of review and clear and open communication with the company before such an App can be subsequently rejected, <em>especially if nothing on the App side had changed</em>. Apple owes that to its users, the mobile space in general and the employees of mobile companies the world over that are currently developing applications for the Apple eco-system. Without such a raising of the bar Apple not only puts AppGratis at risk, but risks a massive walk-out of developers and investors in mobile companies from the Apple eco system.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[available jobs, March]]></title>
    <link href="http://jacquesmattheij.com/jobs-march"/>
    <updated>2013-03-12T20:00:00+01:00</updated>
    <id>http://jacquesmattheij.com/jobs-march</id>
    <content type="html"><![CDATA[<p>I have received a number of requests to find people for IT companies, both in the Netherlands and elsewhere in Europe. If you&#8217;re interested in any of these let me know and I will put you in touch with the company.</p>

<p>Job 1, Location: Amsterdam, Position: CTO/VP of Engineering, mobile cloud gaming network</p>

<p>Job 2, Location: Cyprus, Position: Ruby Developer, gaming</p>

<p>Job 3, Location: Amsterdam, Position: Java/Scala Developer, online travel company (4 positions)</p>

<p>Job 4, Location: Amsterdam, Position: Ruby/Javascript Developer, online travel company (3 positions)</p>

<p>Job 5, Location: Hilversum, Position: tester, PHP &amp; selenium, online video network</p>

<p>Job 6, Location: Uitgeest, Position: PHP developer, ecommerce</p>

<p>Job 7, Location: Uitgeest, Position: Project Manager, ecommerce</p>

<p>Recruiters: please do <em>not</em> contact me because of this posting.</p>

<p>If you fancy any of these please contact me, j@ww.com, full disclosure, some of these companies I have personal experience with, some not, in no way am I going to make money of referring you, directly or indirectly this is just a &#8216;community service&#8217;.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Come and help save posterous from oblivion!]]></title>
    <link href="http://jacquesmattheij.com/come-help-save-posterous-from-oblivion"/>
    <updated>2013-03-12T20:00:00+01:00</updated>
    <id>http://jacquesmattheij.com/come-and-help-rescue-posterous-from-oblivion</id>
    <content type="html"><![CDATA[<p>A couple of years ago I got wind of the fact that geocities was about to die and along with many others I did my bit to save geocities, the site now lives on (or as much as I could save of it) as reocities.com.</p>

<p>At the time I didn&#8217;t think too much of it, a small thing to do really. But over the years, after many <em>thousands</em> of emails from people that are insanely happy that their old webpages, photos of loved ones (sometimes deceased) and tons of other memorabilia have not been lost it became clear to me that this really was something that had to be done. It is incredible how that project has worked out in the long term, right now about 50,000 people <em>daily</em> visit reocities.com.</p>

<p>So, when I heard that posterous was shutting down I figured I&#8217;d try to do the same. The posterous guys have sold their company to twitter and twitter has decided to pull the plug. I made an offer to continue to host posterous.com and all the stuff on it but never received an answer.</p>

<p>Last week I decided I&#8217;d been waiting long enough, time to do something a bit more concrete. Jason Scott and the guys at archiveteam have done a great job at putting together an easy to use VM application that you can download and run, it is literally 3 clicks to join the archive team and to help them to save what they can of the posterous.com archives.</p>

<p>The clock is ticking, there are only 49 days left as of this writing, so any pages that are not saved in the next 49 days will be lost forever. Please come and help the archive team, if everybody that reads this blogpost downloads a few Gs worth of data then we may be able to reduce the size of the next hole in the web!</p>

<p><head>
  <link href="https://fonts.googleapis.com/css?family=Lato:300" rel="stylesheet" type="text/css" />
  <link href="http://jacquesmattheij.com/css/dashboard.css?1359037176" rel="stylesheet" type="text/css" />
</head></p>

<div id="how-to-help-cue">
  <h1>How to help? Run your own ArchiveTeam Warrior!</h1>
</div>




<div id="how-to-help" class="expandable">
   
  <div id="how-to-help-card">
    <h1>Run an ArchiveTeam Warrior on your computer.</h1>

    <p>The ArchiveTeam Warrior is a virtual archiving appliance. You can run it to help with the ArchiveTeam archiving efforts. It will download sites and upload them to our archive &mdash; and it&#8217;s really easy to do!</p>
    <p>The warrior is a virtual machine, so there is no risk to your computer. The warrior will only use your bandwidth and some of your disk space.</p>
    <p>The warrior runs on Windows, OS X and Linux. You&#8217;ll need <a href="https://www.virtualbox.org/wiki/Downloads">VirtualBox</a> (recommended), VMware or a similar program to run the virtual machine.</p>
    
    <p>Instructions for VirtualBox:</p>
    <ol>
      <li>Download the <a rel="nofollow" class="external text" href="http://archive.org/download/archiveteam-warrior/archiveteam-warrior-v2-20121008.ova">appliance</a> (174MB).</li>
      <li>In VirtualBox, click File &gt; Import Appliance and open the file.</li>
      <li>Start the virtual machine. It will fetch the latest updates and will eventually tell you to start your web browser.</li>
    </ol>

    <p>Once you&#8217;ve started your warrior:</p>
    <ol>
      <li>Go to <a href="http://localhost:8001/">http://localhost:8001/</a> and check the Settings page.</li>
      <li>Choose a username &mdash; we&#8217;ll show your progress on the leaderboard.</li>
      <li>Go to the All projects tab and pick a project to work on. Even better: select ArchiveTeam&#8217;s Choice to let your warrior work on the most urgent project.</li>
    </ol>
  </div>

    <p>If you need help or want status updates then you can join #preposterus (note the &#8216;us&#8217;, not &#8216;ous&#8217;) on efnet IRC.</p>

</div>



]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Suffering from depression? Don't do that start-up!]]></title>
    <link href="http://jacquesmattheij.com/depression-dont-do-that-startup"/>
    <updated>2013-02-27T14:00:00+01:00</updated>
    <id>http://jacquesmattheij.com/suffering-from-depression-dont-do-that-startup</id>
    <content type="html"><![CDATA[<p>I hope this post will save some lives.</p>

<p>With some regularity I read articles about some amiable, accomplished and brilliant young kid that decides to end their life in the start-up scene. Invariably they&#8217;ve managed to come a very long way along some perceived curve of success and then there is a snag. Either they plateau in their growth, the start-up tanks or there is some other hiccup that causes trouble.</p>

<p>To someone who isn&#8217;t suffering from depression such things can be quite devastating. Investing a significant portion of your person (your &#8216;ego&#8217;), of your alloted time on this pale blue dot, investing a large amount of savings or even other people&#8217;s capital (family perhaps), and then losing a large chunk of it - or even all of it - is harsh. It&#8217;s so harsh that those that fail in their endeavour typically need a long time to recharge to try again, if they ever try at all.</p>

<p>But when you are prone to depression chances are that you will find yourself in the kind of funk the likes of which you&#8217;ve never seen, and which you may find too much to deal with. Start-ups are - for want of a better word - an extension of their founders. If a start-up fails, then to some degree it may feel like you yourself have failed, even if that is absolutely not the case. This is the kind of introspection that can be really difficult to deal with. The more you&#8217;re associating yourself with the company that you&#8217;ve founded, the more money you took from friends, family and investors, the more in the public eye your company is, the more you will pressured to succeed. And then if your company should fail or even simply plateau the pressure can become overwhelming - even if at a rational level you know that such failure is actually to be expected, and that there is no shame at all in this failure.</p>

<p>It is precisely because of this that you should avoid (co-)founding a start-up like the plague if you are depression-prone.</p>

<p>I can name off the top of my head five people all in their twenties or early thirties that ended up taking their own life because they found themselves at the focal point of simultaneous significant negative forces related to the ideas they were executing on. There are many more similar cases, I just don&#8217;t remember their names because I&#8217;ve had no interaction with them, and I&#8217;m not elaborating on these five because that will re-open old wounds. Rationally they did not have a single good reason between them to end things that way. They left huge gaping holes, a tremendous amount of grief and shocked surroundings behind. In some cases nobody ever even suspected that they took their troubles so seriously (or even that there was trouble), keeping up outward appearances of being cheerful and happy, right up to the moment when they took their lives.</p>

<p>If you&#8217;re prone to depression and you are in a start-up as a (co-)founder or if you are considering starting a start-up please, please, please don&#8217;t do it. Please get out in an orderly fashion if you&#8217;re already on-board, please don&#8217;t even think of starting a start-up if you feel that this applies to you.</p>

<p>Please get yourself a great job at some stable company, a research position somewhere, or any one of a great multitude of ways in which you can succeed in life and have impact - without being subjected to the stresses that start-up life will inevitably bring. And please get help to deal with your depression (these things are never easy, and never simple). But for the love of $DEITY don&#8217;t get into start-ups as a founder, and if you&#8217;re in right now <em>get out while the getting out is good</em>. Only you know your little secret, only you have the means to chart your future paths. Purposefully, maybe even defiantly going exactly where you shouldn&#8217;t be will only lead to trouble for all involved.</p>

<p>I&#8217;ve had just about all I can take of young and brilliant people ending their lives because they couldn&#8217;t cope with some perceived failure. Failure is the norm in start-up land, and that means that you have to have the mental disposition that shrugs off failure and treats it like just another step on the way to success. That&#8217;s not an optional item, or a nice to have, it is essential, <em>a must have</em>.</p>

<p>For some reason start-ups are a magnet for people that suffer from depression. As though by going up the Eiffel tower it will magically make your fear of heights go away, maybe to harden yourself against it. But start-ups are nothing at all like the Eiffel tower, standing there, serenely still while you practice your mastery by going up the stairs one at a time. Start-ups are more like rodeo rides, doing their damndest not to give you a thrill ride, but to rough you up and spit you out. Do not place yourself knowingly in positions or situations where you will have to deal with extreme stress if you know that you find it hard to deal with extreme stress!</p>

<p>Start-ups are not a place to get therapy, or to learn to deal with (perceived) failure if you&#8217;re prone to depression. The failure rate of start-ups being what it is, if you are suffering from depression or if failure is not your thing then start-ups are the very last place that you should be. Start-ups tend to focus a lot of energy - sometimes extremely negative, but even success is extremely stressful - on the individuals running them. And if you don&#8217;t have a natural disposition to stand at the nexus of something like that without burning up like a fuse that has to conduct too much current then you shouldn&#8217;t be there in the first place. The end result is all too predictable.</p>

<p>No start-up is worth a life, especially not yours.</p>

<p>&#8211;</p>

<p>tx Kai!.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Domain Knowledge or a lack thereof]]></title>
    <link href="http://jacquesmattheij.com/domain-knowledge-or-a-lack-thereof"/>
    <updated>2013-02-22T14:00:00+01:00</updated>
    <id>http://jacquesmattheij.com/domain-knowledge-or-a-lack-thereof</id>
    <content type="html"><![CDATA[<p>I believe that a lack of domain knowledge is the root cause of a lot of very bad software that gets developed and I think that it is up to computer programmers and their managers to deal with this. Acquiring domain knowledge is an essential component in the development of software that really works well for its users. A programmer that has to automate a warehouse but that has never picked an order and doesn&#8217;t have a clue about actual logistics is going to be writing far less effective software than someone that has done a few shifts on the floor. And that&#8217;s purely practical knowledge in a field that is reasonably well understood. There are many other examples where the effects of the differences between someone automating some solution with or without domain knowledge would be far harder to see.</p>

<p>Programming and systems analysis are like architecture in many ways. An architect has to have a reasonably good understanding of what a customer is going to do with a building if they&#8217;re going to do a good job of designing that building. An enclosure for a machine would have to match the guts of that machine just like a building encloses a company. Having the loading docks of a warehouse on the fourth floor is usually not what you want.</p>

<p>Software is much more intertwined with the institution commissioning it and the people using it than any building ever will be, with the exception of engineered structures such as the CERN ring. If all should fail a building, no matter how mismatched can always at least be used for storage. I&#8217;ve seen fire-stations converted to houses and industrial buildings converted to office space. But software that doesn&#8217;t match is unusable.</p>

<p>Imagine architects designing a fire station without consulting with fire-men and fire station chiefs and without understanding the basic operations of a fire-station and how the situation develops when a fire is called in. When utility matters, domain knowledge is very valuable.</p>

<p>Over the years I&#8217;ve worked on a large number of projects in a variety of industries. One of the things that I absolutely love about software is that it is everywhere, there isn&#8217;t an industry that doesn&#8217;t have software component in it nowadays. And for each and every one of those projects there was a large amount of domain knowledge to acquire. That&#8217;s hard work, and you probably can&#8217;t put it on the bill but it is an absolute requirement if you want to deliver a half decent product.</p>

<p>What that translates into is that when I worked for a company making CNC equipment that I learned how to use a mill and a lathe manually. Only when I understood how you work metal by hand did I reach a level where I could confidently write software to work metal by numerical control.</p>

<p>Working for a manufacturer of sails I soaked up piles of books on sail making and sailing and I actually spent some time on a boat. Half the library on that subject was digested for breakfast, lunch and dinner. Add another helping on fabrics and their properties and on stitching and cutting techniques! Knowledge like that helps a lot when you have to lay out your &#8216;panels&#8217; on the cloth, and then afterwards when those panels have to be combined to form a sail. In that particular case I took great care to make sure that the panels had their major lines of stress run along the threads in the weave, even if that meant that we might get one or two fewer panels from a piece of fabric the resulting sail would be stronger and it would last longer. Quantity or quality is a business decision and if you&#8217;re not aware of this then you might accidentally make that decision for your employer without anybody being aware that a decision has been made. The software used the exact same terminology that the sailmakers used, and used it consistently.</p>

<p>When working for a company that did colour calibration software and pattern checking I read and learned about colour spaces and imaging hardware. All kinds of history there, from manual inspection to semi automatic inspection all the way to the present day. Industry is funny that way, you start out with a simple assignment (can you read values from this sensor) to sucking you in into a project that has a century of history behind it with lifetimes of domain knowledge that you need to absorb before you can even begin to properly automate the solution to some problem. It is also funny in that it all ends with knowledge about physics.</p>

<p>If there is a message in this blog post then it probably is that if you are currently working on a project that requires domain knowledge but you don&#8217;t have any of that knowledge yourself that you should probably take the shortcut of stopping your work and to first educate yourself about the field that you are operating in, and <em>then</em> to return to whatever problem you&#8217;ve been assigned to solve.</p>

<p>Programming without domain knowledge for a discipline that is steeped in it is like an architect designing a building without knowing its true purpose.</p>

<p>If you are working in some industry spend time on the shop floor, become a user of your software if there is any opportunity to do so. It will make you a far more effective programmer and it will reflect itself in the usability and the perceived quality of your software. The <em>combined</em> knowledge about the domain you are operating in and your IT knowledge is far more valuable than any of the two in isolation.</p>

<p>Domain knowledge is not optional, it is essential. The one common factor between the failed projects I come across is that they were automated by people that had little love for and little or no knowledge of the domain they were operating in. Companies and institutions should make time available to get their IT staff up to speed on the inner workings of the company and should allow their IT staff to be embedded on the floor for a taste of what the real world looks and feels like.</p>

<p>So stay clear of the trap of little or no domain knowledge and get your hands dirty, learn to see through your users eyes by acquiring the knowledge associated with the field you are working in, don&#8217;t treat IT as a world that only communicates with its users through tickets and requirement documents, step down from that ivory tower.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[how to make a quick buck]]></title>
    <link href="http://jacquesmattheij.com/how-to-make-a-quick-buck"/>
    <updated>2013-02-21T14:00:00+01:00</updated>
    <id>http://jacquesmattheij.com/how-to-make-a-quick-buck</id>
    <content type="html"><![CDATA[<p>In 1992 I had bought a license to a little known real time micro kernel based operating system called QnX.</p>

<p>QnX was a pretty interesting development for me, it was the first time that I used an OS that used message passing for its internals and that ran the file system, the network system, the scheduler and all other i/o as separate processes. Quirky, but interesting and an opportunity to learn. Because QnX was mostly used in Industry I was a pretty strange customer, a single person shop that bought a license stood out as an oddity for the importer of the software, LS Technologies in the dutch harbour town of IJmuiden.</p>

<p>After a couple of visits there to talk over strategies on how to solve certain problems using QnX, one fine monday morning I got a reasonably panicked phone call from the owner of the QnX import business, his brother had a bug they couldn&#8217;t solve and he thought maybe I should go there and have a look.</p>

<p>So I drove to IJmuiden in my rickety old car (a 25 year old Citroen DS that was just as likely to deliver you at your destination as it was likely to get you stranded), and found myself in front of an office building at the waterfront.</p>

<p>Housed there was a company that brokered cargo capacity for a very large percentage of the worlds shipping companies. If you wanted to ship 12 containers from Shanghai to Boston you made a request to your shipping broker. He would then send a telex to the company in IJmuiden which would then fan out your telex to a few hundred shipping companies within a specified amount of time. That telex would then be responded to within another specified amount of time and the bid criteria were evaluated and the results would be sent back to the broker. On a good monday morning a million or so telexes would not be an exception.</p>

<p>After arriving there I was ushered into a room with a pretty tense atmosphere. Four guys in suits stood behind a single man behind a computer typing frantically at the keyboard, sweating profusely (and it wasn&#8217;t all that warm). &#8216;Who is Jan?&#8217;, I ask.</p>

<p>The guy behind the keyboard looks up and says &#8216;You&#8217;re the guy my brother sent, the &#8216;whizz kid&#8217;?&#8217;.</p>

<p>So he jokingly tells me that his brother suggests I can fix this, he doesn&#8217;t believe it, but he&#8217;s willing to give me a chance if I can fix it in the next five minutes. It&#8217;s pretty clear that he feels he&#8217;s wasting his time and that he wants to get back instantly. The four suits stand aside for a bit so I can get closer to the screen and the keyboard. So I ask him to explain the situation.</p>

<p>He goes: &#8220;it&#8217;s worth 2500 guilders on the spot if you solve this problem we&#8217;re having, this morning at 8 all our systems froze. Yesterday we did a huge update, tested everything and it looked pretty good. We have our own home built message switch on top of QnX, the whole thing is a large constellation of C programs, yesterday it worked flawless, now it is a total lock up, and we can&#8217;t find the cause&#8221;.</p>

<p>So I spent a few minutes interviewing the guy and then did one thing, I typed &#8216;date&#8217; on the command line. And it came up with <em>yesterdays</em> date, whereas all the messages that are being queued are set to be transmitted today&#8230; The system took each and every message as being embargoed. What had happened is that someone unplugged the box and plugged it back in again. Somehow the bios clock must have been set to the wrong date &amp; time (no NTP) and when it came back up again it simply used the wrong date. Whoever installed the machine set the date properly the last time after boot but never bothered to update the system hardware clock.</p>

<p>The four guys in suits were laughing pretty hard and relieved. &#8216;Quick money!&#8217;, one said, and another started teasing Jan about having to pay up and make good on his promise.</p>

<p>They were so focused on the big software change they had pushed yesterday that they completely forgot the most basic check. So he went to the bank, got me 2500 guilders in cash (I&#8217;d never even seen a thousand guilder note before that day) and gave it to me saying &#8216;win win&#8217;.</p>

<p>Good guy. No, great guy. We ended up working together for years, I became lead dev on the project at some point and we are still in contact, though he is retired now.</p>

<p>When you&#8217;re looking for a bug it&#8217;s terribly hard to not get bogged down in details at the expense of seeing the bigger picture. An outsider doesn&#8217;t have those details so that helps tremendously. The lesson I took away from that day is that when I&#8217;m stuck I ask an outsider.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Disqus bait and switch, now with ads]]></title>
    <link href="http://jacquesmattheij.com/disqus-bait-and-switch-now-with-ads"/>
    <updated>2013-02-14T14:00:00+01:00</updated>
    <id>http://jacquesmattheij.com/disqus-bait-and-switch-now-with-ads</id>
    <content type="html"><![CDATA[<p>Looking at the site earlier today I suddenly noticed a couple of links to sites that I would <em>never</em> ever think of endorsing through my blog.</p>

<p>A &#8216;what is this&#8217; link explained that this was disqus&#8217; way to thank me for using their comment system, a chunk of my webpage in between the comments section and the article body was claimed in order to attend visitors to my website to interesting content which they claim I &#8216;recommend&#8217;. I do no such thing.</p>

<p>Here is what it looked like:</p>

<center>
<img src='http://jacquesmattheij.com/images/disqussnap.png'>
</center>


<p>This is really not nice. Those links are indistinguishable from the links on the left hand side which are links inside the blog, so it doesn&#8217;t really stand out as an advertisement, it makes my site look stealthy and sneaky. <em>IF</em> I would place advertising on my site it would certainly stand out and be labelled as such. Stealthy advertising is one of the least nice ways of advertising on a site, the end user will think that such advertising is an endorsement by the site owner rather than a paid spot, and the word recommended increases that perception.</p>

<p>Apparently somewhere in December disqus decided that they could pull this stunt without an active alert to the website owners that use the disqus plug-in. There is a degree of trust between a SAAS or plug-in provider and the user that the offering will not be changed in important ways without active notification, and that changes will default to &#8216;off&#8217;. That&#8217;s called grandfathering and it is one way in which you can show those users that helped you to grow that you appreciate the relationship.</p>

<p>The fact that disqus holds on to the comments is a sign that I trust them to do the right thing with my data, I absolutely never expected them to suddenly claim a chunk of my pages for advertising purposes, especially without notifying me first. That I am apparently entitled to a share of the take makes no diffence to me, if I want advertising on my blog I will put it there myself, and if I decide to endorse another website by linking to it that is <em>my</em> decision, not theirs. I do not &#8216;recommend&#8217; any of these links and I don&#8217;t think I need to be surprised by finding out that I apparently endorse a bunch of companies.</p>

<p>Naming this euphemistically a &#8216;discovery&#8217; feature doesn&#8217;t do much either, it&#8217;s advertising, so call it advertising, calling it a recommendation and making it blend in is illegal in lots of places, and even if it isn&#8217;t illegal it is not what you should do. Advertising should be clearly labeled as such, and it should stand apart from the content of a site.</p>

<p>So, bye-bye disqus, no more comments on my blog.</p>

<p>postscript: some people claim that the blog owners themselves do not see the ads, I am currently not logged in to disqus and not at my normal location so maybe that is why I suddenly saw the ads where there were none before (including yesterday). If that is true it is a lot nastier than I already thought it was.</p>

<p>postscript2: <a href='http://news.ycombinator.com/item?id=5220072'>Hacker News Comment thread</a></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Computers I have known]]></title>
    <link href="http://jacquesmattheij.com/computers-I-have-known"/>
    <updated>2013-02-14T10:00:00+01:00</updated>
    <id>http://jacquesmattheij.com/computers-I-have-known</id>
    <content type="html"><![CDATA[<p>Over the years I&#8217;ve owned quite a few computers. An endless series of PC compatibles that mostly differed from each other in CPU speed or memory capacity. But before the PC era computers were a bit different in that they differed vastly from each other. The advent of the PC homogenized personal computing to a large extent, this is now due to the proliferation of mobile platforms and various tinkerer devices (Raspi, Arduino, etc) changing again but for the longest time it seemed as though x86 was what computing was all about.</p>

<p>The very first computer that I owned outright was a TRS-80 pocket computer. It was actually manufactured by Sharp and marketed by Radio Shack in the USA and Tandy in Europe. I&#8217;d befriended a number of Tandy store managers in and around Amsterdam, they let me play with the bigger machines so when I&#8217;d finally delivered enough papers and repaired enough TVs to buy a computer it was a fairly natural decision to get a TRS-80 of some kind and at 549,- guilders it was just within reach. The paper route was pretty steady income, the TVs mostly hit and miss (scan the garbage on wednesdays and fridays for likely candidates for fixing up or parts, then sell the TVs through classified ads for 25 guilders a piece). But eventually I got there and my first computer was mine. I still have it and it still works!</p>

<p>A cassette interface was another 150 guilders or so so I ended up writing out all my first programs into a copybook. 2K of RAM isn&#8217;t a whole lot so most programs were under a hundred lines or so.</p>

<p>The next step up was a pretty big one. From the pocket computer I went on to a &#8216;dragon 32&#8217;. The dragon was a clone of the TRS 80 color computer, it had an interesting mix of hardware and software, with the software doing the job where other computers of that time would have used a piece of hardware. For instance, the sound interface and the cassette tape interface were entirely in software. This taught me a lot about timing, phase locked loops in software and serializing memory to tape and back again. I fixed a friends computer (burned out RAM chip) and we realized that the chips were 64 Kbit x 1, and there were 8 of them. So our &#8216;dragon 32&#8217; was really a dragon 64! The 6809 chip that powered it could address 64K, the memory was laid out with 32K of RAM in the low part, then 16K of ROM and then another 16K of ROM + peripherals in the final portion. The controller could bank switch each 16K block between ROM <em>and</em> between RAM, an undocumented feature. We found out how to move the BASIC rom to RAM and had endless fun documenting and modifying the BASIC interpreter using 6809 assembly.</p>

<p>Because I couldn&#8217;t afford a disk drive I wrote a disk simulator that would seek to a specific spot on the tape and then hit the &#8216;stop&#8217; button on the cassette drive, then switch to record or play mode depending on whether I wanted to read or write a block. Auto-reverse cassette recorder doubled the storage space available :) I&#8217;m pretty sure Sony never foresaw that putting electrical push-buttons on their cassette recorders instead of the usual piano keys would allow some crazy dutch kid to use them as random access storage.</p>

<p>The dragon could interface to a TV or, if you fiddled around a bit with it to a monitor. I scavenged a &#8216;real&#8217; monitor from a studio TV camera that I found in a dumpster, an old tube driven beast with a super sharp 8&#8221; black and white display. It kept losing sync as it warmed up but it had a ton of thumbwheels to adjust Hsync, Vsync and so on. Especially in winter this was lots of fun since the room I lived in didn&#8217;t have any heat. Effectively that old tube monitor was both my screen and my heater :)</p>

<p>My friend Henri and me had the same machine, we&#8217;d write assembly programs and then we&#8217;d call each other and transfer our code in &#8216;hex&#8217; by typing it in line by line on the other end with a checksum to make sure we had not made any mistakes. Human modems!</p>

<p>Then came the KIM-1. In many ways this was a huge step down from the dragon. The KIM-1 was a very barebones computer, basically nothing but a board with a couple of 7 segment displays and a keypad that wouldn&#8217;t look bad on a calculator. The KIM-1 had only a few hundred bytes of memory and a 6502 CPU. This was interesting because it allowed me to learn 6502 assembler. Tape interface was through an FSK chip. What&#8217;s funny is that this was such a restrictive environment that you ended up having to be extremely creative in order to do anything useful at all.</p>

<p>Ever tried to play &#8216;snake&#8217; on a couple of 7 segment displays?</p>

<p>Next up, one of my big loves, the BBC micro model &#8216;B&#8217;. The &#8216;beeb&#8217; as it was known at the time was an absolutely amazing machine. Excellent hardware build quality, a switching power supply, several rom slots which you could use to install software available at boot time (exmon, word and a ton of others). What really set the BBC apart from the rest was the language that came with it, Acorn Soft structured basic. A basic which - unlike other basics at the time - allowed you to define functions and procedures by name rather than by line number. This opened up the world of structured programming for me and I distinctly remember that resounding <em>click</em> when I got it. Suddenly I could write programs several times larger without getting bogged down. Names are so much easier to remember than line numbers, and it made it much less of a chore to renumber a programs lines. (remember the renum command and how you had to re-set your whole internal symbol table about what lived where? No? lucky you!).</p>

<p>Mass storage ended up being two 160K teac 5 1/4&#8221; floppy drives, and the internal memory was expanded using a thingy called a &#8216;solidisk&#8217; to 128K, using a technique called bankswitching. Every one of the 16 rom slots could be paged in for read or write into a 16K segment of the memory map.</p>

<p>After the BBC micro I moved on to the Atari ST. The ST was a serious step up from the 8 bit era. The Motorola 68000 that powered it could address a lot more memory. The initial run of the ST (the 260) had 256K of ram, then the 520 came and after that the 1040 with a full meg of RAM. That was an amazing amount of memory for that time and it seemed as though I would never write a program that would fill it all. (this didn&#8217;t take long, Jenny Yips laws of computing have held true over the years: eventually computer programs will fill every cycle, every byte of RAM and every bit of secondary storage that you&#8217;ve got). The ST came with something else as well, it had a hard drive interface and you could use this to connect a small selection of 5 1/4&#8221; hard disks to it. I eventually got a 20M hard disk and bought a C compiler. This bootstrapped my career as a free lance programmer and I proceded to write computer games profesionally for a studio in Leiderdorp (Aackosoft, long since bankrupt, two titles that I wrote that shipped were &#8216;FlightDeck&#8217; and &#8216;Indy 500&#8217;.).</p>

<p>After the ST there was a brief period where I used an Acorn Risc Machine, but since it was a pre-production demo unit and it took forever for the machine to pick up more steam in the marketplace I ended up abandoning it. This was a real pity because it was an extremely powerful computer for the day, the chip that powered it (the ARM) is no used in countless mobile platforms and has survived where lots of others have not.</p>

<p>Next up, the PC era. I worked for a bank for a bit and got my first introduction to PCs there. The first PCs seemed quite underpowered compared to the computers that I&#8217;d been using and for the longest time I didn&#8217;t get what all the fuss was about. Even though the ST only had a megabyte of RAM the CPU was already using larger registers than the CPU in the PC and it could address that megabyte without resorting to bank switching or other tricks. But PCs got better with every new generation of CPU and by the time the 286 came out I got an el-cheapo mother board from some taiwanese manufacturer and a &#8216;hercules&#8217; graphics board. A bit more scrounging got me another drive (a Seagate 40 MB unit) and this eventually gave me enough experience to start offering my services as a PC programmer as well. This was important because economically speaking the ST was doomed forever to be a &#8216;game computer&#8217; (though you&#8217;d be surprised to see what we did with it, including a full CAD-CAM program directly driving lathes and mills!), and the PC was the choice of just about every business.</p>

<p>Programming the PC (after the ST with its linear memory space) really felt like a step back in many ways. But over time it got better, and after I discovered the QnX operating system it really came into its own. I wrote tons of software for the PC platform either for Windows or for QnX. Cad systems (for instance, for classical sail designs), process control, a whole suite of software around the idea of digitizing pictures, printing them on credit cards and distributing these (you probably have a descendant of that system in your pocket right now), editors, database applications, a good chunk of a message switch for telex messages used to broker shipping capacity and so on, and finally my own 32 bit QnX clone called &#8216;Unite!&#8217;, a multi-tasking multi-user operating system with built in networking and primitive clustering capabilities.</p>

<p>Around the time the world wide web launched I used SGI machines for several years. IRIX, SGI&#8217;s version of Unix was a really nice implementation and was quite fast. Hardware accelerated graphics meant that you could do reasonably complex 3D scenes with acceptable frame rates. It also doubled as my first web server, hooked up to a nearby provider using what was probably the longest run of coax on the internet at that time ;) The Indy as it was called was this funny little pizza box with a MIPS cpu running at 200 MHz, 32M of ram and internal 3.5&#8221; hard drive. It was quite fast and the operating system felt extremely well integrated with the desk top environment. To this day, whatever machine I&#8217;ve got I try to re-create that feeling as much as possible.</p>

<p>SGI eventually bit off more than they could chew with the acquisition of CRAY, the hardware was way overpriced compared to the PC offerings and eventually the company died and I was back to PCs.</p>

<p>In spite of the PCs (especially from the 386 onwards) dominance in the market, their utility and eventual performance and the fact that they powered a huge part of my professional career there was something special about those funny little 8 bit machines.</p>

<p>Apart from the operating system exercise (which, together with games programming taught me more about computers than anything else) I have over the years come to feel more and more out of touch with the machine. Those 8 bitters you could actually know, you&#8217;d be aware of each and every memory location and what was going on there, you could know those computers exhaustively, until there was literally nothing left that you did not know.</p>

<p>Nowadays when I boot my trusty Ubuntu machine (24G of ram, 48T of attached storage, 2.6GHz clock, one of those 8 bitters would fit in a <em>very</em> small corner of that machine) I feel strongly that it is impossible for me to fully &#8216;grok&#8217; that computer. I have to rely on trust rather than knowledge that everything is the way it should be and when I program I know I write on top of countless layers of code written by others rather than directly to the machine. API gluing rather than actual coding. Of course the effect of tying together a few APIs with some glue code will outmatch anything you could have achieved in a lifetime writing on an 8 bitter but still, there is some aspect that is missing there.</p>

<p>I don&#8217;t actually know the computer that I&#8217;m using for my day to day work any longer. Those oldies they had personality, they were quirky and strange, each computer completely different from the others in many ways, and knowing them intimately gave you a tremendous edge. In that sense they were more personable, more individual.</p>

<p>A man named Jim Lawless just mailed me, we seem to have more than just a title in common, read his post as well if you feel like it and spot the 7 differences :) : <a href='http://www.mailsend-online.com/blog/computers-i-have-known.html'>Computers I have known</a>.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Introducing The Paper Bay]]></title>
    <link href="http://jacquesmattheij.com/introducing-thepaperbay"/>
    <updated>2013-02-13T10:37:00+01:00</updated>
    <id>http://jacquesmattheij.com/Introducing-ThePaperBay</id>
    <content type="html"><![CDATA[<p>Over the last couple of weeks I&#8217;ve been working off-and-on on a little side project. The idea is that there are lots of people that are not in a position to visit a university or that don&#8217;t have a public library with &#8216;access&#8217; at their disposal but that do need to be able to read scientific papers. Ever since the advent of the world-wide-web the funding for public libraries has slowly but surely dried up. There are fewer of them and they offer ever fewer facilities, including more limited or non-existent access to scientific journals. And that is a pity because libraries offer something the web does not, access to a wealth of copyrighted materials for a very small fee.</p>




<p>Scientific research costs lots of money. So much that most if not all research can trace its funding back to public money. Every paper cites the papers that it builds upon, and even if a piece of research is not funded directly with public money you won&#8217;t have to trace back very far through the citations before you hit papers that were funded with public money. So, effectively, *ALL* research that is conducted is funded directly or indirectly through public money.</p>




<p>Historically, publishing anything was a costly affair. Copyrights on scientific papers submitted to journals were routinely assigned to those journals by the scientists that wrote the articles. The copyrights didn&#8217;t matter much to them as long as their work made it out into the world, to get to an audience larger than the scientists themselves could reach. Quite a few of those journals even had such copyright assignment as a requirement. At that time nobody could foresee that the world would change to the point where this mechanism no longer made any sense at all. Lots of people are aware of this problem, but nobody is in a position to do much about it. The reason why is that the lobbying power and the legal armies that are at the disposal of the few publishing companies that find themselves in the luxurious position of holding hostage the last 70 years or so of the results of scientific research are so formidable that they serve as an effective deterrent against correcting this historic mistake.</p>




<p>It&#8217;s a beautiful business to be in: publish research that you took no part in, claim the copyrights to the results of that research, publish the research in a very expensive journal, publish reprints at exorbitant fees and finally, when a more efficient distribution method appears get rid of all the costly components of the business but keep the prices the same. According to one person I spoke to who is knowledgeable about the publishing field the profit margins dwarf even those of the publication of pornography.</p>




<p>In our current technological age storing and distributing 50 to 75 T of data (estimated amount of storage required to store all the papers produced historically) is an affair that even a private individual can afford. Passing a paper from a central service to a person that wishes to read that paper no longer takes a printed volume and a physical distribution network. Such a service can operate not on several 10&#8217;s of Euros/Dollars per reprint of a document (which was, even when it was needed excessive), but it can operate on very small fractions of pennies. And yet, the publishing industry that seeks rent on the content that (they claim!) has been assigned to them routinely charge excessive amounts of money for access to this information. <a href='http://www.guardian.co.uk/science/2012/jan/16/academic-publishers-enemies-science'>Many words have been written about this subject</a>, but in the end the publishers have pockets deep enough and lobbying power sufficient to protect their business interests against the very people that fund the research.</p>




<p>If you are living in a country that is poor, if you are a private individual (whose taxes have likely been used in part to fund the very research you might be interested in) and if you have a desire to enhance your understanding of how some aspect of the universe works, or if you want to help lift your country out of poverty by studying hard chances are that you will not be able to do so without paying exorbitant amounts of money to parties that did not contribute to the original research in a meaningful way.</p>




<p>A Small Detour</p>




<p>In the 1980&#8217;s, when computers were a bit more scarce and a lot less powerful than they are today, and when a half decent development environment was even more scarce I finally found my home on the Atari ST, an MC68K computer that was more suited to writing games on than software of a more productive nature. It came with your option of several not-so-hot and fairly buggy programming languages, mostly limited to BASIC and assembler. And then a little known company called <a href='http://en.wikipedia.org/wiki/Mark_Williams_Company'>The Mark Williams Company</a> came out with &#8216;Mark Williams C&#8217;, a very good C compiler and a standard library implementation to go with it. I was hooked instantly, this was what I&#8217;d been looking for, a computer with a very powerful CPU and a more ambitious amount of memory than what my 8 bitters could provide, an environment to learn more about programming (I&#8217;d been reading Kernighan and Ritchie&#8217;s introduction to the C programming language back-and-forth but had no access to an environment where I could actually write programs and try them, so &#8216;desk checking&#8217; was my lot until that point).</p>




<p>Mark Williams C really changed my life, it literally launched my career as a free-lance programmer. It came with a *fantastic* reference manual, that I kept with me until it fell apart from use and even my attempts at taping it together were no longer enough to keep it serviceable. Long after all my Atari machines had all died from old age and hard use that manual came with me, to Poland where I lived for a while, and then back to the Netherlands.</p>




<p>The Mark Williams Company derived its curious name from William Mark Swartz, the father of the man that ran the company, Robert Swartz.</p>




<p>End Detour</p>




<p>Late in 2010, A young man named <a href='http://aaronsw.com/'>Aaron Swartz</a>, the son of the above mentioned Robert Swartz worked very hard to achieve one of his goals, to ensure that everybody would have access to scientific papers, no matter whether they were affluent or whether they were affiliated with a university or not. He went about it in an unfortunate way which got him into trouble with the law. <a href='http://en.wikipedia.org/wiki/Aaron_Swartz'>Aaron</a> had already achieved several noteworthy victories for someone as young as he was but the combined might of the United States federal justice system and MIT (who insisted on labeling him a felon and jailing him) proved too much for him to deal with and he took his own life on the 11th of January 2013. Volumes have been written about Aaron&#8217;s saga, I won&#8217;t go into the details but if you feel like reading more about it I recommend <a href='http://www.slate.com/articles/technology/technology/2013/02/aaron_swartz_he_wanted_to_save_the_world_why_couldn_t_he_save_himself.html'>this slate article</a>.</p>




<p>What really bothers me that someone so young, so nice and accomplished and so idealistic would be pressured to such an extent for trying to do something that was good by any definition of the word that I&#8217;m familiar with.</p>




<p>Most of the work I do is born from a love for my profession, this work was born in anger and frustration at a system that causes the best and brightest lights to be extinguished.</p>




<p>So, here is <a href='http://thepaperbay.com/'>ThePaperBay.com</a>, a way for those that seek scientific papers to make contact with those that have access. It&#8217;s my salute to the man that tried to give us access to all the products of science and a very small token of gratitude to his dad.</p>




<p>We should all wish for sons to be so proud of.</p>



]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[When Haskell Is Not faster than C]]></title>
    <link href="http://jacquesmattheij.com/when-haskell-is-not-faster-than-c"/>
    <updated>2013-01-21T10:37:00+01:00</updated>
    <id>http://jacquesmattheij.com/When-Haskell-Is-Not-Faster-Than-C</id>
    <content type="html"><![CDATA[<p>This article is in response to an earlier one comparing Haskell and C, which made the claim that Haskell beats out C when it comes to speed. On a Hacker News thread I made the bold claim that the C code is rife with problems and that it is tempting to fix it.</p>

<p>I&#8217;ve earned a good part of my life&#8217;s income to date taking other people&#8217;s C code, cleaning it up, making it work and then making it work better. In one sense the original program that this article is about is perfect, it takes the prescribed input, processes it and produces the desired output using the test set provided. That&#8217;s really all you can ask for in any program, under normal circumstances. Provided of course that the program produces its results in an acceptable time. What acceptable is is up to the user of such a program, in this particular case the writer of that article (linked at the end) used acceptable to mean &#8216;slower than Haskell&#8217; and as a long time observer of the language wars this irks me.</p>

<p>For one, I think if you compare two languages side by side I think you should at least be as proficient in the one language as you are in the other, and you should be proficient in both. Second, you should if you are not proficient in one of the two limit yourself to highlighting the strong points of your favorite language rather than talking down the other language that you don&#8217;t know as much about. Third, a comparison on speed between Haskell and C is almost meaningless, speed is not Haskells strongest point and it would be folly to bench it against C for that particular reason.</p>

<p>The monetary gain from using a higher level language than C is made because the programmer spends less time writing/debugging/maintaining the software. As compilers get better and languages are better capable of using raw speed of the hardware without investing a lot of programmer time this trade-off will be made more frequently to the disadvantage of languages lower on the totem pole such as C.</p>

<p>I have no clue about the specific strengths or weaknesses of Haskell. I hear a lot about it but there are so many languages and there is only so much time. My own language repertoire is probably outdated, limited and not &#8216;hip&#8217; by any stretch of the imagination but I think I know my old tools well, a bit like an elderly carpenter, please keep your fingers away from the chisels.</p>

<p>C may be old, but beating C for raw performance is quite hard (if it is possible at all, even FORTRAN still has its uses) and there are applications where the sheer number of computers working on a single problem outweighs the programmer cost advantage offered by an easy to use language (I&#8217;ve never heard anybody describe Haskell as &#8216;easy&#8217;, but it may very well be easier than C, I just do not know) by a considerable margin. The example chosen is quite apt because a lot of the problems in the field of computational genomics are exactly such problems. Other advantages from efficient code may translate into hard real time guarantees, improved battery life, lower charges from your service provider or a lower power bill. And since the environmental impact of computing is more and more on the radar optimization may find a new lease on life. That said, any optimization that you don&#8217;t know for sure that you need is likely to be premature and it is important to be aware of the cost of optimization and to make the appropriate decision when to employ it.</p>

<p>So this is an attempt to set the record straight and will give a level comparison between the &#8216;old&#8217; version of the code as supplied by the original author and a re-written piece of code. I&#8217;ve purposefully not looked at other C entries in the language shoot-out section to keep things fair and to show what you can do to fix this code. A from scratch implementation would go for the end result in a much more direct way.</p>

<p>The time taken by the version as posted on http://paulspontifications.blogspot.nl/2013/01/when-haskell-is-faster-than-c.html on my machine (i7 920, 2.66GHz) when compiled with -O3 (a C compiler optimization directive) to process a 250M &#8216;fasta&#8217; format file is about 7.4 seconds (average of 10 runs), so we&#8217;ll be using that as a baseline.</p>

<p>As we go the original program will be transformed into one that hopefully reads a bit easier and performs better as well.</p>

<p>The first re-factor will be a simple cleanup.</p>

<p>After turning on some compiler warnings (-Wall -Wextra) the first thing that jumps out is an unused variable &#8216;title&#8217; in the &#8216;main&#8217; function (happens to everybody without warnings on) and the fact that characters (signed entities) are used as array indices. Changing the base type of the arrays and pointers to &#8216;unsigned character&#8217; removes these warnings and takes care of a potential problem if the program would ever be fed bytes > 0x7f, in which case it would start to refer to memory <em>before</em> the lookup table. You really don&#8217;t want to do that. C&#8217;s signed character type has tripped up many programmers, especially when used as an index. Main really has a type &#8216;int&#8217; and you should declare it as such, and add a proper return value.</p>

<p>As usual when dealing with programs that are undocumented other than a few brief comments here and there part of the fun in doing things like this is figuring out how it does what it does. This one is fairly simple but still, the principle holds, I like puzzles.</p>

<p>C does not require you to set static global arrays to &#8216;0&#8217;, so the for loop in the main function can go, you also don&#8217;t need to declare empty blocks so the {} after the while can go as well.</p>

<p>First thing to hit is the loop that writes the output. This is a character loop that is a bit inefficient the way it is written. The fasta format uses 60 characters to a line and we can simply write out lines of 60 bytes in one go, adjusting the size for the last line to whatever is left. New runtime of the program is 5.2 seconds.</p>

<p>I don&#8217;t really like the way the feof / fgets bit at the beginning of the process function looks so I&#8217;ve changed it a bit using the return value of the fgets function as a guide whether we&#8217;re at the end of the input or not. A bit more fiddling to the output loop to make it look nicer (obviously no speed gain, that&#8217;s just cosmetics). What is not cosmetics is that the title string is messed up if it is longer than 132 characters, the remaining characters would be dropped. This is a problem because the FASTA format does not allow lines > 120 characters but if we receive input like this we have the tough choice of either keeping the input and performing the job or throwing an error. Silently discarding the excessive input seems wrong to me. If this were a contract job I&#8217;d aks for guidance at this point what the company policy is in situations like these ;) Some more looking at that loop and you see that you can simply drop the title variable altogether and simply use the loop that scans for the &#8216;\n&#8217; character to process the whole title. End of file handling of this program (and bad input) are pretty weak, but those things are not specified so we&#8217;ll just leave them the way they are. For robust production code this would have to be substantially improved on.</p>

<p>Next up, the read loop. The read loop is also character based, just a minor tweak and instead of reading characters we&#8217;re reading lines using fgets. New runtime: 1.2 seconds. C has a nasty problem with looking ahead in the input stream, we need to know if the first character of the next line is a greater than sign, if it is then that&#8217;s the sign that we are looking at the beginning of a new sequence. This is done rather un-elegantly using a getc / ungetc pair, which effectively allows you to peek one character ahead.</p>

<p>That 1024 bytes buffer is a bit anemic, this is 2013, we&#8217;re processing 250M of data and we&#8217;re going to pull it all in anyway. Let&#8217;s use 256K buffers, we&#8217;ll still use exactly the same amount of memory + on average half an empty 256K buffer. That&#8217;s a very small price to pay. Runtime now 0.97 seconds.</p>

<p>So far we&#8217;ve been quite nice with our optimizations, no tricks, no gimmicks. The speed of the program is not fantastic but quite respectable.</p>

<p>But suppose your boss is at your desk breathing down your neck. It&#8217;s fast but really not yet fast enough, what can you do to make this code faster? &#8216;Use as much memory as you want&#8217; he said when leaving&#8230;</p>

<p>Optimization is a funny game, the more you optimize the code the uglier it gets. Programs that have been optimized are - if you don&#8217;t stop where we&#8217;ve gotten so far - a lot harder to maintain and a lot harder to debug as well. So now we&#8217;re entering the twilight zone of optimizations, things that you really don&#8217;t want to do unless you&#8217;ve got an extremely good reason for doing them, and things that might subtly alter the way you can use your program, so you need to be vigilant against that. Since there is no clear specification here we have a lot of leeway but in a real world setting there would be all kinds of constraints.</p>

<p>A quick check of how fast the program runs when you disable &#8216;reverse_complement&#8217; shows that this takes approximately 20% of the runtime. This means that even if we&#8217;d reduce that portion to &#8216;0&#8217; there would still be 80% of the time used for other bits of work. Another quick check, cat&#8217;ing the file to /dev/null shows that this takes about 50 ms. Clearly raw IO speed is not what is holding us up.</p>

<p>That leaves the two loops that we&#8217;ve already optimized a bit as the main offenders.</p>

<p>One of the problems with those loops is that (unlike reverse_complement) we can&#8217;t do the work in parallel, so the usual &#8216;get out of jail free&#8217; card does not help us here. If we were CPU bound for the larger part of the runtime the effect of multi-threading would be much more pronounced, but in this case we can never win more than 20% that way. Reading from an input stream is an inherently serial operation and writing to an output stream is too. When you&#8217;re optimizing there are a bunch of trade-offs that you can make, the most common one is space versus speed. If memory is significantly larger than the largest possible input sequence you could read all of the sequence into one giant chunk of memory. that would mean a single read. The interesting possibility that approach offers (versus the block oriented approach used by the original program) is that the linefeeds would remain where they are. Simply skipping them would be enough. (this skip would require two tests in the inner loop of the reverse_complement routine, which would incur a penalty, but that penalty is not as large as the one imposed by the way the linefeeds are processed now). A single read and a single write could then do the whole job.</p>

<p>A very quick check, increase the block length to something > than the input file length shows about 5% improvement, but we&#8217;re still going through those loops. I like the idea of a very fast scan, let&#8217;s see what we can do with that.</p>

<p>So, this is the first major departure from the original code,  We start off with allocating buffers again, but this time we read huge chunks of data until all data has been read, and then we move all the data into one single buffer which we can then process in place.</p>

<p>To make reverse_complement a bit more universal we pass it two pointers to the data instead of the &#8216;block&#8217; pointer.</p>

<p>Reading and writing the data now comes in at 0.22 seconds with 1M blocks. (reading from a file and writing to /dev/null).</p>

<p>Next up the processing. We leave all the data in place, we don&#8217;t mess with the linefeeds (we just skip them) and we stuff it all into one giant buffer. Runtime: 0.44 seconds. .22 of that comes for the reading/writing, and the other half is the actual processing.</p>

<p>Note that this change means that the program will need an end-of-file at some point in order to function, and that end-of-file should arrive before we run out of memory. This is a serious drawback and we should really do something about that, because now the program is no longer up to spec. It may be fast, but if it contains a bug like that the speed is not relevant. Make it correct first, <em>then</em> make it fast!</p>

<p>The problem is (like with many text protocols) that we have absolutely no idea how much data to read to get the next working set into memory. The only thing we have to go on here is that single &#8216;>&#8217;. Scanning for that character is expensive! It requires a full pass through the data just to figure out where the one sequence ends and the next one starts. And since this is crucial information we can&#8217;t really skip this step. The good news is, we had that scan anyway so whatever the reader gains in complexity is lost by the processing step (which will now only process one sequence).</p>

<p>The final result is a runtime of about .75 seconds, quite acceptable and this would put it #1 on the shootout if submitted. There are stil two bits of low hanging fruit left to optimize this code further:</p>

<p>The first is very obvious. If we&#8217;re processing multiple sequences then (in the case of the original program) we can process blocks in parallel on multiple cores using threads. In the current incarnation of the program you&#8217;d apply that technique to a full sequence. As shown above this would yield at most a 20% improvement, my best guess is that with the input streams given the yield would be lower than that (about 7%, 1/3rd of 20% because there are 3 input sequences).</p>

<p>The second is a bit less obvious. The reader loop now reads in as much as it needs or a bit more. Once detected the bit more is saved for the next round of reading. Every time that scan takes place it re-scans from the beginning of the sequence found so far. That&#8217;s fast (because it is in memory), but still very wasteful (because a sequence is larger than the CPU cache it is in fact very wasteful), you only need to scan the new part <em>after</em> you&#8217;ve done the initial scan. So you could improve on this by adding another scan in the first portion of the reader loop just after it re-cycles the saved portion. For every iteration of the loop after that one you only scan the bit that you just read in.</p>

<p>Total memory consumption of this version is about twice as good as the best C version in the shootout, and elapsed time slightly better. Using the threading and scan tricks above memory consumption should be about the same and elapsed time should be significantly better.</p>

<p>In the words of Colin Wright: &#8220;You can&#8217;t make a computer do stuff faster, but you can make it do less work&#8221;, and that really is the essence of optimization.</p>

<p>The realloc is not as bad as it looks, since it is almost always the last allocated block growing it is nearly free.</p>

<p>C gives you a lot of leeway in how you want to express your code. Over the years I&#8217;ve settled on a style that is pretty defensive, this helps in avoiding some of the pitfalls in the C language. When you read the code below you might think &#8216;I can do this quicker using a pre-decrement&#8217; or you might think &#8216;I can push these two separate statements onto a single line&#8217;. These things are all true, and in fact they might give you a small performance boost at times. But for me such optimizations are not worth it unless we&#8217;re talking about an inner loop where a substantial amount of time is spent. And even then I&#8217;d work hard to get rid of the number of times we iterate through the loop before resorting to such micro-optimizations trading readability for speed.</p>

<p>I hope you enjoyed this little exercise, I certainlyh did. The final code is below.</p>

<p>(afterword: Joachim Schipper points out that memchr could be used to speed up the inner loop in the scanner for the &#8216;>&#8217; character see <a href="http://news.ycombinator.com/item?id=5091645">here</a>, that&#8217;s important because it makes the inner loop both faster and more readable, and this is a good illustration of why you want code review).</p>

<pre><code>#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;string.h&gt;

#define BLOCKLEN (1*1024*1024)

#define TRUE 1
#define FALSE 0

/* Initialised by calls to set_complement. Holds the complement codes. */

static char complement[256];

void set_complement(int c1, int c2) {
    complement [c1] = c2;
    complement [c2] = c1;
    complement [c1 | 0x20] = c2;
    complement [c2 | 0x20] = c1;
}

/*
 *  this walks two pointers towards each other, every time one of the pointers
 *  hits a linefeed the linefeed is skipped and the loop restarted. Whenever neither
 *  pointer is on a linefeed (the most common case) the characters are complemented
 *  and swapped.
 */

void reverse_complement(unsigned char * ptr1, unsigned char * ptr2) {
    unsigned char c;

    while (ptr1 &lt;= ptr2) {

        if (*ptr1 == 10) {
            ptr1++;
            continue;
        }

        if (*ptr2 == 10) {
            ptr2--;
            continue;
        }

        c = complement[*ptr1];
        *ptr1++ = complement [*ptr2];
        *ptr2-- = c;
    }
}

/*
 * Fasta files do not have any parser friendly features such as length fields. This means 
 * that if you want to know if a sequence is complete you have to scan for the next '&gt;' 
 * character of the title following the current sequence. This is quite time consuming, 
 * and even if you find it you still have a problem because you'll have read *too much* 
 * data from the input stream. That excess is then saved in a separate buffer to be re-used 
 * at the beginning of the next round of reading. 
 * 
 * This loop is pretty slow, it takes up about 40% of the total runtime of the program. 
 * There is a clear way to improve it, which is to scan only the part that was just read 
 * in after the first pass through the loop in read_sequence. I'll leave that as an exercise 
 * for those that want to beat this version of the code, there is an easy #1 spot in the 
 * language shootout waiting for you if you add that feature ;) (and multithreading if
 * you want to keep that #1 spot!)
 */

int sequence_complete(unsigned char * p, int n, unsigned char ** saved, int * savedsize)

{
    // skip the leading '&gt;' for the title of the current block, we want the *next* block

    p++;
    n--;

    // now search the rest of the data for a sequence start

    while (n) {
        if (*p == '&gt;') {
            // we've found a title for the next sequence, figure how how much excess we have
            // and save the remainder

            *saved = malloc(n);

            memcpy(*saved, p, n);
            *savedsize = n;

            return TRUE;
        }

        p++;
        n--;
    }

    return FALSE;
}

// read in a sequence, if we read in more than one whole one save the excess

unsigned char * read_sequence(int * s, unsigned char ** saved, int * nsaved) {
    int size;
    unsigned char * p;
    int read;
    int n;

    if (*saved == NULL) {
        // first round or a really lucky break
        size = BLOCKLEN;
        p = malloc(BLOCKLEN);
        read = 0;
    }
    else {
        // round which starts from excess data read during a previous round
        size = *nsaved;
        p = *saved;
        *saved = NULL;
        read = *nsaved;
        size &lt;&lt;= 1; // fix for bug spotted by Robert G. Jakabosky
    }

    while (!feof(stdin) || read) {
        p = realloc(p, size);

        n = fread(p + read, 1, size - read, stdin);

        read += n;

        // if the sequence is now complete save the excess for the next
        // iteration and process this sequence. Like that we don't need
        // to read all the way to end-of-file before we can start processing
        // if we have read more than one whole sequence this still works, it
        // just means that we will re-visit this on the next round through
        // the reader to fetch another whole sequence.

        if (sequence_complete(p, read, saved, nsaved)) {

            read -= *nsaved;    // compensate for saved portion
            break;
        }

        // if we did not read any data we can return now

        if (n == 0) {
            break;
        }

        // every time we reach the end of the block we scale up

        if (read == size) {
            size &lt;&lt;= 1;
        }
    }

    *s = read;

    return p;
}

void process_sequence(unsigned char * p, int size) {

    unsigned char * start;

    // skip the block title
    start = (unsigned char*)strchr((char*)p, '\n') + 1;

    // figure out start and end of this sequence and do the complement

    reverse_complement(start, start + size - (start - p) - 1);
}

void setup() {

        set_complement ('A', 'T');
        set_complement ('C', 'G');
        set_complement ('M', 'K');
        set_complement ('R', 'Y');
        set_complement ('W', 'W');
        set_complement ('S', 'S');
        set_complement ('V', 'B');
        set_complement ('H', 'D');
        set_complement ('N', 'N');
}

/*
 * process sequences one-by-one until we're out of sequences and end-of-file 
 * has been reached on the input and the readahead buffer is empty
 */

void process() {

    unsigned char * readahead = NULL;
    int nreadahead;
    unsigned char * p;
    int s;

    while (readahead != NULL || !feof(stdin)) {
        p = read_sequence(&amp;s, &amp;readahead, &amp;nreadahead);

        process_sequence(p, s);

        fwrite(p, 1, s, stdout);

        free(p);
    }
}

int main() {

    setup();

    process();

    return 0;
}
</code></pre>

<p>Finally, this code is still terrible! Yes, really. It is fragily because it does not deal well with error conditions such as broken input and many others besides. Because the original does not and the specification doesn&#8217;t give any requirements I left it that way but I would never ever consider a piece of code like this finished. At a minimum it would require checks on all system / library call return values, unit tests for every function and so on. Even a &#8216;rivial&#8217; little program like this is not trivial if you plan on putting it into a real world situation where people will run their business based on your code.</p>

<p>One thing that struck me about the FASTA format is that there is absolutely no attempt to detect/correct errors in the data, for a file format that stores information where mutations are not without effect you&#8217;d hope they would at least put in some safe-guards to make sure that mutations are of the biological variety rather than the digital one (bitrot).</p>

<p>Another thing that I noticed when I was finished and looked through the language shootout entries was OCaml #3, about 3 times as slow as the C version here, but only 12.8M of ram in use, I have absolutely no idea how it does that!</p>

<p><a href="http://benchmarksgame.alioth.debian.org/u32/performance.php?test=revcomp#about">the language shootout entry</a></p>

<p><a href="http://news.ycombinator.com/item?id=5082212">skybrian notes about battery life/cloud charges</a></p>

<p><a href="http://en.wikipedia.org/wiki/FASTA_format">FASTA file format</a></p>

<p><a href="http://news.ycombinator.com/item?id=5080210">Original HN thread</a></p>

<p><a href="http://news.ycombinator.com/item?id=5083267">@ay: I left you a message</a></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[A World Without Power]]></title>
    <link href="http://jacquesmattheij.com/a-world-without-power"/>
    <updated>2013-01-02T10:37:00+01:00</updated>
    <id>http://jacquesmattheij.com/A-World-Without-Power</id>
    <content type="html"><![CDATA[<p>The 14th of August, 2003 was an interesting day in many ways. I&#8217;d just taken the family down to Toronto to spend a day there and pick up our newly minted passports at the Dutch embassy. We had some fun in the city seeing the sights, visited Niagara Falls and were on the way back on a sunny August thursday afternoon. What could possibly go wrong? We pulled into a gas station just outside of Barrie. We parked behind the person gassing up and waited our turn. The guy took his time, walked into the store to pay, got into his car and drove off. We moved up the line to the pump, I got out and put the nozzle into the fuel port but nothing happened. This normally means that the pump hasn&#8217;t been &#8216;cleared&#8217;, usually that takes 10 seconds or so (an annoying little bell starts ringing in the office over the blinking light indicating the pump that needs to be cleared). After a minute of waiting I went into the office. &#8220;Sorry bud, the power is out&#8221;.</p>

<p>Bummer! The car we were driving was our family car, one of those ford minivan affairs and it wasn&#8217;t exactly a paragon of fuel economy. 3.8 liter engine, still slow as could be and it drank like a fish. So when we pulled into the gas station the needle was at &#8216;empty&#8217; and the fuel warning light was on. We were stuck for the duration.</p>

<p>I looked at Barrie from the highway down and noticed that there were lots of people in the streets, many more than you&#8217;d normally see in a place like that. Traffic lights were out. Billboards were dark. Little by little it dawned on me that this was more than just a trivial outage. I tried my cellphone, it still had a signal and called to the Island where we lived. We had a business there (a gas station, coincidentially) and I asked them if they had power. No, they didn&#8217;t. Oh oh. But the generator was up and running and as far as they were concerned it was business as usual. Maybe a bit more busy because some traffic from the highway pulled in on the island to gas up. I asked them to call the supplier (Wardlaw fuels in Sault Ste Marie, an awesome company to work with) to make sure they were going to be provisioned.</p>

<p>An hour and a half into the blackout a truck from OPG pulled into the station. The guy in it took all the ice his truck would carry, paid cash and drove off again. Now I was getting really worried. OPG is the &#8220;Ontario Power Generating Company&#8221;, they are the company that runs all the grid infrastructure, and more importantly they run the nuclear generators. If a guy with that much knowledge buys ice he must know something that the general public doesn&#8217;t know yet: that this outage is going to take a very long time, long enough that food will spoil. Nuclear power is funny in that it is excellent baseline power, but when you shut down a nuke it&#8217;s going to be down for a while. They go down quite quickly but they take forever to get back online.</p>

<p>I saw one guy walk around to the spot where the air hose for refilling tires was. A few minutes later the same guy walks by with the length of air hose coiled up and on his shoulder like it was the most normal thing in the world. Presumably he was going to use it to siphon fuel from one car into another. Let&#8217;s hope they were at least both his cars. Another guy made off with the fire extinguisher. I&#8217;ve heard it say that the veneer over our society is very thin and that it won&#8217;t take much to bring out the ugliness underneath but I had not expected to see that illustrated so clearly so quickly. Suddenly I didn&#8217;t feel safe and I did not want to wait for who knows how long next to an unfamiliar town in a vulnerable position like this with my wife and kid with me.</p>

<p>My mobile still worked, so I called the gas station on the Island again. The mood around us continued to detoriorate from resigned to menacing, people were getting angry with the operator of the station (just some kid that was clearly not the cause of the trouble). I asked the people at our gas station on the Island to please go to our house, get our other car (a honda civic hybrid, capable of doing 1200 km on a single tank if you were careful), load it up with fuel cannisters and drive down to where we were. They said they&#8217;d get on it, and that the station was being mobbed by people that wanted gas, some coming all the way from DesBarats and Sault Ste. Marie (a good 50 Km or 30 Miles away). They&#8217;d already gone through one full drop (50,000 liters) and another one was on the way. Our trusty diesel was doing just fine running the pumps and half of the freezers, they&#8217;d sold the food in so they could be switched off, the other half at a discount rather than to let it go bad.</p>

<p>We talked to some of the people stranded around us. One group was a bunch of motorcycle enthusiasts, guys that not only drive but <em>build</em> their own bikes. Lots of nice metalworking there so we talked for a bit about that. One girl that was stranded came from Toronto and was on the way to Muskoka, a popular place to spend the holidays. We waited&#8230; One of the bike guys went into town and scored a pizza. One of the pizza bakers had set up in the street and was selling pizzas for $5 as long as he had ingredients. We munched our pizza, talked some more and waited some more.</p>

<p>Barrie is about 500 km from the Island, and around 10 pm I saw our saviors roll into the station. Two kids with huge grins on their faces and music blaring loud from the open windows. I don&#8217;t think I was ever so glad to see my own car. The honda was a veritable bomb, it was filled with cannisters as many as they could cram in. We gassed up, then gassed the bikes of the bike guys (we swapped addresses, they invited us for a pig roast which we attended and they came to visit us on the island). The girl got enough gas to get back to Toronto, and we parcelled out the remaining fuel in the same way, just enough to get as many people home as possible. No charge, obviously (people were on the whole expecting to pay the gas station with a credit card or debit card). We made a lot of friends that day :), and quite a few enemies too (all those that we couldn&#8217;t help).</p>

<p>So, finally done we drove back to the island. It was the weirdest ride on Highway 17 North ever. Normally even at night there is light traffic there, this time not a single car. Just lots of wildlife, deer, moose and the occasional bear that had already taken over the highway so we went pretty slow. In none of the little villages on the road were there any lights. When we got back to the island it was 5:30 am or so, the gas station was <em>still</em> open, the pumps were still manned and going pretty much continuously. For 75 miles around there was no gas. The distribution point had huge tanks (millions of liters) that did a gravity dump into the delivery trucks, and then the truck would do a gravity dump into the underground storage tanks at the station. So none of that required power. And then the generator driven pumps would pull the fuel out of the underground tanks and deliver it to the customers just like normal.</p>

<p>The outage lasted 2 days and a bit. We went trough our monthly amount of fuel in that time and we made the Sault Star (the local newspaper) after the power was restored. (Good thing too, their presses were down just like everything else, we wouldn&#8217;t have been able to cope with the demand if there had been any publicity during the outage, word of mouth we could deal with, barely).</p>

<p>When we bought the station one of the first things I did was install that generator. I felt that what with the station being critical infrastructure for many of the islanders that we could not be dependent on Ontarios power grid. The island was fed by cables to a step-down transformer, and after that there was a &#8216;low voltage&#8217; (not really that low, but low compared to long distance lines) distribution net on the island and every house had its own drop transformer. Outages were frequent, once every couple of months, and more frequently in the winter months. Whenever lightning struck it was 50/50 that the power would go out. I imagined a situation where the power was out for just a bit longer than normal and decided that we could not run that risk. My software background makes me abhor single points of failure and to run an infrastructure business without a back-up in place seemed unwise and ran against my nature (even if the partners in the bussines thought that it was a bit over the top they still helped installing the genny).</p>

<p>I didn&#8217;t have any idea that there would be such a massive power outage (there had not been one like that in decades). I also didn&#8217;t know that I was going to be one the main beneficiaries of having a back-up. I definitely didn&#8217;t plan to get our business in the newspaper this way and did not realize how many people would end up relying on our silly little out-of-the-way gas station with it&#8217;s puny 2x50K liter reservoirs for a critical resource (a typical highway station has a 1/4 of a million liters). But being prepared for the occasion sure didn&#8217;t hurt. What is really scary is that apparently none of the other (much larger) stations than ours had thought this scenario through. Critical infrastructure being down is annoying enough, but the knock-on effects are devastating.</p>

<p>Our house didn&#8217;t have any issues at all, we were &#8216;off the grid&#8217; by that time so our business worked uninterrupted. One thing that I was very impressed with was how well the cellphone network dealt with the outage, for at least 24 hours all the base stations worked, after that point they slowly dropped out one by one as their batteries ran dry.</p>

<p>Infrastructure is invisible, as long as it works. And only when it fails do you realize just how much we are all dependent on it and how badly we are able to cope with such infrastructure being unavailable for any length of time. No power translates quickly into: no fuel, no water, no food and so on. If this had happened during the winter instead of a nice summer day the results would have been much more severe.</p>

<p>There is no moral to this story, but I&#8217;d like to add one: if you&#8217;re in the infrastructure business design as if lives depend on it. One day they may, even if you can&#8217;t foresee how that is possible. Even if you&#8217;re just running a lousy gas station on some barely accessible island.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Elon Musk and the Hyperloop]]></title>
    <link href="http://jacquesmattheij.com/elon-musk-and-the-hyperloop"/>
    <updated>2012-11-21T10:37:00+01:00</updated>
    <id>http://jacquesmattheij.com/Elon-Musk-And-The-Hyperloop</id>
    <content type="html"><![CDATA[<p>For a while now there have been tantalizing hints that Elon Musk is at it again. His usual way of approaching a problem is to look at an industry, find some fatal flaw in it, fix that flaw and then leave everybody else in the dust, wondering why they didn&#8217;t do what he did. He&#8217;s one of the most interesting people on the planet at the moment and there isn&#8217;t a week that I do not come across some bit of information that re-inforces that view. I&#8217;m not a person that will readily admit to being a &#8216;fan&#8217; of someone but let&#8217;s leave it at that I find it hard to not be infected by his devil may care attitude towards all things holy in industry and convention. Recently there has been a lot of buzz regarding the &#8216;hyperloop&#8217;.</p>

<p>The Hyperloop is the code name for his plan to disrupt the transportation industry, and maybe to hedge his bets on Tesla (which attempts to do the same in a less revolutionary way), and because of the lack of details speculation runs rampant about what it could be.</p>

<p>I&#8217;ve seen the most fantastic interpretations of the hyperloop name, including space bound filaments kept aloft somehow that people carrying projectiles are fired into (doesn&#8217;t anybody think of the children, or the grandmothers) and other science fiction interpretations.</p>

<p>This is my attempt at putting together what it could be taking into account some of the common elements in Tesla, SpaceX and paypal.</p>

<p>One thing Elon Musk doesn&#8217;t dabble in is science fiction, he seems to be stuck solidly in the science and engineering departments so I&#8217;ll go with &#8216;make it as simple as possible, but no simpler&#8217; principle. Airborne tunnels don&#8217;t have that simplicity component so I&#8217;ll happily discard them, they&#8217;re almost impossible to construct and they are terribly fragile once they&#8217;re up (and taking them down for maintenance would suck).</p>

<p>There are a few facts known from things that Elon has said on the subject:</p>

<p> &#8220;Cheaper than high speed rail&#8221;</p>

<p> &#8220;ground based&#8221;</p>

<p> &#8220;it leaves when you arrive&#8221;</p>

<p> &#8220;no rails required&#8221;</p>

<p> &#8220;It will revolutionize the transportation industry&#8221;</p>

<p> &#8220;It is <em>not</em> an evacuated tunnel&#8221;</p>

<p>That last one really piqued my interest. At first sight says very little, but that depends on how you interpret the sentence and I suspect that Elon may be playing a little practical joke on us here, let&#8217;s not forget he knows a thing or two about computers.</p>

<p>You can parse that sentence two ways to get a completely different meaning, depending on where you place your &#8216;brackets&#8217;, but in a spoken sentence these are invisible. So they&#8217;re a neat spot for a verbal trick:</p>

<p> It is not (an evacuated tunnel)</p>

<p>and</p>

<p> it is a (not evacuated) tunnel</p>

<p>So, in other words he may be putting the truth out there for everybody to see: it is a tunnel that is explicitly not evacuated.</p>

<p>Which I read to mean that he is saying that it is <em>pressurized</em>. Pressure is a lot easier to maintain than a vacuum is, especially if you&#8217;re building long stretches of tubing. A really good vacuum needs a considerable support structure because the atmosphere will happily crush your apparatus. There is also a low limit of how effective you can be (1 atmosphere, to be precise is the upper limit of diference that you can achieve by definition). Then there is the problem that to brace against that atmospheric pressure you have to push outward, which would be annoying because that is exactly where you want you vehicles to run, which means that if you want to make a high speed transportation device using a tunnel based on a vacuum that you&#8217;re going to have to make the tunnel double walled, which will greatly increase the cost. So clearly a vacuum would have all kinds of drawbacks and is a non-starter. Then there is the problem of convincing the general public to enter a cart in a tunnel that is evacuated, no way to refresh the air while it is moving and so on. Vacuum: bad idea.</p>

<p>So here is my vision for what &#8216;hyperloop&#8217; stands for:</p>

<p>If you reverse the picture and you imagine a tunnel that is pressurized then there is a much easier way to make the whole thing work, in fact it would explain one of the two parts of the word &#8216;hyperloop&#8217;, the fact that it apparently is a loop, which means that it is going to recycle some critical component. (the other, the &#8216;hyper&#8217; bit I assume refers to the maximum speeds attainable by such a system).</p>

<p>And that re-cyclable component may very well be the moving air inside the tunnel. If the pressure is supplied from the outside then it could leak away causing vehicles to have to work harder than they were designed for and the transit speed would suffer, but there is an elegant solution for this and it involves seeing the system as a whole rather than as bits and pieces.</p>

<p>A packet switched network of carriages that can be inserted and removed at various locations that are propelled into a slot on the &#8216;loop&#8217; and taken back out again when they reach their destinations. Energy would be expended when accelerating a carriage to the speed of the loop, after that has been done on a parallel track the carriage is shunted into the loop, and energy expenditure drops rapidly. Such shunt points would exist every few thousand meters along the length of the loop, comparable to on-ramps on highways. The whole thing uses the carriages themselves as the impellers that cause the air to move through the tunnel system, effectively everybody is drafting with everybody else. So the pressurized air is pressurized by the combined motive force of all the carriages. The more carriages in the loop the lower the energy budget per carriage. Carriages would be electrically propelled, mostly seal the tunnel walls and use maglev principles or something similar to reach their speed. One hyperloop could be the ramp up to the next by keeping &#8216;packets&#8217; for the same destination together, shunting them out to an intermediary phase and speeding up again for the next level. Downshifting would be the same but in reverse.</p>

<p>So this system would actually be cheaper and more energy efficient as usage goes up, compared with ordinary roads where congestion and fuel consumption goes up with usage.</p>

<p>There would be a fair amount of redundancy in the system, since if a carriage would for some reason slow down or if it would be really busy they could be made to move in such a way that a rearward carriage would start to help push the one in front of it, effectively reducing aeronamic drag on the rearward carriage to near 0, using the air between the carriages as a buffer medium and shock absorber. Pumping the remaining air between two carraiges out would effectively lock them together for the duration of the trip. Instant train formation, with some maximum length based on the radius of the loop, and even if the carriages would not be locked together from an energy consumption point of view if they get close enough the effect is much the same.</p>

<p>Loops around a city would be joined to other loops around other cities by long stretches of tubing, with the occasional spot for egress in case of emergencies. The whole thing resembles the internet loosely, both are packet switched, where the electrical wiring needs a return path for the electrons the tube system needs a return path to keep the moving air in the system. If traffic is light dummy carriages can be inserted into the system to keep the air moving, and as traffic increases more and more of these can be circulated out. That way the system would work even when there is only very little payload.</p>

<p>No vacuum (with associated risks and technical issues), simple, reasonably cheap to set up and maintain with all the active components in the carriage and with good economies of scale and redundancy. It would still cost a bundle to install such a system but compared to todays roads it will probably come in cheaper, especially in the long run asphalt is terribly costly to maintain. No traffic jams, just a fixed maximum capacity that can be expanded by installing parallel tubes.</p>

<p>I&#8217;m not sure what the end-points of such a system should look like, I&#8217;m imagining something akin to what I saw in a mailroom where they used pneumatic tube mail. And effectively, that is what this is, a scaled up version of pneumatic tube mail with some elegant tricks thrown in to make it energy efficient.</p>

<p>So, that&#8217;s what I think the &#8216;hyperloop&#8217; concept stands for. Time will tell if I was right or not, I wished I had some drawing skills so I could give you an artists impression of the words above.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Thank HN: Our friend is safe and sound]]></title>
    <link href="http://jacquesmattheij.com/thank-hn-our-friend-is-safe-and-sound"/>
    <updated>2012-11-18T10:37:00+01:00</updated>
    <id>http://jacquesmattheij.com/Thank-HN-Our-Friend-Is-Safe-And-Sound</id>
    <content type="html"><![CDATA[<p>Hello again, Hackernews.</p>

<p>I tried to post this on HN but the limit is 2000 characters.</p>

<p>Two weeks ago to the day I asked for your help in finding a lawyer for a HN&#8217;er that was about to be arraigned in front of a Delhi judge.</p>

<p>The original thread:</p>

<p> http://news.ycombinator.com/item?id=4739649</p>

<p>To say that the results were overwhelming would be an understatement but I don&#8217;t have more superlative words in my vocabulary.</p>

<p>We got offers from people for shelter, legal advice, money and all kinds of other help and most importantly, several pointers on how to quickly obtain a good lawyer.</p>

<p>A special mention for Shubham Goel who found us Rohit Kaliyar, advocate in Delhi.</p>

<p>Rohit met with his newfound customer on arrival in Delhi (our friend was snatched from her home in Pune in a bogus criminal case) so instead of facing a scared single young person the opposition faced a legal team that was briefed as good as time permitted and the result of that was that all efforts to keep our friend under some form of custody fell flat.</p>

<p>Right now she&#8217;s free, still there are people trying hard to ruin her life but at least for now the main threat is under control and a sense of normalcy has returned.</p>

<p>In the original thread there were a lot of requests for more details, we gambled on our combined reputations to keep these details from you but still ask for your help. That gamble paid off, and if at some point this story is to be told then we&#8217;ll leave that to the protagonist, rest assured that you won&#8217;t be bored if and when it ever comes to that. But for now the details of the background behind this will have to remain out of the public eye. Our friends&#8217; peace of mind and safety depends on keeping her identity and circumstances as much of a secret as we can.</p>

<p>So, thank you Hacker News, for trusting us about the urgency of the request in spite of the lack of details and for pulling together when it really mattered. On behalf of our friend: &#8220;Thank you so much for being there for me and for helping to keep me safe.&#8221;.</p>

<p>We hope that there will not be any re-runs of this, and that our friend is now safe from further bogus prosecution but in India not much is sure in this respect, especially not when the opposition has significant clout with the police who will apparently not be deterred by such simple things as laws. Fortunately, with the help of a competent lawyer and a somewhat more solid judiciary it seems you can get a semblance of justice. But that does mean having to live a life on the run and in hiding, which isn&#8217;t much of a life at all. Working on that.</p>

<p>best regards to all &amp; thank you again,</p>

<p> Jacques Mattheij (jacquesm) and Daniel Tenner (swombat)</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Stick to what you know, a tale of an investment gone wrong]]></title>
    <link href="http://jacquesmattheij.com/stick-to-what-you-know-a-tale-of-an-investment-gone-wrong"/>
    <updated>2012-10-01T10:37:00+02:00</updated>
    <id>http://jacquesmattheij.com/stick-to-what-you-know-a-tale-of-an-investment-gone-wrong</id>
    <content type="html"><![CDATA[<p>After moving to &#8216;the Island&#8217;, a place I won&#8217;t make too obvious here to protect the innocent and the guilty alike we settled down and built a house. We got to know a lot of people and were quite happy to employ a few of the people there to help run our various businesses.</p>

<p>We had money in the bank and a very positive outlook on life, the breathtaking nature and some hard earned time-off had renewed the store of energy that I had come to rely on over the years. A couple of the local people that we got to know expressed their desire to run a company of their own, and it didn&#8217;t take long before an opportunity presented itself.</p>

<p>The Island had two stores, one a general store where you could buy just about everything but it was on the far side of the island. The other a gas station, right next to the only access point to the island by car (technically it wasn&#8217;t an island any more since the bridge had been put in but it definitely still felt like one). The owners of the gas station were getting quite advanced in age and working a company like that in Canada, especially during the harsh winters is pretty heavy. Operating a gas station is a funny business, you make almost nothing on the gas (1 to 2 cents per liter, and of that you have to operate and service the pumps, pay for inspections, deal with occasional theft and so on), but you make it all back in the store. If you run such a station wisely it can hold its own, stay afloat and provide employment for a fairly large number of people (2 people, 2 shifts, 7 days per week) and turn a profit. So with the old owners willing to sell (they&#8217;d tried selling it before but that had not gone through for some reason) and new people willing to step up there was a possible deal to be made.</p>

<p>We put together a package, bankrolled by us which would result in one family having a house, one new company subletting the large garage space next to the gas station and a group of individuals that would be employed and would be co-shareholders in the gas station. It looked like a pretty good plan on paper and with the blessing of the bookkeeper and the various authorities it was put in motion.</p>

<p>The first year things looked to be going quite well. The man that had stepped forward to manage the whole thing had many years of experience in retail and he did a good job of making the transition from the old owners to the new one. We kept the name and we re-established ourselves as a constant factor in the lives of the local population. The gas station was quite important to the locals, it had been around longer than many of the people and there was a large element of loyalty involved. Be nice, serve up a good product, improve the store bit by bit, what could possibly go wrong?</p>

<p>In the winter of that first year I got the first sign of trouble. We&#8217;d done pretty good over the summer but somehow there wasn&#8217;t enough money in the bank to cover the tax bill. I really didn&#8217;t understand what was happening, all the books seemed to be in order and yet, even after the best quarter we were down enough that extra money was required to plug the hole. After discussing the situation we borrowed the missing amount. The store manager back-pedalled on his original commitment, and wanted to be relieved. This was a major problem. Even before the whole thing had started I had made it more than clear that we were willing to bankroll the operation but that we did not have the time or the knowledge required to run a retail operation ourselves and that we were relying on everybody to do their part.</p>

<p>A solution was found, one of the other partners in the venture stepped forward and made a good case why she should be allowed to take the position. She had been one of the hardest workers over the summer and seemed absolutely reliable. So the management change was made and things were back on track.</p>

<p>For about another year things seemed to be going well. We survived the winter (which had always been touch and go, the energy bills were huge), spring arrived and we were set for a fantastic summer. That year things derailed spectacularly. At some point the fuel supplier called me on my personal number inquiring when the next payment would come in. Fuel is sold in &#8216;drops&#8217;, a typical drop is one truckload of a mix of diesel and regular, sometimes premium (if that&#8217;s still sold, we still had one pump serving premium). The original arrangment was that I had asked specifically <em>not</em> to be given a line of credit. In spite of that agreement the fuel supplier had delivered three drops without payment, about $150,000 worth of fuel! Their reasoning was that since we had such a good reputation that the money would be coming any moment, and in fact they were assured to that effect by the people running the station. The call came as a complete surprise to me, I didn&#8217;t have clue that we were in arrears on anything, let alone in excess of a hundred grand.</p>

<p>The decision to shut down the station and liquidate the assets was a tough one. But it had to be done, there was no way we were going to survive a hole this size. But that still left the question of how we had gotten into this situation in the first place. Little by little the truth dribbled out, I&#8217;ll likely never know all the details but it seemed that some people figured that since the cash isn&#8217;t counted on a daily basis, why not take that cash and visit the casino. Surely if you gamble a bit then you can make some money, pay back the difference and nobody will be the wiser. And then, if it doesn&#8217;t work the next time you go gambling, you just take a bit more. And so on. In a span of 3 months a business that was the 3rd largest employer on the island was destroyed by those that were supposed to be minding it.</p>

<p>I blame myself. Trust but verify should have been my motto, trust alone simply doesn&#8217;t cut it. I should have kept a <em>much</em> closer eye on things. Coming from a software background I had 0 insight in the retail business, the one thing that I thought would offset this was the fact that we had a retail expert on board and that the people we were dealing with were effectively destroying their own livelihood if they would do anything against the interest of the group. But apparently not everybody is smart enough to see even that far ahead. What a pity!</p>

<p>So, a lot of people lost their jobs, some their house and reputations. We lost a bunch of money, the station got sold and the amount it fetched was high enough to cover all the debts (it turned out that there were many more bills that had not been paid) with a little bit of money left over.</p>

<p>And a very expensive lesson was learned: If you invest, do it in a business that you understand, and keep a close eye on your investment otherwise you risk getting burned.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[This white powder will kill me one day]]></title>
    <link href="http://jacquesmattheij.com/this-white-powder-will-kill-me-one-day"/>
    <updated>2012-09-29T10:37:00+02:00</updated>
    <id>http://jacquesmattheij.com/this-white-powder-will-kill-me-one-day</id>
    <content type="html"><![CDATA[<p>There are lots of bad things that you can insert into your system through various ways that all seem to be represented in physical form as white powder. Heroin, Cocaine, various other chemicals that people will consume in order to alter their state of consciousness. I hate drugs, with a passion. I&#8217;ve seen up close in many people during my years in Amsterdam what drugs can do to a healthy human body and it isn&#8217;t pretty. Having a dad that was a full blown alcoholic (brilliant when he was sober, mean tempered and agressive when he was not) probably helped a lot too.</p>

<p>So, long ago, when I was 12 or so I told myself that that would never <em>ever</em> happen to me. There was absolutely no way I was going to end up an addict to any of this stuff and become a living wreck. So instead of giving in to peer pressure and joining the club, I vowed to simply abstain from any drug at all. No Beer, Wine, Spirits, smokes, hash, coke or other dope for me. I wanted to be healthy and to live as long as possible while keeping my body in as good a shape as I could. Peer pressure by the way, especially to consume alcohol or to smoke pot is absolutely enormous when you&#8217;re a teenager. The amount of scorn heaped on me and the kind of treatment I got for not joining in any of this ought to be illegal. Kids can <em>really</em> be dumb when it comes to things like this and pressuring someone to join you in an act against your own interest especially when the pressure is from a group aimed at an individual is something that ought to be illegal. Fortunately I can take heat like that fairly well or I would have surely given in.</p>

<p>My plan was to simply not start any of this, that way I wouldn&#8217;t have to stop either. (one of my weaknesses is that if I like something I tend to do it a lot, by not finding out of I like something I thought I could elegantly side-step the problem).</p>

<p>Good plan! If only I had realized I was already addicted when I made that vow. The white powder seems to have gotten hold of me at an age early enough that I didn&#8217;t even realize how far in I was when I told myself &#8216;no drugs&#8217;.</p>

<p>Here is my vice: sugar.</p>

<p>It doesn&#8217;t seem as though it is very bad compared to the other ones in the list above. After all, you can buy it (legally, for a change) on every other street corner in convenient 2 pound bags. It&#8217;s really cheap too. Buy as much as you want, there is more if you need it. The DEA is not going to lift you from your bed for moving it from the distribution point into your house, it is transported by truck in plain sight instead of by submarine or ingested plastic balls because it is not a proscribed substance. Your kids will not be placed in foster homes if you are identified as a heavy user and everybody around you will be of the opinion that it is perfectly ok that you consume this chemical.</p>

<p>Sugar is poison, and much as I hate it, it seems that I can&#8217;t kick the habit. It really angers me to know that this substance seems to have a hold over me that I can&#8217;t break. Periodically I&#8217;ll try to get rid of it. I drink tea, lots of it, several liters per day. And I sweeten that tea with sugar. If I don&#8217;t drink my tea my head feels like mush. That&#8217;s why kicking the habit is so hard. It is as if there is something real and tangible that I get out of all this sugar, it raises the fog and makes it easier to think about stuff. If I don&#8217;t use sugar (but still drink the tea) then I simply get (or feel, hard to tell the difference) very low on energy. All I can do then is consume media, mostly reading and sit around. I&#8217;ve tried to write code while abstaining from sugar but it just doesn&#8217;t work. I&#8217;m not sure what the link is here, all I know is that without that chemical in my bloodstream for some reason I can&#8217;t get my head in first gear, let alone second or third.</p>

<p>Very frustrating. Extra frustrating because I know just how bad taking in these quantities of sugar is. Sugar has been linked to all kinds of disorders, especially when used in excess. None of it instantly fatal, more a kind of steady erosion of the system. A slow poisoning. When I observe myself aside from the dependency I can&#8217;t find any real signs of degeneration yet, but that&#8217;s something that probably every addict would say. And likely that&#8217;s just a matter of time. At 3 liters of tea per day (a fairly accurate estimate), 1.5 teaspoons per glass, 5 glasses per liter that&#8217;s 15 * 1.5 teaspoons per day, or 22.5 teaspoons. A teaspoon is 5 grams of sugar, so that makes for 112.5 grams, or a kilogram of sugar for every 9 days. That&#8217;s 40 Kg per year, I started this when I was 11 or so, figure 36 years since then so about 1.5 <em>tonnes</em> of sugar consumed since then!</p>

<p>Kicking this habit is something that I&#8217;ll need to do. Tomorrow, maybe. Right now I feel like having a nice cup of tea.</p>

<p>http://articles.mercola.com/sites/articles/archive/2010/04/20/sugar-dangers.aspx</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[How to build a windmill part 2, parts, nuts, bolts and blades]]></title>
    <link href="http://jacquesmattheij.com/how-to-build-a-windmill-ii"/>
    <updated>2012-09-28T10:37:00+02:00</updated>
    <id>http://jacquesmattheij.com/how-to-build-a-windmill-part-ii</id>
    <content type="html"><![CDATA[<p>Yesterday I wrote up a post that I had on my list of the last couple of years but never got around to. My all time favorite project, building a windmill and some of the stories behind it.</p>

<p>I made a promise to open source the design, and today I finally hope to make good on that promise. This comes with a word of warning though, I am flooded with work at the moment so I do not have the time to make this a picture perfect release. I am making a lot of assumptions about the skills of the people that would attempt an undertaking like this and if you are in doubt you probably should not even try this. In some ways releasing this scares the crap out of me because the possibility of someone getting hurt is > 0, even simply building this (without ever using it) is not without risk. I almost lost a bunch of fingers mounting the magnetic drum, so please take this as a warning (and I <em>really</em> like my fingers, and I&#8217;m <em>really</em> careful). A single &#8216;neo&#8217; magnet is already dangerous, 18 of the mounted to a chunk of steel is a formidable thing. No pretty pictures today, just dry technical stuff.</p>

<pre><code>Welcome to this terribly messy jumble of bits and pieces that I recovered from my subversion 
repository. It's a snapshot of the state of the project after the machine was finished. 

I wished I could say I was proud of the result but that's far from true.

In this archive you will find a number of directories with a fairly large number of files
that should in theory allow you to re-create some or all of the parts that went into
making the Big Blue Windmill that is on display at 

    http://jacquesmattheij.com/how-to-make-a-windmill

and some of the tools (specifically, the software to drive the plasmacutter/3D mill and to 
visualize the toolpaths).

I promised I'd open source the design and this is my attempt at doing just that. Here are some
of the caveats regarding this design:

 (1) Only *ONE* of these was ever built. That means there are likely design flaws, errors and
     omissions that will cause problems in the first few hundred copies made according to these
     (possibly incomplete or inaccurate) plans.  

 (2) I'm releasing this information as a private individual and accept absolutely no liability
     of any sort with respect to this release of information. If you build this machine even
     if it is exactly according to these plans then I do not warrant anything whatsoever. These
     plans are provided 'as is' without any warrants as to suitability, accuracy or even being
     fit for reproduction. If you, your pet, your children, spouse, innocent bystanders or any
     other person or good are harmed, lost, killed or damaged because you use these plans then
     *YOU* accept full responsibility for that. 

 (3) These plans are now 8 years old. 3 of those years the windmill was operational in Northern
     Ontario, Canada. The climate there is fairly harsh but there may be local factors where 
     you live that affect the design in a negative way. If you don't do your research before 
     you embark on building a machine like this then you will likely end up doing damage to 
     yourself or others. 

 (4) Windmills of this size are *NOT* toys. The amount of energy in a machine this size moving
     at full speed is downright scary, you could very easily do considerable damage to
     structures and people (including killing them) in a radius of 2 Km (1.3 miles) around the 
     location of the tower, possibly even further if you put it on a really tall tower. Keep 
     this in mind when you experiment with windmills, there is absolutely no fun at all in 
     turning a school bus into a giant shish-kebab by hurling an 8' windmill blade through it 
     at 400 miles per hour. 

     If you do not understand the engineering and manufacturing challenges of building
     something like this then please go and collect poststamps or find another hobby that is
     safe and within your area of expertise. I have a large amount of experience designing
     mechanical stuff and in fabrication and the complexities and challenges involved in 
     windmill design - as well as the enormous energies involved - have left me with nothing
     but respect for the wind and its ability to destroy things and to surprise you.

 (5) If this is your first windmill by all means stop now and build something smaller and 
     simple first, see 

            http://www.fieldlines.com/ 

     the people there have tons of experience making machines that are much simpler to 
     reproduce than this one. This machine is complex, far from perfect and requires a lot 
     of tooling and expertise to build and to operate safely. Please take this serious.

 (6) This project, the code and the design is licened under the:

     http://sam.zoy.org/wtfpl/

     Wtpfl license. 

Now, with that out of the way, and assuming you are still reading:

This package partially (there is some stuff missing, but if you can't figure that bit out
you really shouldn't be building this) describes the bits and pieces that are required to 
build a horizontal-axis 2.5 KW design power 16' wind turbine. 

Such a machine is suitable for the power requirements of a single home assuming there is 

  - enough wind

  - some kind of backup system (for instance, solar power or a diesel generator)

  - a battery pack 

  - an inverter

  - a rectifier to take the AC current from the windmill and turn it into DC

A windmill is part of a system, it is not a stand-alone source of usable power and you need 
to take this into account.

The windmill itself (professionals (and snobs) call them 'turbines' because they don't mill
your mustard seeds but here in .nl where I live we call water pumpers windmills and so on 
so forgive me if I stick to the term windmill, if you have trouble with that then please
imagine it milling the wind) consists of several structural elements that give the machine
a way to attach to the post that it is mounted on, a main shaft, a rotor, a stator made 
up from laminates, a governor, a set of blades and a tail. 

Lots and lots of pictures about the construction of this machine can be found at

http://pics.ww.com/v/jacques/renewables/windmill/ 

the directory tree that goes with this package contains:

cad-drawings         All of the .dxf files that I could find 
cutter-jobs          The job files ready for transmission to the homebrew plasmacutter/mill
programs             Software used to design the various parts in a parametric way

Here is a verbal description of all the parts/construction of the windmill, all the bolts are 
copiously covered with 'never seize' aka copper grease. You will likely balk at the price when 
you buy this stuff but you will balk a lot worse when you want to dissassemble the machine
three years down the line if you don't use it. I have not listed the 'small fry', nuts and
bolts, I assume you're smart enough to figure out that if a hole is threaded for 3/8" that
that's the bolt that goes in there. All the bolts used in the construction are regular grade
hex head inox or anodyzed. Bolts that are subject to vibration are held down with locktite 
blue. 

There is no handholding here and I'm afraid I can't offer you support if you decide to build
this machine. So be prepared to do some figuring out and fixing if you find something in this
description is wrong or if you think you have a better plan. Most of the sizes used are in 
*Imperial* measurements, I was building this machine in North America. With a little bit of 
work you can adapt those measurements to the metric system, I'd go for a drum outer diameter
of 300 mm and work back from there if I wanted to build this machine using metric components.

- support structure
  (1) Main housing, upright tube
      4" od, 1/2" wall technical tubing, 12" long, hole milled in the center for the slipring
      assembly (bronze riders on trespa making good contact with sliprings around the shaft
      that connects to the tower stub) milled out at a 15 degree angle at the top to accept (3)
      which will be welded in place. The bottom end of this tube is milled out to accept two
      bearings id 2", these bearings are locked in place using lockrings, which are placed
      in a groove turned into the wall of the tube.

  (2) The support shaft. 
      This shaft is hollow so the wiring for the 3 phases can pass through
      the center and be connected to the sliprings. Another bearing is seated at the bottom
      of this tube. The shaft itself will be stationary with respect to the tower, so the 
      machine rotates around it as it orients itself with respect to the wind. 

  (3) Main housing, horizontal tube
      4" od, 1/2" wall technical tubing, 18" long 2 bearing holes cut out at each end. Bearings
      are 2" id which will accept the main shaft (4), again secured with lockrings placed into
      a groove turned into the wall of the tube. 

      http://pics.ww.com/v/jacques/renewables/windmill/dscf0272.jpg.html 

      Shows these components before welding up, in the picture you can see that the shaft and
      the stator mount are already in place. 

 (3a) the statormount
      See the file spacerring.job

  (4) The main shaft is a 2" solid high tensile steel shaft, a (4a) 3/4 " steel disc with a 
      hole od 4", id (of course) 2" is welded on to the end sticking out the front onto which 
      the governor base plate will be bolted. The end of the shaft is threaded with 3/4" 
      thread to accept the central post along which the rider will move.

 (4a) Disc welded to the main shaft, 3/4" mild steel, 12 hole pattern to mate with magnet drum
      and governor base plate (13)

  (5) 4 bearings, 3" od, 2" id (I used SKF but this is not overly critical, I'd use a quality
      brand though because a bearing failure can have dramatic consequences).

  (6) Lockrings to secure the bearings in their spots

  (7) A stub that matches the tower inner diameter, with a hole large enough to accept the 
      shaft. Keep a bit of space here, secure the machine against lifting (yes, that can
      happen, don't let it happen to you) by bolting it down from three sides with bolts
      that are threaded trough the stub *into* the shaft. 

- The stator
  (8) 48 sheets of mild steel (preferably with good magnetic properties) cut into the shapes
      described in the files statorproto2_00.job through statorproto2_47.job These sheets are
      placed on top of each other after making sure they are nicely flat, then welded *ON THE
      INSIDE* where they ride against tube (3). This is to reduce eddy currents, if you weld
      them anywhere else you will be generating a lot of heat but very little power.

  (9) Copper coils #18 wire, 100 windings per coil in sets of 6, leave wires plenty long
      so you can route them comfortably to the electrical box.

 (10) slot paper to coat the inside of each coil slot so the coild don't ride against the metal

 (11) after placing the coils liberally coat the stator with thermally stable resin to fix 
      the coils into position 

 (12) mark the 'hot' end of each coil and mark the set number to make sure you know what to 
      connect to what when you're done. 

- The governor
 (13) Cut the governor base plate according to governorbase.dxf, I made the baseplate for my
      machine out of 3/8" mild steel, if I did it again I'd use 1/2". The reason why is that 
      the bearings for the blade shafts can bind under heavy load and this may interfere with 
      the governing action leading to overspeeding. 

      A 1/2" base is a lot more sturdy (it is also a bit heavier) and will prevent this 
      binding. Another way to improve on this part is to strengthen it by welding a piece 
      of angle iron left and right of the spots where the bearing support blocks will be 
      mounted.

      http://pics.ww.com/v/jacques/renewables/windmill/dscf0289.jpg.html

      shows the governor base plate

      The governor baseplate is mated to the alternator drum, the bolts go right through the
      alternator drum into (4a) mounted on the main shaft. 

  (14) The bearing support blocks (2 sets of 3)
      These blocks are made out of mild steel and are shaped to receive a bronze bearing with
      id 1". These bearings need lubrication and there is a little lube nipple mounted in 
      each of them with a channel that reaches the bearing (which has a hole mated up with the
      hole in the support block).

      In this image you can see the bearing support blocks on the right hand side

      http://pics.ww.com/v/jacques/renewables/windmill/dscf0286.jpg.html

      Originally I was going to use only three of them but later I changed the design and added
      the three short blocks at the back. The short blocks are mounted with two bolts, the 
      longer ones (which take the brunt of the force of the blades) are mounted with 4 bolts 
      each.

  (15) The bearings (2 sets of 3)

      These are bronze bearings, 1" inner diameter with a spiral groove for lubricant. I've 
      sized them to sit just inside the bearing blocks (14), they're a press fit inside the 
      blocks.

      At the pressure end (so at the rear) there is a small 1" id needle bearing that makes sure
      the blade shafts (17) can rotate freely even when the mill is spinning. If there wouldn't 
      be a bearing here then the back of the nut that holds the shaft under tension would rub 
      against the stationary bearing housing. On either side of the needle bearing there is a 
      ring id 1", and a similar arrangement is present on the blade side. The nut at the back 
      end of the shaft holds the whole arrangement under very light pressure. 

 (16) The weights (set of 3)
      The weights are made out of 1/4" steel sheet, according to weights.dxf and the large 
      shapes on linkage.dxf. They're stacked together as shown in this picture:

      http://pics.ww.com/v/jacques/renewables/windmill/dscf0288.jpg.html

      And then welded up with 'invisible' welds. A 1" nut is welded onto one side of each 
      weight.

 (17) The blade shafts, 1" stock shaft, welded onto (18), with a small ring welded onto the 
      end 

      closest to (18) so the blade mounts ride free from the bearing blocks.

      http://pics.ww.com/v/jacques/renewables/windmill/dscf0303.jpg.html

      The shaft is threaded over the length from the back of the main bearing block all the way
      to the end, this thread will thread into the nut on the weight and will be used to secure
      the blade at the rear bearing block. (yes, this means that the back bearing block is
      touching the thread, which is not ideal, on the positive side the movement is very subtle
      and there is not much force on that part, it mainly helps to stabilize the shaft and to
      prevent binding of the linkage).

 (18) The blade mounts (3x)
      these are made of 2"x1" bar stock, threaded with bolt holes to accept 4 bolts on each side
      to fix the blade mounting plates. The blade mounts are welded onto the blade shafts. This 
      is a *VERY* critical weld, take your time, make sure it is 100% true, check for 
      deformation after welding and correct if neccesary, anneal this weld to make sure there is 
      no remnant stress and avoid hardening. 

 (19) The Rider
      The rider is a small tube of mild steel with a 3/4" hole in the center which will ride 
      along the 3/4" threaded rod sticking out of the main shaft. It has three sets of 'ears' 
      welded on to it that are used to connect the linkage (with a bolt through each hole).  

 (20) The linkage (3 sets)
      The linkage connects the weights with the rider, the linkage transfers the force exerted 
      by the weights and causes the rider to be pulled into the direction of the governor 
      baseplate.

      The rider is pushed in the other direction by the spring that is coiled around the 3/4"
      threaded rod sticking out of the main shaft. The top of the threaded rod sticking out
      of the main shaft is stabilized by running threaded rods from the perimiter of the 
      governor base plate all the way to a small steel disc at the end of the rod. You can
      also use that to connect a nose cone to protect the governor mechanism from the 
      elements.

- The rotor

 (21) The Rotor Drum
      The rotor drum is 12" od tube that with 1/4" wall, 4" high. This holds the 18 magnets (23) 
      in place. 

 (22) The rotor drum spider
      The spider is the shape sitting at the top of the rotor drum, it connects the rotor drum 
      (21) to the disc at the end of the main shaft (4a). The spider has been drilled with 12 
      holes, 6 of those holes are recessed holes for bolts that will hold the rotor drum in 
      place when the governor is taken off. 

      The governor bolts pass right through the rotor drum spider into the holes in (4a).

 (23) The magnets
      18 2"x1"x0.5" neodymium magnets are placed at equal distances along the inside of the 
      drum, aligned in such a way that each of them has about 1/4" of magnet above and below 
      the stator pack. 

- The blades

 (24) The blade mounting plates (set of 6)
      Size pieces of 1/4" mild steel 8"x8" drilled with holes to mate with (18) and drilled 
      with a hole pattern to mate with the blades (25)

 (25) The blades, made according to the coordinates in 

      jam2.back.job
      jam2.front.job

      Registration of front-to-back is critical, make sure that the Z axis registers 
      perfect or there can be substantial variation in the shape of the blade (because it 
      is very thin even the slightest change will cause huge changes in contour).

      Feel free to play with blade.py to create your own job files for your own blades.
      You will need pygame, tkinter and the scientific python package, this stuff was done
      in the dark ages (2004), chances are that you'll need to tweak things a bit to get it 
      running because of changes to those packages. 

      Sharp cookies will have noticed the governor.dxf file in the cad-drawings directory, 
      note that that is not the design that was eventually used (the shafts were made longer 
      and the a second bearing block at the back was added for more rigidity). 

      In the 'plasmacutter' directory you will find a whole pile of code that can be used 
      to read .job and .dxf files, to control a plasmacutter if you should have one laying 
      around and to simulate a 3D gantry mill on the screen of a computer to save on 
      materials. 

 I'm not sure if any of that is of any use but if you should get it to work I'd like to 
 hear about it. My email is j@ww.com, twitter is @jmattheij

 You will be able to find the files that come with this article on:

 http://jacquesmattheij.com/windmill.tar.gz (300 MB, be kind to my server, if you don't 
 need it then don't download it!)

 If you find I made any mistakes above (which I surely did!) please leave the corrections 
 in the comments thread on this page, that way if someone decides to follow in your 
 footsteps they can save themselves some time and trouble. 

 Have fun tinkering!
</code></pre>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[How to build a windmill]]></title>
    <link href="http://jacquesmattheij.com/how-to-build-a-windmill"/>
    <updated>2012-09-27T10:37:00+02:00</updated>
    <id>http://jacquesmattheij.com/how-to-build-a-windmill</id>
    <content type="html"><![CDATA[<p><img style='float: left; vertical-align: text-top; padding: 10px;' border=0 src='http://pics.ww.com/d/92271-3/dscf1145.jpg'> Windmills have always fascinated me and for a long time I was dreaming of one day building my own. Where I live there are still machines from the 1600&#8217;s that are just as magnificent today as when they were first built. When you see one standing in a field rotating and converting passing air into usable energy they look like simplicity incarnate, but nothing could be further from the truth.</p>

<p>They&#8217;re complicated beasts even the most humble water pumper or a decorative item in someone&#8217;s garden. As soon as it is allowed to rotate freely driven by the wind there are a lot of things that you should take into account. And if you don&#8217;t one day you&#8217;ll wake up to find bits and pieces all over your yard, or worse.</p>

<p>The reason for this lies in the nature of the wind. That gentle breeze cooling you down on a summer morning and a gale 10 force flattening trees and ripping up buildings are only separated from each other by a single metric, the wind speed. The amount of energy that passes through a given area goes up as the <em>cube</em> of the speed(*). So a windmill that is spinning happily at its designed windspeed of 10 meters per second will have to survive in an environment where the amount of energy put into the system is a very large multiple of the energy at the designed (or &#8216;rated&#8217;) speed. That is a very difficult engineering challenge to overcome.</p>

<p>There are a number of strategies for mitigating this problem: shutting the windmill down (which requires a <em>reliable</em> mechanism to do so) above the rated speed or gradually reducing the fraction of energy that the windmill extracts from the wind.</p>

<p>Even the shutdown concept, which seems to be at first glance the safest approach is quite a challenge. Once a windmill is moving shutting it down is not something that is going to work unless you&#8217;ve really thought the problem through. Mechanical brakes have been used since the dawn of windmill construction, and they&#8217;ve caused many a windmill to burn to bits before the wind could rip them apart. Typically they work best when the windmill isn&#8217;t moving yet but the usual time when you find out that you want to shut down is when the machine is already working. Friction + a ton of energy = lots of heat. If the heat has nowhere to go the machine will at some point ignite the grease in the bearings or it will simply function as a very large scale fire bow. The end result is as predictable as it is sad.</p>

<p>So enterprising engineers figured out other ways to deal with this seemingly simple problem. Some involve designs that will move the windmill at an angle to the wind reducing the effectiveness of the blades. Figure the surprise on their faces when they realized that a windmill once it is spinning has two stable attitudes if you discount the tail, sideways into the wind where it will slow down and head on where it will speed up until it blows apart. So that trick does not work very well with windmills that can seek their own direction. Lots of methods to do this have been tried, many of them are usable to some extent (furling as this technique is called can also be done along other axis, for instance upwards). Others concentrate on the blades themselves, changing the angle of attack so the blades will not be as effective as they are below the rated speed. This latter method is known as pitch control and it is one of the most complicated but also one of the most effective and reliable ways of dealing with overspeeding.</p>

<p><img style='float: left; vertical-align: text-top; padding: 10px;' border=0 src='http://pics.ww.com/d/90582-1/dscf0298.jpg'> The design parameters of my homebrew windmill are: 2.5 KW of output at a windspeed of 10 m/s, variable pitch blades, rotor diameter 5 meters (about 16&#8217;). The total weight of the machine is about 85 kilograms (or about 170 pounds). It has survived numerous storms and worked very well supplying our house with reliable power, far more reliable than the solar panels we had used exclusively up to the point the windmill was finished. The plan was to open-source the design and to make available a list of parts. I really should get around to that one of these days, the fact that I finally had the time to do this write up means that there is hope ;) If you bought a machine with those specs commercially it would have cost about $10,000, but that would not be a variable pitch one. This machine cost a (fairly) large multiple of that, not counting our time, tooling and so on, but it could be reproduced well under that $10,000 mark if you already had all the tools and the knowledge and you didn&#8217;t have to go through a prototyping stage. Prototyping is very expensive and time consuming.</p>

<p>Designing a machine that size was a lot harder than I ever thought it would be. What was intended to be a one summer project turned into a two year tour of technology including magnetic theory, power generation, mathematics, mechanical engineering, woodworking, metalworking, meteorology, CAD/CAM, computer programming, electronics and aerodynamic theory. If you feel like acquiring some real world skills, go build a windmill! I never ever realized how much knowledge goes into making one of these until I tried it for myself.</p>

<p>The most demanding bit in my spec was that the windmill should be super reliable and should not require maintenance other than a lube job once every year or so. The place where it was put up has some of the harshest climate conditions on the planet, winters with days of -40 celsius and summers of +35 and sometimes even higher. Taking the windmill down during the winter was absolutely not an option (too much snow and no grip for the tractor used to raise and lower it) so reliability was extremely important, being without power meant that our house would be inhabitable almost instantly (no backup power grid, we did have a stand-by diesel generator which was used quite a bit before the windmill was installed).</p>

<p>When starting out I thought this was going to be a one-man job. I did not intend to involve as many people as it eventually took and I&#8217;m really grateful to all the people that lent a hand (or two) at fulfilling my dream and that helped with their knowledge, skills and time. Without that it would have never ever worked.</p>

<p>Windmills consist of several major components: a structure that holds the generator, typically a tower of some sort, an alternator, an optional gearbox (the one described here is direct drive so there is no gearbox), a rotor plate + (optional) governor that holds the blade assembly and the blades themselves, and finally a tail.</p>

<p><img style='float: left; vertical-align: text-top; padding: 10px;' border=0 src='http://pics.ww.com/d/90721-3/scale_model.jpg'> To learn more about how windmills work I decided to build a 1/2 scale model first. It probably doesn&#8217;t seem like a big difference, 15 cm (about 6&#8221;) or 30 cm (about 12&#8221;) for the rotor drum that holds the magnets but the scale model you can pick up with one hand whereas the &#8216;real&#8217; thing (the scale model is just as real, it is a functioning machine) takes two adults to lift it. The idea here was that all or most of the trouble that would be experienced in the large machine would be present in a smaller one, where mistakes would be cheaper and easier to fix.</p>

<p>The first problem we hit when building the scale model was that even though the machine was quite simple and small, the precision required to make the pieces was well beyond what I could do with the hand tools that I had available when I started this project. Bit by bit we assembled a pretty formidable array of metalworking tools. In the 80&#8217;s I&#8217;d co-founded a CAD/CAM start-up which had taught me a lot of metalworking skills and those came in pretty handy. We bought a lathe and a mill and used these to make the drum and various other componenents of the scale model. Of course I could have outsourced the work but I really wanted to do this myself. What use are skills if you can&#8217;t use them :)?</p>

<p>We hit a serious roadblock when we came to manufacturing the stator, the part of the alternator that holds the coils used to generate the electric current. The difficulty was that the design called for an &#8216;inside out&#8217; stator. The reason why is that I&#8217;d observed a tendency in windmills run by members of the same forum that I was active on at the time tended to spit out magnets leading to catastrophic failure. By inverting the design, putting the rotor on the outside as a drum instead of on the inside the force on the magnets would simply push them harder against the drum they were placed in, instead of attempting to eject them from a spinning core where they were on the outside. At first sight that was a no-brainer, but making an inside-out stator was a lot harder than using any one of a 100 different models used in the industry where the coils are on the inside (almost any electric motor has that arrangement) of the laminations. So we ended up having to manufacture our own stator elements.</p>

<p>The stator consists of a stack of thin metal sheets, each insulated from the other to reduce an effect known as eddy currents. Eddy currents are bad for two reasons, the first is that they cause the windmill to be less efficient, the second is that they tend to warm up the stator and that can lead to failure of the whole machine if it gets out of control. Coil losses are bad enough to contend with.</p>

<p>Each stator sheet is a circle with some mounting holes on the inside, and then a bunch of &#8216;fingers&#8217; radiating outward and little edges attached to the fingers to hold the coils. Imagine a dinner plate with capital &#8216;T&#8217; letters tacked on to the edge radiating outward. Drawing that in the cad tool was really easy, but realizing the drawing in metal turned out to be very hard indeed.</p>

<p>At this point we took a 6 month detour in the wonderful world of sheetmetal fabrication. This was a lot harder than it seemed at first. Finally we settled on using a plasma cutter to cut the stator elements from standard sized sheets of metal (a special kind, which is low on carbon and has very good electromagnetic properties). Die cutting was impossible due to the cost of the dies, but if this were ever produced in volume that would be the way to go).</p>

<p><img style='float: left; vertical-align: text-top; padding: 10px;' border=0 src='http://pics.ww.com/d/11225-2/dscn3995.jpg'> A rig was built to hold the plasma cutting head and a sheet of metal, the whole thing operated by stepper motors connected to a small computer that ran some homebrew controller software to translate the design (made using &#8216;qcad&#8217;) into metal pieces. Building that machine and getting it to work properly was a fairly big project all by itself, in many ways more complicated than building the windmill! One interesting sub-problem was that to make the plasma-cutter gantry we needed to have - you guessed it - a working plasmacutter. We solved this by hacking one out using the hand torch to bootstrap the machine, and then used that to make the real gantry.</p>

<p>Working thin sheets with a plasmacutter is very difficult. The first attempts failed horribly, the sheet would deform during the cutting causing the plasma cutter to come in contact with the sheet of metal (this is called a &#8216;strike&#8217;) which would short out the arc ruining the plasma tip (they&#8217;re consumables but they are not cheap) and this would cause terrible deformation. During cornering the cutting speed was too low which would cause the tops of the &#8216;T&#8217;s to melt off because too much heat would be injected. Thin sheet is a very hard material to work using torches. Little by little we overcame these difficulties, the cutting speed by coming up with a way to make the stepper motors work much more smoothly (instead of ramping down to &#8216;0&#8217; at right angles we ended up using very small arc segments or to purposefully overshoot the desired spot at speed and then to hit the 90 degree turn by making a 3/4 circle going the other way, which kept the cutting head moving at a nearly constant velocity, and any slowdown would occur in the scrap portion of the sheet).</p>

<p>To make the increase in speed possible the gantry was redesigned to be much lighter than the original which allowed for faster acceleration and deceleration which in turn made the cuttings much more regular and consistent. Originally the gantry system weighed about 80 Kg (about 160 pounds), the redesigned version weighed in at only 18 Kg (36 pounds). I came up with a funny way of using the cutter, I don&#8217;t think it was intended that way but it worked wonderfully. Instead of cutting all the way through some parts of the machine we&#8217;d simply score them, running at a speed much higher than the one required to make a full cut. This then leaves you with a nice &#8216;fold here&#8217; line, after which you just fold them over and weld the edges up. You end up with all kinds of very rigid and precise box like structures like this. This technique was used to make the motor casings and the Z-axis support structure.</p>

<p><img style='float: left; vertical-align: text-top; padding: 10px;' border=0 src='http://pics.ww.com/d/90707-1/laminate.jpg'> Once we finally had the stator sheets ready they could be stacked and placed in the now nearly finished 1/2 scale alternator. During testing it produced about 500 Watts at 600 RPM, which was more than we had hoped for (the reason for this turned out to be that I had missed one elemment during the calculation of the the gap between the magnets and the rotor drum, I&#8217;d simply subtracted the magnet height from the rotor drum inner diameter but of course (well, in retrospect everything is obvious) the rotor isn&#8217;t flat but curved inward there, which caused the magnets to ride slightly higher and hence the airgap was smaller than it should have been resulting in an increase in output power).</p>

<p>With a working scale model of the alternator in our hands we began work on the larger version. The design was scaled up and we spent a few months on making all the parts for the real thing. All of the experience we gained making the scale model paid off and the 1:1 version of the alternator worked as designed the first time we tried it.</p>

<p><img style='float: left; vertical-align: text-top; padding: 10px;' border=0 src='http://pics.ww.com/d/90606-1/dscf0310.jpg'> Here you can see the finished stator mounted on the base, the slant in the stator pack is to reduce &#8216;cogging&#8217;, the effect caused by the magnets lining up with the stator elements. If you don&#8217;t do anything about that the machine will vibrate terribly which will reduce the life-span and it will need a lot of wind to get going which means that you will be making substantially reduced power over a given amount of time. We used the big lathe as a test rig, the alternator fixed on the tool support and the lathe driving the rotor drum. We could easily stall out the lathe by loading up the alternator!</p>

<p>Next on the todo list was the rotor plate which would hold the blades and the bearings that allowed the blades to change pitch. The idea behind this rotor plate was a very simple one: each of the blades would be free to rotate around a pivot mounted on the rotor plate, the three blades would be kept synchronized by tying them all to a central &#8216;rider&#8217; which would go up and down on a central shaft. Piece of cake ;). It took three tries to get this right, the pitch control mechanism worked by having a weight attached to the shaft for each blade, which was pushed out by the centrifugal force and a spring that pushed the rider back up. This gave a lof of adjustment options to change the dynamic response of the governor. Spring tension, starting angle, ending angle, pre-tension and an ending stop to limit the travel of the blades all controllable with two nuts riding up and down on the central shaft. In retrospect I would change one small detail here, I would add a hydraulic or air based shock absorber to reduce the speed with which the governor rider can move up and down the central shaft. That would have made the machine a bit more gentle in its responses to sudden wind speed changes. I never realized how quickly the wind can change direction or speed and the windmill would follow these changes almost instantaneously.</p>

<p><img style='float: left; vertical-align: text-top; padding: 10px;' border=0 src='http://pics.ww.com/d/90622-1/dscf0318.jpg'> Even though this was time consuming and lots of solutions were tried and discarded this was by far the easiest portion of the whole prototyping process, the governor was tricky to figure out but relatively easy to manufacture. The weights in the picture as well as the base plate were cut out of 8 mm sheet steel (3/8&#8221;) using the plasma cutter. The weights are stacked segments that are then welded up and finished. This gives the same effect as a solid but is much easier and quicker to make than milling the same structure.</p>

<p>After the rotor plate and the governor mechanism were done we began work on the blades. Making three windmill blades that are <em>identical</em> in wood is hard. Wood, being a natural material is of variable density, and moisture will cause that density to change over time. Wood also doesn&#8217;t really like to keep its shape. After trying to make some blades by hand we settled on converting our trusty plasmacutter rig to become a 3D milling machine. The size was just about right so we could make a blade in two passes (one for the front, one for the back).</p>

<p><img style='float: left; vertical-align: text-top; padding: 10px;' border=0 src='http://pics.ww.com/d/90348-1/17_0ct_2004_ronwithblade.jpg'> At this point I found that I had a friend in Texas who really liked the project and would mail me in the evening with the solutions for the problems we&#8217;d have the next day.</p>

<p>He kept on doing this and after a while I jokingly told him that if he really knows what we&#8217;ll be up against tomorrow, why not come over and give us a hand. And so he did! Enter Ron Brown, Texan, woodworker extraordinaire. Without Ron this whole project would have failed miserably at the &#8216;making the blades&#8217; stage, the bit that we all thought would be the easiest part of the whole project.</p>

<p>Ron taught us a lot about wood, woodworking, making windmill blades in general and using a 3D gantry mill to make complicated objects with repeatable accuracy.</p>

<br />


<p><img style='vertical-align: text-top; padding: 10px;' border=0 src='http://pics.ww.com/d/90730-3/snapshot5.png'></p>

<p>I wrote a small interactive python program to help with the design the 3D contours of the blade which then produced a file used by the program written earlier to control the gantry mill.</p>

<br />


<p><img style='vertical-align: text-top; padding: 10px;' border=0 src='http://pics.ww.com/d/90727-3/snapshot4.png'></p>

<p>Trial runs in wood are expensive so I made a simulator of the 3D mill that showed on the computer screen what would have happened if we ran on the mill. This saved several forests. After we were confident we got the geometry right we prototyped a bunch of blades in foam and when we finally had ironed out the kinks and dealt with the challenges of &#8216;registration&#8217; in a two sided piece (both sides of the blade are curves) we switched to wood. A very nice lot of knot free white pine was hand picked by Ron and used for the blanks that we made the final cut of the blades from.</p>

<br />


<p><img style='vertical-align: text-top; padding: 10px;' border=0 src='http://pics.ww.com/d/90360-1/17_0ct_2004_trueblank2.jpg'></p>

<p>A few months after Ron joined our little band of windmill making friends we had three identical to a very small fraction of a millimeter absolutely flawless blades sitting on the bench with trailing edges so thin that you could read the newspaper through them. We sat around for a day just looking at them :) These were then given a coat of fibreglass and using an ingenious system that Ron came up with that would make them rot-proof for many years were mated to the rotor plate. For the first time all the components were ready.</p>

<p>The machine was painted a spiffy blue, the blades white, sliprings and an electrical connection box were added and we set off to place it on the tower that we&#8217;d installed over the summer.</p>

<br />


<p><img style='vertical-align: text-top; padding: 10px;' border=0 src='http://pics.ww.com/d/90676-1/dscf0345.jpg'></p>

<p>The final assembly took place in the rain, and by the time we were done it was too dark to even see the machine sitting on top of its 20 meter high (60&#8217;) tower so we took it back down and waited until the following morning. We also had to tweak the balance a hair once it started moving, you can get only so close with static balancing alone. For proper balance you have to observe the machine moving. The slightest error and it will show up as ever increasing oscillations and vibration in the mount. We ended up balancing the machine on the ground and there is not much else that is scarier up close than a windmill of this size running at a few hundred RPM. You really have to have good faith in your design and welding skills. I must have checked the mount 50 times before trying this. The rotor weighs in at a good 40 Kg and I&#8217;d hate to think what would happen if it struck something (or someone). There is a lot of energy in a system like that and the blade tips move at roughly 150 meters per second ((3.14 * 5 * 600) / 60) (550 Km/h or about 330 MPh) when it is going at its rull speed of 600 RPM! Nothing to sneeze at.</p>

<p>Running it for the first time and seeing it make power was - outside of my children being born - one of the high points of my life to date and even though from an economical point of view this project was an absolutely terrible loss the amount of satisfaction of seeing a dream like that come true is truly amazing. In the end the machine produced 2250 Watts at 10 m/s winds, so a hair under design power. Probably with some more tuning of the airgap we could have gotten spot on but 10% more did not seem worth re-doing a substantial portion of the work on the rotor drum. That would also mean running the coils close to their maximum temperature and it doesn&#8217;t hurt to have a bit of safety margin there.</p>

<br />




<center>
<img style='vertical-align: text-top; padding: 10px;' border=0 src='http://pics.ww.com/d/90696-3/firstrun.jpg'>
</center>


<br />


<p>Many thanks to:</p>

<p>Ron Brown</p>

<p>Tom Wilkinson</p>

<p>Dan Bartman</p>

<p>Matt Bartman</p>

<p>Wayne Abraham (+)</p>

<p>Mirka Jucha</p>

<p>Chris Stevens</p>

<p>Ed Arthurs</p>

<p>Johannes van den Dop</p>

<p>Laurence &amp; Dina McKay</p>

<p>All the people at otherpower.com/fieldlines.com that helped with tips and tricks, especially &#8216;flux&#8217;, &#8216;kurt&#8217;, &#8216;donc&#8217; and &#8216;marty&#8217;. Out of sight is not out of mind guys, you may be a continent away these days but you&#8217;re not forgotten.</p>

<p>For many more pictures: http://pics.ww.com/v/jacques/renewables/windmill/</p>

<p>(*) Edited after a comment on HN pointed out an error here. Thanks HN :)</p>
]]></content>
  </entry>
  
</feed>
