Tuesday, June 16, 2009

Sailor waiter cedar whirled

I think the title says it all.

If you don't get it you might be mispronouncing cedar, it's see-dar.

I can't take the credit for this though, it was the first two lines in a crossword a few days ago (the one on the back page of the dom post).

Vegetarian Nachos

Well I cooked dinner tonight, and I made nachos, but vegetarian style (we had no mince). It turned out rather well so I thought I'd make a record of it if anyone else wants to try it out, and so I can make it again (and perhaps improve). I made this without consulting a recipe, and it wasn't really even based on any recipe I make, more just throwing stuff together.

Ingredients

1-ish tbsp olive oil
2 small onions (1 large onion would be similar)
3 cloves of garlic (they were pretty small)
1 tin of chopped tomatoes
1 tin of kidney beans
1 tin of baked beans (I typoed here and wrote ton first time)
3-ish tbsp flour
3-ish tsp paprika
1-ish tsp chilli powder
1-ish tsp salt
1-ish tsp pepper
1 capsicum

Method:

Dice the onions, garlic and capsicum. Obviously do the garlic much smaller than the other two. Fry onions and garlic in the oil in a large pan, until the onions go to the kinda see-through cooked-ish state. Add tomatoes, drain, then add kidney beans, then add baked beans. Stir to combine relatively evenly. Add flour to thicken a little, then paprika, chilli powder, salt and pepper. I just put as much of these in as I felt was about right, approximately the amount I wrote above. Be careful with the chilli powder if you don't like your food too hot. Stir to combine again. Add capsicum. Stir some more. Simmer, covered, for 10-15 minutes. Make sure to mix it and get it off the bottom every 3-5 minutes otherwise it will stick.

When I did it I only simmered for 10 minutes, and it could've done with a few more minutes, which is why I said 10-15.

Serve with nachos. Top with sour cream and grated cheese if you like.

Feeds 1+ depending on appetite (probably 4-6)

Shrinking rt.jar

I was reading somewhere that one of the reasons java applications are slow to load is that the large, 50 MB rt.jar file (94 MB extracted) must be read from disk. A jar file is basically a zip archive, so I wondered if I could make this smaller by recompressing it.

First I used advzip, from the AdvanceCOMP set of utilities that uses the 7zip compression algorithms. Copying rt.jar to my home directory, and recompressing it using -z4 I compressed it to quite a remarkable 24 MB, for a 52% size reduction. Surely this would take less time to load? Though I'm, not sure if it would take longer to decompress, and whether the bottleneck is reading from disk, or decompressing it. Though for a device with limited hard disk space, these 26 MB could make a difference.

For a second comparison, I extracted the jar file, and made a tar.lzma version, which came in at a lean 10 MB, though this did take about 2.6 s to decompress on my computer, so this is unlikely to be a viable option. The tar.gz version was still 17 MB (as was the tar.zip version), and only took 1 s to decompress.

For a third comparison, I remade the jar file using the command line zip utility, which itself produced a 25 MB file, so I'm starting to wonder why the version that comes with java is so big.

From what I understand of the zip format is that each individual file is compressed separately within the archive, which makes it good for this kind of thing in that only the classes that need to be decompressed have to, not the entire archive, which knocks out the tar.x files (and is also why they have better compression, the one file as a whole is compressed).

The thing I don't get though is why is this file so big? I tried replacing rt.jar in my java folder with the recompressed one, and everything seemed to work fine, but I did not get any noticeable performance improvement (probably in part due to the files being in the disk cache), but I didn't want to break anything so put the original ones back.

The last thing I'm wondering is that presumably these jar files are made by a java program, using the java libraries. Does that mean the java libraries are really bad in making jar (zip) files? And if so, surely the code can be replaced with some from say the 7-zip project, at least in OpenJDK, both being FOSS projects. Maybe it already has and it'll all be seen when java 7 comes out. Who knows?

Monday, June 15, 2009

Study goodness

I just had one of my most fruitful study sessions ever today, studying for quantum mechanics. Got some tough problems done, and understood some things a lot better than I had done previously. Now for anyone who's interested, and because I want to play around with LaTeX in this blog, I'm going to show how to formulate the time independent Schrödinger equation.

We'll start with the time dependant version:

i \hbar \frac{\partial \Psi}{\partial t} = - \frac{\hbar^2}{2m} \frac{\partial^2 \Psi}{\partial x^2} + V \Psi

Where \Psi = \Psi \left( x,t \right) i.e. a function of x and t, and likewise for V.

Now we shall assume \Psi \left( x,t \right) = \psi \left( x \right) \phi \left( t \right) i.e. it is separable.

Then the equation becomes:

i \hbar \psi \frac{\partial \phi}{\partial t} = - \frac{\hbar^2}{2m} \phi \frac{\partial^2 \psi}{\partial x^2} + V \psi \phi

and dividing through by \psi \phi gives:

i \hbar \frac{1}{\phi} \frac{\partial \phi}{\partial t} = - \frac{\hbar^2}{2m} \frac{1}{\psi} \frac{\partial^2 \psi}{\partial x^2} + V

