Reference Management in HTML

[EDIT – this article has been superceded by a newer one – click here to view it]

Writing well-referenced material is a chore. If you’re using LaTeX, then you’re in luck because it works with BibTeX to lessen the tedium. If you’re using a word-processor, you’re still in luck as you can use something like EndNote to manage your references. How about if you are writing a blog, or an HTML book, or contributing to a Wiki? Then, it seems, you’re out of luck.

Until now. Enter JSNote (Javascript Note). It works pretty much the same way that BibTeX does with LaTeX. You maintain a list of references in a separate file, and in your material you cite those references by means of calling a javascript function. For example;

// Filename /downloads/references.js
addRef ({name : "john",
year : "2012",
volume : "17",
author : "Charles Dodgeson",
title : "Obtuse Works of Mathematics in 'Alice in WonderLand'",
addRef ({name : "boehm_1",
year : "2006",
month: "May",
conference: "ICSE '06",
author : "Barry Boehm",
publisher: "ACM",
title : "A View of 20th and 21st Century Software Engineering",

And then, in your HTML you pull the jsnote.js script in, as well as your list of references and use them like so:

<script src="/downloads/jsnote.js"></script>
<script src="/downloads/references.js"></script>
<p>I now will reference Boehms article<script>cite ("boehm_1")</script>and then reference Johns article like this<script>cite ("john")</script></p>


The practical result is that the citations are all printed properly. The above example looks like this. Note that the list of references in reference.js works exactly like it would in BibTeX, namely that you can put the arguments in any order, or even leave some of them out if you don’t want them displayed. As long as each reference in the references list has a name, jsnote will be able to cite and display all the information you gave when adding it as a reference.

Literate Programming Is Not Dead Yet.

Get jsnote.js
Get a sample references file

Memory accounting routines for C

Managing memory is Hard. Very Hard. If you are programming in C you have a few options, notably valgrind. However, if you find yourself in the situation that I find myself in now in which valgrind cannot work, then you need something more.

For example, I’m writing code in ECL to call out to a few C libraries (that I’ve written myself). Valgrind is incompatible with ECL. In fact, it might just be incompatible with any GC-language. Whatever. I still need to keep accounting of my memory during testing.

Hence, I wrote this little replacement/wrapper for malloc. It stores all allocated memory as a list of blocks internally. It stores the filename, function and line number and the amount of memory that was allocated by each invocation of xmalloc. Usage is fairly standard:

int *foo = XMALLOC (sizeof *foo);


Easy? You can look through the header for all the options (how to dump the list of blocks allocated, some general statistics on allocation, etc). Also, this can be turned off while the program is running, and normal malloc() is then used.


Download the the xmalloc library

Writing fiction is for Dummies

I’ve been writing short works of fiction (not on this blog, of course, everything here is as fact-based as I can muster), and I’ve now got a full six short stories up on various sites.

You can get a nice overview of the short stories over here at smashwords. Feel free to read, review and rate. They are free, after all, although this state of affairs is not going to last if I can manage to keep up the pace for another four  months.

Why four months? Well, in about four months I figure I’ll have enough to put together a collection into a single book, which will then go on sale. At the moment though, if you like science-fiction, OR, wicked mind-games, OR short humour, OR Zombie apocalypse tales, then head on over to the smashwords site, and read, review, rate.

I’m open to suggestions, by the way, so feel free to email me about any of the short stories.

Baby Sex-selection at Conception

Everyone knows how to make a baby. When a mummy and a daddy love each other very much, they make a baby. Well, thats what we tell the kids anyway. There is more to that, however.

The ovum is released  roughly 14 days into the womens monthly cycle. The sperm cells can survive for between 3 and 5 days. The ovum will be viable for only 24 hours (or less). Hence, intercourse must occur before ovulation, and ovulation must occur before the sperm cells all die.

Hence the fertile period  (the best time to make love in order to conceive a child) is during those 4- 6 days (sperm cells will survive for 3 – 5 days, and you can still make love on the 4th – 6th day when the ovum is descending the fallopian tube). It’s pretty easy to mark these days off on a calendar.

What most woman don’t realise is that not all fertile days are equally likely to result in a boy or a girl baby. Making love on certain days is more likely to result in a boy baby, and making love on other days is more likely to result in a girl baby. This is due to two particular characteristics of the sperm cells. For a more thorough explanation please see this document over here.

So, lets say you want a girl baby – how do you know which day will be the best to conceive a girl? Well, you can either use the Conception Fertility Calendar which will mark off the days that are better for conceiving a girl, and mark off those days that are better for conceiving a boy, or you can do the calculation manually and mark it off on a calendar yourself. Let me demonstrate.

First, figure out when your ovulation is due to occur. This is generally 14 days from the end of your cycle, so measure your cycles to get an accurate number (not all woman have a 28 day cycle), add that to the start date of your period and then subtract 14 days from that.

For example, if your cycle length is 26 days, and your period starts on the 2nd of the month, then add 26 to the 2nd, and you get 28th, then subtract 14 days from that, and you get the 14th of the month.

Now that you know when your ovulation will occur, you need to figure out when the fertile period starts. The start of the fertile period is simply the day of ovulation minus the lifespan of the sperm cells. So, if we assume that sperm cells will last for 3 days, then the start of the fertile period is … “the 14th (the day of ovulation) minus 3 days (the lifespan of the sperm cells)”, which works out to the 11th of the month.

This means that if you made love on the 11th, with a sperm lifespan of 3 days, they’ll all be dead  at the end of the day on the 13th, there will be no more sperm cells left on the 14th when the ovum is viable, therefore we have to add one more day so that the start of the fertile period works out to be the 12th.

To determine which of the days are better for a girl (or a boy) is a little more complicated:

  • Do integer division on the fertile period by 2. In our case it is 4 (the total number of days you are fertile for) divided by 2, which is 2 with no remainder. Hence the first two days of the fertile period are better for a girl and the final two days are better for a boy.
  • The above won’t work if the fertile period is an odd number – for example if the fertile period is 5, the results of the integer division is 2 with a remainder of 0.5. In this case mark the first two days of your calendar as fertile for a girl, the day after those as fertile for both boy or girl and the final two days as fertile for a boy.
  • To determine the sperm lifespan, or to work out more accurately when ovulation will occur, I have some tips that you can follow.

Is all of that too much work to get a baby of the sex you want? I expect it is, but good news is here in the form of an Android application I wrote called (unsurprisingly) “The Conception Helper”.

For the price of a happy meal ($3.99) you can simply purchase an application for your cellphone that will do all this for you (and do it more accurately as well). I’ve written the Conception Helper for Android phones and tablets. Simply use it as directed and it will display a calendar for you each month with the relevant days indicated on it.

Further, even if you do not start it at all (after setting your start of period), when the relevant days come along,  it will warn you. No need to trust your memory to look at it at all. See the Conception Website  for more details.

And, there is also no need to take my word for it – there is a trial version that will work for 30 days – after 30 days you’ll have to pony up the cash to buy a copy, or simply redownload it to your phone again.

Download it, try it before you buy it, and if you are happy with it, then and only then spend your money on it. In the meantime, you can read the manual and see just how effective Conception can be.