My code is trying to kill me

Is this still on?


I'm just wondering if my static publisher is still working. I just noticed that I eat my own dog food (that's Spolsky's term - google it, I don't know how to add links now). In the last few years I wrote some applications that I use often, some of them daily, and they just work.

Hm, the problem is that I don't know my markup syntax anymore. Well, let's do the plain-text only now.

Static publisher - I'm using it to post articles on the blog and they are formated exactly as I want them. I didn't use it fore some time but if you are reading this online then it works.

Car sharing monitor - I have a web app that crawls facebook car sharing groups to find me a ride when I need one. Without that app, I would have to monitor facebook groups and manually search for rides on my route. If I am too slow, on busy days rides get full in minutes. This app monitors groups for me and alerts me if it finds the ride on my route. I'm usualy able to reserve my ride before anybody else.

Stock monitoring app - Not the live monitoring, I don't need that. I'm trying to be a value investor. This app downloads financial information about companies, their fundamentals and price. I wrote a formula that scores the stock depending on its value and selects what should my portfolio look like and compares to the current state. Of course, the hard part was to learn everything about investing. This app is my knowledge base. It's also fun to apply math to finances.

N3R (Not Really an Rss Reader) - my most used app ever. When Goodle pulled the plug on their RSS reader (Google reader?) I was in trouble. For years I currated my list of blogs that are worth reading. It shouldn't be a problem to switch to another Rss reader, right? But it is, because what I expect from Rss and what they all provide is so different. I just need a notification that there is a new article, and when i click on it it should open the article in a new window, in full context of the website and mark the item as read. And now I have the app for that.

Static publisher features



  • read Writemonkey files
  • create static html file for every article
  • create static html file for all articles combined
  • recognized markup: H, UL, LI
  • one click publish to local folder or ftp


  • local index of file - upload only changes


  • delete surplus files on destination and ftp


  • categories, tags, types
  • service that publishes in background
  • probably should use third party markup to html converter
  • mark some texts as tweets or facebook posts and automatically post or tweet them to my timeline
  • create rss

Project Economix 7 - money


To implement money in the simulator, first I need to know what money is. Last time I wrote why it was invented and why it is necessery. But how does it work and how it did emerged?

You can google it yourself and find many plausible theories, I'll just sumarize the parts I think are important.

First, imagine the world without money where you trade by bartering; it's possible but problematic. A farmer can trade some apples with a toolmaker for a new tool. But he can't trade apples for strawberies because when strawberries are ripe, apples are not yet fully grown. What he can do is to promise he'll give some apples in a few month for strawberies he will get now. So, the root of money is a promise, you can call it debt. If two farmers trust eachother, they can make such trade.

In a small community, it is quite possible to trade without money, only on promises. But how many promises can I give to someone? Can a farmer promise he'll give tons of apples? He can, but only if he has a large apple orchard. He actually have a credit rating to his promises. The more productive he is now, the more promises he can make. So you don't need money to have debt, credit and credit rating. That seems to be inherent to the trade system.

Project Economix 6 - trade


Society is pretty limited with only resource gathering and consumption. Everybody is just scavenging for the basic resources and spending them or resting if they have enough.

To reach a more complex society, we need two main ingredients:

  • specialization: instead of everybody doing everything, people can specialize and become experts in they field thus producing more
  • trade: if expert in one field can exchange products with expert in another field they both have more of both than if they didn't specialize

First version of trade is barter where products are exchanged directly: one unit of food for one unit of stone, one axe for three units of wood. Problem with such arrangement is that both buyer and seller have to want each other's product or trade is not possible. As a seller, you need to find not only someone who wants your product but he have to have something you want (Coincidence of wants).

That's way money was invented: it is necessary. In money trade, as a seller you just need to find somebody who needs your product and has the money. Then you can use it later to buy what you need from person completely unrelated to the first trade. Naturally, I tried to implement it too. But to implement the money naturally, without some unknown force printing money and putting it into the economy (like state is doing now), definitely it's not an easy task.

Project Economix 5