If V is only a function of x, then the left hand side is dependant on t alone, and the right hand side is only dependant on x, therefore they must be equal to some constant. Lets call this E.

Now, it is easy to solve for \phi:

\begin{align*}
i \hbar \frac{1}{\phi} \frac{\partial \phi}{\partial t} &= E \\
\int \frac{1}{\phi} \frac{\partial \phi} dt &= \int \frac{E}{i \hbar} dt \\
\ln \left| \phi \right| &= - \frac{i E t}{\hbar} \\
\phi &= e^{- \frac{i E t}{\hbar}}
\end{align*}

Note that the left side is always positive, so the absolute value works out alright.

The other part of the earlier equation becomes the time independent Schrödinger equation:

- \frac{\hbar^2}{2m} \frac{\partial^2 \psi}{\partial x^2} + V \psi = E \psi

Which can only be solved if the potential, V, is defined.

Now I hope that is accurate, but is not unlikely that I made a mistake somewhere.

Sunday, June 14, 2009

Double contractions

I don't think these are technically correct, but I find them awesome, and oh so interesting. If I were one of the ones making the rules for English, I'd've included them. Ah well, they can still be introduced through incessant usage.

The one I find most interesting is it's'nt (it is not), as it can be expanded to have an ordinary contraction in two ways, it's not and it isn't. Has a strange, but nice sound, I reckon. (Learning Japanese causes me to append the verb on the end often, rather than using it at the beginning as is the more natural way in English - ah well)

There are lots of others, at times I even find myself using them unintentionally, like couple of hours ago, I used they'd've (they would have). So why not try and use a double contraction this week. Go on, I dare you.

But triple contractions, they're just ridiculous.

Laughter is good

And I just got a whole lot of it watching this video. Warning: It is 24 minutes and contains a whole lot of swearing. It's fully worth it though.

But as I was saying, laughter is good, it can make your day, and lack of it can break it. That is all.

I just wanted an excuse to post the above video, really.

Saturday, June 13, 2009

Wikimedia Pictures of the Year 2008

They're out. I discovered that wikimedia did this a while ago, and had been waiting for ages for this to become official, it's what, 5 months and a bit after the end of 2008 now, but I understand that these kind of things take time. This year is impressive as the previous two, though I can't say I'm all that big a fan of the picture who won, preferring 3, 4 and 18 (the 2nd 18) in particular.

I recommend checking this out, all the pictures are nice, some of the animated gifs are very impressive, like the cicada one, and who knows? You might find a new desktop wallpaper, I did.

Nice going Redmond

As some of you may know, Aaron Redmond hit a sizzling 63 off 30 balls in New Zealand's victory over Ireland in the 20-20 world cup. This is a tremendous score, especially for someone who was only playing due to injuries to other team members. At the time of writing this blog, it was the 8th equal highest score of the tournament so far, and there was only one score higher than his at a greater strike rate. It's also the highest score by a New Zealander (again at the time of writing).

This brings a bit of a problem on the NZ selectors, if Ryder (and possibly other injured players I'm overlooking) become fit and able to play again, do they drop the in form player? and if not, who do they drop? Though this is a better situation than they have faced recently, having to choose which out of form players to select.

The other thing that a little unusual about this success story is that the only games that Redmond had played for NZ prior to this match were tests, where he had been moderately successful. I only hope he can keep up this form, and keep demanding a place in the NZ side.

Thursday, June 11, 2009

Testing, testing, testing, testing,

When I released a new version of my game (shameless plug) a couple of days ago, I fell into the trap of insufficient testing. I had made some quite big changes and never tried actually playing one of the new levels. After I had uploaded it, and changed all the necessary pages with details of it - my entire release process, I tried playing it. Within 10 s of starting a new level, the game freezes. Shoddy testing.

It turned out that I was using way too much memory (to get good performance with that version you'd need to allocate the JVM something like half a gigabyte of RAM). This was due to some oversights in earlier code causing failures with the new maps (and caching way too many images). It took me a couple of days to fix - in which the game was effectively broken (though the older levels would still have worked fine). I just uploaded a newer version which I hope fixes the problem, and seems to, but I didn't test that release enough either.

I don't think I'll ever get to the point of thoroughly testing each release of this myself, as it's way too much effort, but this experience highlights the need to do at least some testing of how it would actually be used before releasing a new version.

An amusing site I found

While surfing the interwebs (I'm not very good so sometimes fall in), I found this site. I found it amusing so thought I'd share. It reminded of another site I came across not so long ago.

It also contains one of my pet peeves: a gif image. Nowadays, gif images should only be used when an animated image is required as png images will almost always give a smaller image, at no loss of quality. For instance, I downloaded the image, and ran it through optipng (to convert it to a png and do some png compression stuff) and achieved a 51.76% file size decrease. Then I managed to shrink it a further 6% using advpng -z4. A file less that half the original size of exactly the same quality is not to be sniffed at.

This page also contained an Easter Egg, which wasted around half an hour of my time (not finding it, that was trivial, but the page itself), though it to was amusing. There I found yet another amusing link of a similar variety.

Enjoy.