Quick summary of the project structure so far:

  • there is a world that contains a list of resources and a list of human agents
  • resources are renewable sources of products (forest gives wood, quarry gives stone...) with defined capacity and regeneration speed
  • processes are activities that require input and produce outputs, input being a resource or product and output being another product (stone cutting require query and produce stone, axe making require wood and stone and produce stone axe...)
  • humans are agents that can decide to run a process once per tick (world is ticking)
  • humans have basic needs that must be satisfied regularly to keep living: they have to spend food to eat, wood to warm up and cloth to dress
  • humans can reproduce when they decide to
  • executing a process takes time, this is simulated with cooldown time during which human cannot do any action
  • when human decide to do nothing, it's considered rest and counts as increase in quality of life
  • whem human executes a process, it gains skill in this process, meaning it takes less time to do it (shorter cooldown time)

With this framework in place, I can create various implementations of human and test how they fare in the world. They differ in how they make decisions, do they just consume everything they find or do thy plan in long term, how they behave in abundance of resources and what they do when resources are scarce.

Project Economix 4


In previous articles I defined and explained the Malthusian trap. But somehow we avoided it and the conditions are improving for humanity. What happened?

Let's try the island example from previous example. When people discovered agriculture, island could support 3000 people. Current 1000 inhabitants had to work harder but they lived comfortably and multiplied. When they reached population of 3000, conditions again dropped to bare survival, they still had to work hard and destroy the environment. How could they avoid that?

First and obvious option is to stop multiplying. But without harsh imposed limits on personal freedom that wouldn't be possible. But if in period of time when population was between 1000 and 3000 when island could support its population, somebody invented even better technology that could support even more population, they could avoid Malthusian trap. When population reach 3000, new population limit is 4000. When 4000 is reached, new limit is 5000. And so on.

Exactly that happened in Europe. From neolithic revolution to first industrial revolution (6000 - 10000 years), average living conditions didn't improve significantly. Break from Malthusian trap started with industrial revolution around 1800. Technology improved significantly and average income and wealth increased. As always, population increased; but before living conditions dropped, technology improved again. And then again, thus allowing us to keep or improve standard of living although the world population grew six time.

It seams we are now dependent on technology. Not only on current state of it, but we are dependent on growth. Without constant technological development we would return to bare survival. The question is, how much further can technology grow?

Project Economix 3


In short, Malthusian trap is an explanation for a problem happening to humanity where we tend to live constantly on the brink of starvation. Whenever we find the way to produce more food (or wealth) from natural resources, we tend to multiply until again everybody lives in misery.

Let's try to explain it with hypothetical example. Imagine an uninhabited island that can support 1000 people, hunter gatherer style. Now, 100 primitive people arrive on the island. What happens? They live in harmony with nature, they gather fruits from bushes and trees, they hunt for meat. They enjoy their lives, they are healthy, nurtured and happy. They live in egalitarian communities. And they multiply...

Soon, island have 1200 inhabitants and problems arise. There isn't enough food for everybody. People are malnourished, sometimes desperate and they start to fight. Population stagnates as more children do not survive to adulthood. Even worse, as climate fluctuates sometimes island can support even more people and population grows. But then, when climate changes, mass starvations occur regularly.

Some smart people try and succeed in growing plants, inventing the agriculture. Invention spreads, it is simple and everybody adopts it. It is much more efficient than just gathering what nature provides and now the island can support 3000 people. They don't live in harmony with nature anymore as they cut the threes whenever they need more land. They are working more and harder but they are again properly nourished as there is enough food for everyone. Technology made their lives better (or at least less miserable). And they multiply...

Project Economix 2


Funny things happen when you want to write code but first have to grasp the problem domain. And thoroughly so that you gotta learn something in the way. Supply, demand, elasticity... Simple stuff. I learn that in school. But programming the economy raises some new questions, like:

  • When does economy begin?
  • How does world without economy looks like?
  • Why can't we all be rich and prosperous?

Answers on first two questions are simple. Economy begins when resources are scarce. That's why you have economy for food but not for air. Air is still abundant, but food is not. Once air runs out in some way, there will be economy around it. Same happened with water. Selling water was unheard of two generation ago but it became completely normal to this generation.

Early hunter-gatherer society did not have food economy, anybody who was hungry could just pick or hunt something, there was enough of it. So, the questions is:

  • if there was enough for everybody and everybody was happy, why it didn't stay like that

Well, humanity is in the trap: Malthusian trap.

Project Economix 1


Writing an economy simulator is a kind of a project I always wanted to create but somehow I never did. Not that I do not try, I just never persist long enough for it to became more than quick attempt. I think I have two problems:

  • I can't define the scope
  • I don't understand the mechanisms

This are the problems on which I have to have some answers before I get to coding. They look simple only if you're ignorant enough. I strive not to be, so it seems I'm into serious research project if I want any results.

SourceSafe flashback


I was introduced to source control in the worst possible way: through the Visual SourceSafe. I was using it for 5 years in my workplace. As complexity of our development rise, VSS showed more and more of its problems. When I saw all the problems it had, I've put all of my home projects into Subversion and later introduced it in the workplace. After a four years of using SVN as my primary SCS, I stared using Mercurial for my home projects but I wasn't feasible to push it in the workplace as SVN worked fine. When I switched jobs, HG became my main SCS. All in all, 5 years of VSS, 5 years of SVN and 4 years of HG.

Today I tried the Team Foundation Version control which replaced Visual SourceSafe as the default SCS in MS Visual Studio, just to see how it looks, as I hear more and more good things about it. Although it includes project management features, I was primarily interested in source control part, especially in:

  • source control features: versioning and merging
  • tooling: integration with visual studio
  • workflow

I was positively surprised with TFS when we tried to merge code changes, that went well. Unfortunately, as a whole, it has some quirks I can't tolerate:

  • Commands are scattered over solution explorer, team explorer, source control window and some actions even open in browser.
  • It doesn't respect my folder hierarchy. I added a shared project to the solution from the folder outside the solution. That worked on my computer but other team members got a copy of the project inside the solution's folder.
  • It is a subjective difference, but unlike with HG, I don't feel like I'm in control of my source. It feels more like source control hope instead of source control system.

How do I test the game loop?


In short: you don't.

Tests you write are the game loop. The core elements of the game loop are:

  • read player's input
  • update the game state based on input
  • display the game state

From this three, you only test the middle one.

You can't test the player input or the display (well, you can, but you don't want to). In tests you don't read the player's input, you simulate it. You simulate it by calling functions that will be called when user provide some input. After you call that functions, you check the game state and assert your assumptions about the consequent state. Since game will draw the screen from this very state, you can be sure that it has the correct data to draw.

Static publisher motivation


I strive for years to write regularly on topics I'm interested in, but it seems I just can't do it. On one side, I'm perfectionist but on the other I'm not skilled yet in writing and also not quite fluent in English. That means I'm in constant deadlock where my every article is not quite good enough to publish it. Without publishing, there is no point in writing as you don't get any returns and without writing, my writing skills stagnate. So, either I won't write or I have to lower my criteria. This is the result: I'm writing my first article and publishing it as it is.

After settling down over my perfectionism obstacle, I need to simplify my workflow. I want to be able to fire up Writemonkey, spew my thoughts in it and be done with it. Current workflow that is based on copying text to Wordpress is too distracting. I want my workflow with my rules - and that's why I'm writing static site generator/publisher. With it I'll just write, and it will handle everything else. And as a bonus, I have first topic and few things to say about it.

And blog format just doesn't feel right. Sometimes I just want to create a short mind dump, like tweet or just a little longer, maybe I'll merge articles later. Sometimes I'll incoherently rumble about topic I don't fully understand. Other times I want to write a well structured research article. All those just aren't on the same level and publishing platform should respect this.

To writing


To actually have any use for writing tools and writing methods, you need to - well - write. Regullarly. Thus, the challenge:

  • write 5 days a week
  • at least 100 words on single topic per article.
  • worry about quality once you have something to worry about
  • delete articles deemed unworthy after one month.

Advice from lifehacker:

  1. Research or strong points are not necessary
  2. Delaying an article with the belief spending longer will make it better usually just means it won’t get written
  3. We should fear not publishing articles, rather than fearing the bad outcomes of putting something out there
  4. When I have a strong connection between writing and my higher level goals and purpose, it’s easy to write

There, this is the one for today.

Static publisher v0.1


After a day of coding and fiddling with css, ftp and html (those didn't feel like coding), I finally made basic functional publisher.

It goes like this:

  1. Fire up Writemonkey, write something and save it to source directory as text
  2. Run publisher

Simple enough. It creates one html file for every txt file and one common that serves as an index page. There is a lot of work left but I can add features incrementally while I'm using the software from the first day.