Sunday, December 28, 2008

women and maths and chess...

Two New Scientist articles caught my attention recently:

The first is a bit of mathematical obviousness which points out that: "There are few women at the top of science because there are so few women in science. It's simple statistics."
It uses the German chess federation's statistics to support the theory: there, men outnumber women by 16 to 1 (so if all other (significant) things are equal, there should only be a (1 - 15/16 ** 3 = roughly 18%) chance of a woman being in the top three, if I understand rightly).
Which begs the question, why are there so few women in chess/science/etc? Well, this is the subject of the second article...
Which is about a study where they split the (all female) subjects into two groups. One group was told that women perform poorly at maths due to genetics, and the other group was told that women perform poorly at maths due to social factors. Then they gave both groups the same maths tests and found that the 'genes make women bad at maths' group answered half as many questions correctly as did the 'society makes women bad at maths'.
This supports the idea that women being (statistically) worse at maths is probably wholly due to the negative, self-reinforcing erroneous stereotype that women are genetically predisposed to suck at it. Boo society!

I must admit to allowing myself to openly stereotype people more often than I'd like (i.e. than never), but seeing the power of negative stereotypes to destroy the performance of the maths test subjects it's time to at least keep such preconceptions to myself as much as possible.

Wednesday, December 24, 2008

mini cd/dvd -> Macbook -> oops!

As I inserted the mini CD for the Tevion "Potent Pad" (which I was sure only contained Windows drivers anyway), I thought "uh, how will a slot loading drive pick up a mini CD?". After a few seconds of silence once I had inserted the disc (and poked it in further with an envelope, to bollox things up further), it became apparent that I should have stopped and thought about it, rather than simply thought about it and carried on regardless...

A quick web search yielded predictable advice such as "power off the machine and use a paperclip to extract the disc" or "disassemble the machine and DVD drive to remove the disk". Since I wasn't keen on scratching the optical mechanism to ruin or dismantling the computer, I kept scrolling until I found the following blatantly obvious and blatantly sensible suggestion from 'ashleyman':
"Or just tip it so the drive faces the floor and give it a few taps!!"

This served me well and I safely removed the CD within 5-10 seconds of gently shaking and tapping the laptop with the slot facing down. Sometimes the solution is so obvious that you can completely pass it by!

Wednesday, December 03, 2008

OS X isn't all that great...

It seems like every week or so, OS X prompts me with some system updates that necessitate a reboot (usually Safari and iTunes - why the hell do I need to reboot my computer just because Safari was updated? This is the kind of behaviour people criticised Windows for in the past). I usually leave the dialogue box in the background for a couple of days until I'm ready to reboot, then go ahead.
Every once in a while (month), when I allow it to restart to "finish" updating, nothing happens. I start manually closing programs after getting warnings that each individual program failed to close (although manually closing them causes no problems at all). This time, the Software Updater seemed to hang as well, even though I had already told it to restart my Mac.

In the end, the machine seemed to shut down but the fan was still spinning. After hitting the power button a few times and waiting a minute or two, I held it to force a power-off and reboot. Then, instead of seeing the "Installing updates" dialogue you usually get when rebooting after installing updates, I just got my usual login screen, and sure enough, logging in as normal (after a ridiculous 4 minute delay before the Finder menu would respond to mouse clicks, WTF?) and opening the System Updater started the whole process from scratch.
LAME. Absolutely lame.

Sunday, November 16, 2008

Funny English expression of the day

"Rarer than rocking horse shite."

How to replace a bicycle tube/tyre ten times faster than I do

I hate dealing with punctures. I usually spend about 40 minutes dithering at the task, struggling to get the tube out of the wheel, locating the puncture, patching it carefully, leaving it for 5 minutes, coming back to find that I didn't apply it properly, cleaning it with sandpaper and then jamming the inner tube back in under the outer tyre.

So I was a bit embarrassed to see these videos of a guy removing and inserting the tube (and outer tyre in the process, which seems to just speed things up) in about 80 seconds. I'm still a bit skeptical about dealing with the outer tyre, which seems much tighter and stiffer on my hybrid wheel, but I'll have to try it next time!

Tube comes out

Tube goes in

These videos come from the very useful homepage of Jim Langley. (Note: Opera users such as myself may want to identify as Firefox or IE due to some outdated JS-crippling)

Thursday, November 13, 2008

Meteor MMS on the Palm Treo 680

Meteor uses a system which pushes the WAP/MMS/etc configuration to your mobile phone, but strangely don't provide the details online for anybody with an unsupported phone. In fact, when I phoned their customer service I had to push the agent to speak to his supervisor and get the settings, since he had no idea what I was talking about (indicated by his question "Did you say I.T. address or I.P. address?").

It's not possible to specify those settings completely in the Messaging program on the Treo 680; instead, you need to modify (or copy and use) the settings in (main) Prefs->Network. This configuration worked for us:
Service: Meteor MMS Copy
Connection: GPRS
User Name: my
Password: mms

Then in the Messaging program, go to the Preferences menu, select the Network tab, change "Network Configuration" to manual and enter the "Edit..." dialogue, where you can enter the following settings:
Message centre number: +353857000000
Email centre number: [blank]

Network Profile: Meteor MMS Copy

This works for downloading MMS messages.

Tuesday, November 11, 2008

the arithmetic calculator exercise in GFA Basic

For a couple of reasons, I tried that arithmetic calculator exercise in GFA Basic (v3.6 for the Atari ST; why not?), and although I selected a somewhat different approach, I think it's really like a non-recursive version of the recursive Lisp version I posted before; with state in variables which persist for the whole loop. This is where side-effects can get mysterious, compared to the neater encapsulation of state in each recursive call's parameters.

randomly entertaining Chinese sentence

I check pretty much every new word I come across in my study materials on, which also lists example sentences containing the term.

Here's a nice one I found when looking up the character 肥 (fei2), which according to my book means "(of clothes, shoes) loose*, (of animals) fat":
I was so tightly wedged between two fat women that it was difficult for me to get up and leave the bus.

:D :D

* although I couldn't substantiate the first meaning from the online dictionary..?

Saturday, November 08, 2008

Common Lisp: arithmetic calculator exercise

Following a post on the Atari ST forum I tried a little exercise to write an arithmetic expression parser for expressions like "24 - 3*9 + 9/3". I was surprised to find it a little difficult, taking about an hour even with the concessions I made (accepting input as a list rather than a string, and not checking for well-formedness of expressions). My code is on and I'd love to see any improvements or tips. Embarrassingly, I took two semesters of the final year compiler construction course in DCU and did quite well at it; parsing of programs was a central topic on the course! I guess it's easy to take for granted your skills at 'abstract' coding and notice they need a bit of exercising.

Saturday, October 25, 2008

ntl's expanded internet pipe

Soon after moving here last year, we decided to get our TV, broadband and phone service through ntl rather than get TV from them and broadband/phone through Eircom or some reseller, since Ireland has apparently the most expensive line rental in the world (?? thanks, Tony O'Reilly for exploiting the competition-free market and Comreg/competition authority for allowing it).

They recently retooled their broadband packages, so that the old 6mbit price now gets you 10mbit and for €10 more per month you can get 20mbit (I wouldn't bother with that unless I was sharing with a few people, though).
I had to call up to get it though, since they weren't nice enough to automatically shift me over to the new package - this is really something ISPs should do when they improve their packages.

It's working pretty good too - close to the quoted 10mb:

Thursday, October 23, 2008

Lexmark X4550 wireless woes with OS X

I picked up a fairly cheap Lexmark X4550 wireless printer/scanner/copier about 6 months ago and soon noticed that it stopped working every time I restarted the router.
After a long conversation with a fairly patient technical support guy at Lexmark proved mostly fruitless, I dug a little further and ran a packet sniffer (Wireshark) over an attempted print job.

This prompted me to double-check the printer settings, which showed a device URI of lexnet3:// Which is certainly wrong, as the printer is at I'm not sure why it doesn't just use DNS properly, but anyway.

Trying to correct this, I stumbled across this post explaining how to modify the device URI via the CUPS web interface available on OS X. And it works! Good old Unix!

article: "Early Childhood Education: The Key to Success in Life"

Anyone who has or expects to have children should read this article about preschool learning as soon as possible.

After emphasising some of the importance and benefits of preschool education, it lists some basic and simple ways in which you can help educate your bairns. As usual with such material, there are 'obvious' things that never occurred to me - like placing a young baby face-down from even one month of age, because he will naturally want to raise his head which will help build up his back muscles which will improve general strength and co-ordination. The paper-crumpling trick is clever too.

Well worth a read!

Friday, October 10, 2008

classy typing tutor

This is the funniest-looking educational game I've ever seen. Check out the screenshot :D The description for the game calls it "an educational children’s casual game". It certainly would have appealed to my childhood self.

. o O ( "Cop smearer"?? )

Sunday, August 24, 2008

Ireland's gradual transformation to a police state

Well, here we are. The Department of Justice, Equality and Law Reform have made it so that all migrants to Ireland from outside the EU must be fingerprinted (and their details shared with who knows how many foreign agencies). And of course, the costs for this are passed on to the migrants themselves - they will pay another €50 on top of the old €100 "registration" fee to lose their privacy. I have to wonder what practical use there will really be for the fingerprinting.

The "Land of the 100000 welcomes" is long dead and buried by this point. What disturbs me is all the people who feel that all foreigners should be fingerprinted and they're lucky they're not just sent home immediately anyway. What if all Irish citizens had to be fingerprinted? Would that be okay? No? So why the double-standard, and where does it stop?

Saturday, August 23, 2008

Refactoring threats

Entertaining quote of the week (a comment on an article about a newbie employee running a "NEVER RUN THIS" database recreation script after being told not to) from a user on
Re: Do not run this script, ever!
2008-01-25 15:45 • by morry (unregistered) 173406

I've always thought it's better to put these things into the positive, i.e. don't use "don't". For example:






Thursday, August 14, 2008

Stupid thing of the day

Eclipse (the popular Java IDE) has an update manager which allows it to automatically fetch and install or upgrade new versions of various components and plugins.
However, it can't upgrade itself from version 3.3.2 to 3.3.4.


Wednesday, July 30, 2008

"Who gives a shit?" attitude -> better mental performance

This article was a big surprise to me. The gist is that using the executive function of your brain (switching from deliberation to implementation - making and acting on decisions) has a strong negative impact on all sorts of mental activities.
For example, deciding whether to have cake or cornflakes for breakfast could be enough to make you perform poorly at an interview later on.

A further implication of this (to me) is that people who coast through much of the day like zombies (especially in the morning), not making many decisions, are much better able to perform when they need to, because they haven't depleted those resources yet.

The moral of the story: if you want to improve your overall mental performance, get into the habit of saying "who gives a shit?" about irrelevant decisions like where to put the furniture or whether the curtains need to be washed again this week. Don't deliberate over mundane issues. Don't waste your energy. Just pick the first reasonable option. I'd like to know if strategies like this can minimise this effect, or if we really have to go around like cattle - I know I do, most of the time... Is that what girlfriends are for? To decide where the couch and TV should be and what washing powder to use, so that I can reserve my brain power selfishly for 'clever' use later (which rarely happens)? Seems a little unfair, really...

I have more questions. How do we recover from the effects? How long does it take? Can we speed it up? What about meditation, or induced alpha/theta/delta brainwaves (i.e. by listening to binaural beats, say)? Why does it happen?

Enough rambling (I guess...), I'm off to dodge some decisions! Probably.

Wednesday, July 23, 2008

(Auto-)Growing Panes

In another Swing-related weirdness note, it seems that a certain combination of apparently logical options regarding GridBagConstraints and a JTextArea will cause the JTextArea and enclosing JPanel to expand horizontally by gridBagContraints.ipadx pixels per step, forever.

After scratching my chin in confusion, I whittled out the following minimalish example that demonstrates the result:

import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
import javax.swing.border.LineBorder;

public class TextAreaExample {
public JPanel createContentPane() {

JPanel contentPane = new JPanel();

JPanel mainPanel = new JPanel(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
// ipadx > 0 causes textarea panel to grow horizontally forever if linewrap is set!
c.ipadx = 1;

JPanel leftPanel = new JPanel();
leftPanel.add(new JLabel("Left"));
mainPanel.add(leftPanel, c);

JPanel logPanel = new JPanel();
logPanel.setLayout(new BoxLayout(logPanel, BoxLayout.PAGE_AXIS));

JLabel label = new JLabel("Hello");

// create misbehaving textarea
JTextArea log = new JTextArea(10, 40);
log.setBorder(new LineBorder(Color.BLUE));

mainPanel.add(logPanel, c);

JPanel rightPanel = new JPanel();
rightPanel.add(new JLabel("Right"));
mainPanel.add(rightPanel, c);

return contentPane;

private static void createAndShowGUI() {
JFrame frame = new JFrame("JTextArea growth test");

TextAreaExample demo = new TextAreaExample();


public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {

I can get around it by setting a preferred size on the JTextArea (a size of 0,0 seems to do the trick without changing the initial layout), but what the hell?

Monday, July 21, 2008

Swing and a miss

Does this method Javadoc from the Swing API confuse you? It confuses me:
* Sets the the vertical alignment.
* @param alignmentX the new vertical alignment
* @see #getAlignmentX
* @beaninfo
* description: The preferred horizontal alignment of the component.
public void setAlignmentX(float alignmentX) {

As you can see, the method description and param seem to conflict directly with the beaninfo description. I was sure the first two are a typo, copied from the alignmentY equivalent, but let's have a look at setAlignmentY:
* Sets the the horizontal alignment.
* @param alignmentY the new horizontal alignment
* @see #getAlignmentY
* @beaninfo
* description: The preferred vertical alignment of the component.
public void setAlignmentY(float alignmentY) {


Also, using it is confusing and the docs don't seem very helpful. I created a JPanel using a vertical BoxLayout, so that as you .add(component)s they stack up beneath each other.
To the empty box panel I added a JLabel with the text "Log" and beneath that, a JTextArea which would hold the log output.

However, I noticed on running the program that the label was not left-aligned - instead, it was indented by about 40 pixels beyond the log textarea beneath. Worse still, when text appeared inside the JTextArea, the label above would jump horizontally right, bizarrely. So the most logical thing to do seemed to be to call label.setAlignmentX(Component.LEFT_ALIGNMENT) to keep the label aligned to the left side of its containing box.
Seemed to be the logical thing to do. But no, this caused no obvious change. Various combinations of this did nothing, until I made the same call on the textarea underneath.

So if you have a vertical box containing a label with a textarea underneath it and you want the LABEL to be left-aligned, you have to tell the TEXTAREA to left-align itself.


Wednesday, July 09, 2008

The great antivirus scandal of 2008

This report is pretty scary. It's understandable that everybody overlooks the fact that virus scanners can be vulnerable, especially when they're built with lots of 3rd-party plugins (e.g. upx/zip/arj/rar/etc unpackers).

But the fact is, you can become automatically infected by a virus without running the infected program/trojan yourself; the virus scanner scans it automatically, but the file is designed to exploit a vulnerability in your virus scanner and you become infected.
That's a lot more dangerous than having no AV software and just being careful which programs you run...

Symantec is among the worst here, with about 32 vulnerabilities listed compared to 6 or 7 in FProt, AVG and BitDefender.
Personally, I think it serves AV vendors right for coding their products in languages as dangerous as C and C++, which are so vulnerable to buffer overflow mistakes. And nobody can code without mistakes. And the frequency of mistakes increases with code size, of course. They should have written their scanners/plugins in a better programming language (e.g. Lisp).

Tuesday, July 01, 2008

Update on Gambit-C Scheme benchmarks

Thanks to some helpful comments from a few people on my previous post about Gambit-C Scheme, I rebuilt and ran (with a larger minimum heap size specified) those few benchmarks I was bothered pulling off their site and the shootout site for SBCL (which is a very fast Common Lisp implementation I'm interested in using as a kind of reference).

The results in general are much better:

time ./fannkuch -:m20000 11 > output_fannkuch

real 0m9.931s
user 0m9.465s
sys 0m0.172s

time ./fasta -:m20000 25000000 > output_fasta

real 0m29.843s
user 0m25.220s
sys 0m2.700s

time ./binary-trees -:m20000 16 > output-binary-trees

real 0m2.770s
user 0m2.581s
sys 0m0.089s

time ./pidigits -:m20000 2500 > output
real 0m3.322s
user 0m3.093s
sys 0m0.110s

A range of improvement is apparent, with binary-trees benefitting a lot and pidigits not really getting much better.
I picked a 20 meg heap because a) it seems wasteful for individual programs to reserve (and probably waste) huge chunks of memory, if you're running a lot of programs b) when I tried higher values up to 50 megs on the fasta benchmark, it was faster, but only by another .2 seconds or so; about 1-2%... and c) Most other languages, and in this case SBCL, don't seem to request more than about 20 megs for their initial heap size either.

Of note is the fact that the prebuilt version produced slightly faster code than the version I compiled myself, specifying the optimisations mentioned in the INSTALL.txt document. Not sure why... These numbers are for the Gambit I compiled myself, and I didn't feel like dumping it and re-installing the prebuilt version just yet.

Anyway, these are nice results!

Sunday, June 29, 2008

How fast is Scheme? Well....

Thinking that it'd be a good idea to become familiar with Scheme as well as Common Lisp (but, er... probably after I've read Practical Common Lisp and amn't mentally overloaded, what with me being mental so busy and needing to focus my efforts in a more single-threaded manner), I checked out Gambit Scheme in the hopes that it'd produce faster code than the other free Scheme implementations.
I don't know much about Scheme (or Lisp at all really; I've only become interested in it during the last month or so) but it seems that the Scheme compilers produce quite sluggish code, at least looking through the grainy, distorted lens that is the Computer Language Benchmarks Game.

From some of the microbenchmarks published by the Gambit guy(s) on their homepage, it looks as if it fares really well against the Chicken and Mzscheme compilers, but I wanted to examine its performance on problems relative to SBCL, which is the Common Lisp compiler I've arbitrarily chosen.
Since it's not featured on the language shootout, I pulled the SBCL code for a few tests there as well as the Gambit code which was already prepared on their site (why hasn't Gambit appeared on the shootout site for the nosy hackers who want to find out if less mainstream (man I hate that word) languages are ridiculously slow? Many of them aren't! And they're more expressive and comfortable than C++/Java, use them!) and ran a few comparisons.
SBCL comes out very much on top; in general the Gambit programs take two or three times as long to do their job (although I haven't looked at memory usage). But as far as Scheme compilers go, Gambit seems to be improving things.

(Really dodgy) timings on my Macbook (input values = whatever's on the shootout site):

real 0m3.611s
user 0m3.508s
sys 0m0.066s

real 0m7.519s
user 0m7.309s
sys 0m0.130s

real 0m12.571s
user 0m12.089s
sys 0m0.205s

real 0m46.334s
user 0m42.284s
sys 0m2.668s

Lisp SBCL:
real 0m2.422s
user 0m2.018s
sys 0m0.308s

real 0m1.899s
user 0m1.723s
sys 0m0.127s

real 0m6.221s
user 0m5.982s
sys 0m0.098s

real 0m20.730s
user 0m15.267s
sys 0m4.375s

(ratio-pidigits: 1.5
ratio-binary-trees: 3.959
ratio-fannkuch: 2.021
ratio-fasta: 2.235)

One thing I've noticed from these coarse measurements is the "sys" component of the execution time is mostly higher for SBCL; maybe this means a lot of allocation and de-allocation of stuff is going on ...Or something.

Extra legs on a dog

This hi-larious entry on the wikiwikiweb offers a series of biological analogies for the origins of some popular/not-so-popular programming languages, on the premise "how other languages became ObjectOriented octopi".

I particularly like:

  • ..made by taking an 8-legged dog, housebreaking it, and tearing out its skeleton. Then giving it a machine shop.

    • a boneless 8-legged dog manages to be less useful than either an octopus or a dog - but it comes with a machine shop, so that's good.

That said, this is exactly the kind of thing that I would chuckle ceaselessly at, for which even fellow coders would shun me for being lame and non computer scientists would simply presume me to be insane. Fair play, really.

Tuesday, June 24, 2008

Lisp problem 10: RLE of a list

This one worked out much easier, but again, I went at it non-recursively. Bitching about my struggles with the previous problems made me realise that I had solved most of the previous problems recursively but non-tail-recursively.
I guess there's a danger there of writing really poorly-performing functions on the assumption that the compiler will optimise them. Actually, I don't even know if SBCL does tail-call optimisation... It somehow seems easier to express tail-recursive solutions in Haskell, so far anyway - as a complete newbie to both languages.

;; P10: Run-length encoding of a list.
(defun encode (list)
(let ((chunked (pack list)) result)
(dolist (chunk chunked)
(setf result (append result
(list (list (length chunk) (car chunk))))))

Oh yeah, how do you get around doing that ugly (append result (list (list x y))) stuff? I assume that's super slow, unless Lisp lists have a pointer to the last element for quick access since (you'd think?) appending is common. But then, some of the stuff I read in Practical Common Lisp suggests a push/reverse pattern, which to me seems a bit awkward.

99 lisp problems. Some are hard!

This much publicised set of 99 Lisp problems (taken from an original set of Prolog problems) seems like a nice step for me to take in learning Lisp as a novice to the language.

I figured the first few would be really easy with a smooth learning curve as the questions get more difficult. Certainly, I didn't expect to spend at least two hours screwing up question 9; an ostensibly straightforward problem requiring you to convert a sequence into a list of sublists, grouped by consecutively equal elements (i.e. (1 4 4 8 1 9 1 1 1 2 2 3) -> ((1) (4 4) (8) (1) (9) (1 1 1) (2 2) (3))).

After trying to solve this one a few different ways, I rejected a recursive approach and simply looped through all the elements, doing dirty stuff:
(defun pack (list)
(let (a main-list)
(dolist (x list)
(if (and (not (null a)) (eq x (car (last a))))
(setf a (append a (list x)))
(if (null a)
(setf a (list x))
(progn (setf main-list (append main-list (list a)))
(setf a (list x))))))
(setf main-list (append main-list (list a)))

I had a quick peek at the solution provided on the site and didn't bother going through it except to note that it was indeed recursive (and not tail-recursive). Partly because some of the identifier names are in Portuguese and partly because it looks similar to the mess I had when I tried to do it recursively; I'm just not comfortable with how lists work yet - I was getting stuff like ((1 (1 (2 3)))) and ((1 (1 (2))) . 3) and all sorts of other crap.
I'm sure I could have done this quicker (and much longer and uglier) in Java, but not figuring it out properly in Lisp is making me feel a bit stupid. Wah.

Friday, May 23, 2008

From I Ran to Eye Rack

In a thread on codeproject, someone humorously commented that "pedophile" must mean somebody with a foot-fetish: American pronunciation has even changed it from "peed-o-file" to "peddo-file", which is almost equivalent to "encyclo-peddy-ah" (since American spelling similarly converts that 'ae' glyph to an 'e').

Another funny dodgy American pronunciation is the popular "eye-raq / eye-ran" thing. It was entertaining to hear that our ex-Taoiseach Bertie Ahern was introduced as "Bertie Ay-hern" by Nanci Pelosi on a recent trip to the US.
As culturally-prevalent-and-nobody-corrects-themselves pronunciation errors go, it seems as bad as the Japanese 'l'->'r' transliteration (take the eravator to the rower reveru, prease), since at least Japanese have the excuse that the 'l' sound doesn't appear in their language and they thus have trouble pronouncing it.

Tuesday, May 06, 2008

gymnastic bounces, late

Received 3/5/2008 (happy birthday):

Your membership in the mailing list Announce-gymnast has been disabled due to excessive bounces The last bounce received from you was dated 29-Dec-2003. You will not get any more messages from this list until you re-enable your membership. You will receive 2 more reminders like this before your membership in the list is deleted.

Excessive bounces, but the last one my account apparently sent was four and a half years ago? I don't think I even subscribed myself to that list, though I was in the gymnastics club in first year of college. Weird.

Friday, April 11, 2008

Java's arithmetic operators

Here's a weird little one that confused me at first:

public void testWeirdArithmeticOperators() {
double a = 1.0 / + + + 2.0;
assertTrue(0.5 == a);
String s = + + + + 0 + "abc" + "def";
assertEquals("0abcdef", s);

After playing about for a bit, switching some +es to -es and vice versa, I realised that the effect is that each + or - symbol could be rewritten as follows:
+ -> (+1)*
- -> (-1)*

So that the expression "+ + + 2.0" becomes "(+1) * (+1) * (+1) * 2.0" = 2.0, and the expression "- + + 2.0" becomes "-1 * +1 * +1 * 2.0" = -2.0. Thus, the sign of the result is negative for an odd number of - symbols and positive for an even number.

Seems a little pointless, but I suppose the logical way to see it is:
- + - x = - (+ - x) = - (+ (-x)). It makes sense then that the parser would accept it, but in it that form it looks wrong to (my) human eye.

Also, in writing this post I noticed that JUnit's assertEquals doesn't really like doubles:
assertEquals(0.5, 0) passes, as does assertEquals(Double.valueOf(0.5), Double.valueOf(0.0)) and other combinations. That's why I needed to use assertTrue(...) and == above. Huh.

Tuesday, April 01, 2008

the poor man's breakpoint

Since Eclipse is kind of very ridiculously slow betimes, I tend to avoid making it do too much work, for fear of it getting stuck in a rut and slowing down. Partly because my work machine is pretty much a doorstop, for the purposes of working with Eclipse (512mb RAM just doesn't cut it, if you want a browser and other apps open at the same time - I had to stop using the latest Opera snapshots while coding, as they use too much RAM at the moment, compared to Firefox 3.0b4).

So instead of running tests/etc in the debug perspective and adding breakpoints where I want to stop (if that block of code is executed), I've taken to doing things like this instead:
throw new RuntimeException("FUCK");
This means I get a stack trace showing how we got to the current state, which is often enough to realise what the problem is (at least, it was just now; I saw that a method I didn't expect to be called was being called by a parser for poorly-formed XML messages. Until that point, I didn't realise the messages were now poorly-formed as they weren't before I swapped XMLSerializer for LSSerializer earlier today).
Also, it's easy to search and remove your debugging throws afterward, since they contain the reasonably memorable, short string "FUCK". Of course, you wouldn't want to forget about it and leave one in a currently unused (as far as you know) method, lest an end-user find that their application is throwing an exception because FUCK. :)

Perhaps a more subtle keyword could be selected (how about "Fire in the hole" or "Get to the choppa!")...

Friday, March 28, 2008

how... odd

Here's a funny random thing. Residents in some countries can apply for an Irish visa online.

They're even nice enough to provide translations of the "Information on completing Online Application" into other languages, including Chinese. However, in their list of countries for which they allow online visa applications, China is not present.

So why the hell did they bother translating the "how to use the online application system" PDF into Chinese...?

Welcome to the Irish government. Home of weird bureaucracy and silly contradictions.

Also, the actual web application tells Opera users to upgrade their browser because of some buggy cookie test. As usual, an Irish government site/webapp ends up poorly designed and coded, and probably cost at least €10M. Saps.

Monday, March 24, 2008

Freeze! squad

Here's one of the things I really like about Mandarin Chinese - its simple straightforwardness; a lack of needless obfuscation. The Chinese phrase "别动!" (bie2 dong4) usually means "Don't move!". The character "队" (dui4) means a squad or team.

Combined, the resulting term "别动队" means "special ops team". Literally, "don't move squad".


Thursday, March 20, 2008

When is a clone not a clone? When it's half a clone!

After finding that the clone of a two-dimensional array in Java seems to not be a clone, I searched the web, already strongly suspecting the outcome.

Behold (from one of Sun's references):
A clone of a multidimensional array is shallow, which is to say that it creates only a single new array. Subarrays are shared.
Then that's hardly a clone now is it? Damn you AvatarJava. Daaammmnnnnn youuuu!

Wednesday, March 19, 2008


I ordered a Wacom Bamboo One graphics tablet from about two weeks ago, and am pretty impressed by it (once I installed the updated drivers for my Macbook, since it was sucking with multiple users/sleep/USB disconnect+reconnects). It's nice for scribbling and drawing, even if it just makes me realise what a poor graphic artist I am. The main reason I bought it was for studying Chinese - up to now, I'd been using a scheduled revision program (first Pauker, then Mnemosyne, then when it wouldn't build on OS X Leopard due to one of its Python dependencies being a bit outdated, Anki) to learn Chinese characters and sentences, and writing the characters vertically on paper as I revised them. However, to avoid spoiling the recall process, I was having to draw gridlines and cover up already-drawn characters so I wouldn't see them when presented with flashcards for review. There two problems there; one was that lots of paper was being used up needlessly, and two was that it was fiddly and a hassle, so I stopped doing it due to my self-discipline not overcoming the coefficient of resistance (my laziness is a rough cloth).

Since the graphics tablet arrived, I started using it to sketch the characters in Seashore, a simple bitmap drawing program.

Then I check if I was correct (if not, I draw each character four times or so), clear the canvas (by hitting backspace) and grade myself in Anki, moving onto the next item. It's faster and easier, two reasons which have helped me keep doing it. Along with some truly inspiring ideas (the "how many things will I definitely do tomorrow" game and the "I'll just get the file out" trick) I read on Mark Forster's site, which you should incidentally go and read now, by the way, since it might just help you change your life for the better.

Tuesday, March 11, 2008

Newsflash: Eclipse is bloody slow

It's probably not news to anyone who has ever used Eclipse, and I've been aware of the fact since I started working with Eclipse as my IDE in 2006. However, right now, on this admittedly rubbish machine (PIII 1ghz, half a gig RAM, running Opera as well with a million tabs open which takes up 80-100 megs), it took about 90 seconds to get from clicking the "Find and install..." menu option in "Help->Software updates" to displaying the "Install/Update" dialogue box. It doesn't seem necessary to do a lot of work to get there, since that dialogue simply contains a radio button choice between updating currently installed features and looking for new ones.
What's going on here? I know Java can be slow and Eclipse uses a fair bit of memory so I'm probably swapping to disk like a king, but it still seems excessive.

Friday, March 07, 2008

more on profiling

Well, after being forced to go down the manual speed profiling route, I'm pretty happy about the results. Manually inserting timing code around loops of single (if possible) calls is nice because you can focus your search in a reasonably directed, intelligent way. Since giving up on Eclipse's TPTP profiler yesterday evening, I was able to optimise various parts of the code so that the main client/server conversation executes five or six times faster than previously. Most of the optimisations were of the "cache objects instead of constantly recreating them locally" variety, which can introduce errors (which is always a risk when adding more state to your code, but hey, welcome to one of the downsides of OO) but can also improve performance drastically.

I'm hoping I can find more higher-level optimisations over the next while, but I've gotta draw a line now and get back to adding functionality, or I'll look like quite the sap when I have to demo the current stuff to my pals.

Thursday, March 06, 2008

Eclipse, TPTP and accursed JVMTI

I had Eclipse's update manager automatically "upgrade" some of the component versions, including the TTPT tools I was using to try to profile some VERY SLOW code I'm working on, and since then (and following multiple restarts of Eclipse and a reboot), I cannot profile any Java code.
Hitting the "Test availability" button for the post-1.5 JRE data collectors freezes Eclipse for about 10 seconds before popping up an alert box which states "The JVMTI agent org.eclipse.tptp.jvmti is not available", with a "Show details" button which expands the dialogue to display a completely blank textbox. This is clearly bollox. Searching the web leads to forum posts advising to meddle with the "Agent Controller" and RAServer programs, but I can't find them and never needed to before.

What Eclipse needs is a lightweight, simple profiler which doesn't run into stupid problems like this. For fuck's sake, I've spent over an hour getting nowhere with this stuff. Of course this would happen now, when I'm expected to give a demo of the code (running faster than what it replaces) on Monday morning.

Results of "Test Availability":

Trying to run the profiler:

An automatic update should not break Eclipse's profiler completely. Now I've gotta go with the good old "manually insert time measurement code all over the shop" technique, which fairly sucks.

Thursday, February 28, 2008

Functional Programming in Java? No, not Scala...

Having more experience in Java than most of the other languages I've coded in, I was interested to read this article from 2004 on using some functional programming concepts in vanilla Java.
The notion is attractive, but then I saw some example code:
public int calcPriceInternalIterator(List items)
Iterator i = items.iterator();
UnaryFunction getItemPrice =
new UnaryFunction()
public Object evaluate (Object obj)
return new Double(((SETLItem)obj).getPrice());
Constant usd100 = new Constant(new Double(100));
BinaryPredicateUnaryPredicate moreThanUSD100 = new BinaryPredicateUnaryPredicate
(new UnaryCompositeBinaryPredicate(new IsGreaterThanOrEqual(), getItemPrice, usd100));
FilteredIterator fi = new FilteredIterator(i, moreThanUSD100);
Summer addPrice = new Summer();
Algorithms.foreach(fi, addPrice);
return addPrice.getSum();

And then in the concluding spiel:
In this article, I've introduced two functional programming techniques that can be easily integrated into your Java development practices.

... Now come on. I have no idea what that code does, because it's an ugly, bloated mess of syntax and verbose names (not to mention simply having far too many identifiers and tokens in the first place).

Java is a round hole. Functional programming is a square peg. Without modifying the syntax of the language, trying to fit the square peg in the hole may be possible, but far, far too complicated and impractical. No sane coder would want to work with that.

Tuesday, February 26, 2008

week of doom

Cycling back from snooker on Tuesday, I stopped in a Chinese takeaway in Beaumont, about 3km from home. Laden with chow mein and... whatever I got for my girlfriend, I decided to cycle on the path to the petrol station just around the bend (where I could buy a 2L bottle of something to drink, since coke cans are €1 a pop in the takeaway), rather than bother to cross back onto the road, cycle for 20 seconds and cross again to get to the petrol station.

I slightly underestimated the distance to the petrol station, so when I got my bottle of Club Orange and stuffed it into my backpack beside the Chinese food, I sat on my bike and noticed the front tyre was completely flat. Bollox, said I.
Anyway, I didn't want to faff about trying to fix it there because that takes me an hour and I had hot food in my bag. So after a longer-than-usual uncomfortable cycle home on a flat tyre, I pulled the takeaway out to find that it had leaked all the sauce from my chow mein into my backpack, all over my rain trousers and whatnot. And bollox again, I swore.

Next morning, we spent an hour fixing the puncture (I hate the damn things. Hate.) and I headed off to DCU. Some hours later, when I returned to my bike I noticed it was flat again. No problem, probably a slow puncture elsewhere, or a semi-sticky patch.. I'll just pump it up again and ride home. However, when I took the pump to college in my bag, I neglected to take the small attachment tube which connects it to the tyre's air valve. For the third time, bollox was uttered with some frustration.

Another trip home on a flat tyre, listening to the rim grind against tarmac through the outer tyre, and I left the bike 'til morning before swapping out the cursed inner tube with another I'd pulled out months ago with only one prior patch and which seemed to need only one more. This successfully carried me to college and back, but two days later it was flat again.
I put it out of my mind and on Sunday night, watched Lost at 9pm and prepared to do some catchup piano practice at 10 and a little more on Monday morning... when at about 3 minutes to ten, the power failed... apparently only on my road, or my half of the road even. So that lasted until about 3pm the next day, which caused some trouble since the piano is an electric keyboard.

When life gives you lemons, make cake! Unless you have a poxy electric cooker and the power is out.

...On the plus side, when I opened up my Macbook which had died in its sleep during the power outage (I put it to sleep with about 20 minutes left on the battery monitor, soon after the cut), I expected it to go through a normal bootup. Instead, I saw a funny progress bar whizz for a while, before it brought up the usual unlock dialogue which appears when you're logged on and wake the machine up. So there's a point where it wakes the machine from S3 (suspend-to-RAM) sleep and puts it straight into S4 (suspend-to-disk), then powers off, on the basis that the battery is about to run out which will destroy your S3 image and you'd have to boot again. Nice.

Sunday, February 17, 2008

The joys of Sozobon C

Having been slowly inching towards doing a little coding on the Atari ST, I decided to set some (very) small, straightforward goals to actually get started doing something useful. This seems to be a pretty important tactic for me, as otherwise, I can start to get lost in the haze of all my different interests and never really get anywhere.

I started laying these out in a simple todo list following the extreme programming task card style we used at Cellusys, like so:

 In progress:


* ST: Display a sprite! (IH: 2)


* ST: Switch to low res and back to original. (IH: 0.5 / AH: 0.5)
* ST: Print the current colour palette. (IH: 10m / AH: 20m)
* ST: Change the background colour to green. (IH: 2 (??) / AH: 10m)

Printing the palette took a bit longer since I decided to write a number->binary (string representation) conversion function, and realised I'd forgotten some pretty basic things about C. But that's part of the fun! Note my fairly pessimistic estimate of 2 hours to display a simple sprite. It's probably a good idea to err on the side of underestimating yourself when planning stuff that is somewhat beyond your ken, even if you used to do it ten years ago. To be honest though, I'm not really sure what to try after that. A little animation I suppose? Then eventually some screen flipping and fiddling with the palette and an XBIOS sound routine. Sounds like a plan...

Wednesday, February 06, 2008

The 1 percent rule

From a Wired article on geekiness in Futurama:

Cohen refers to a One Percent Rule that guided the writing on Futurama. When they were scripting the episode "Kif Gets Knocked Up a Notch," a character claims that he painstakingly programmed a holographic simulation using "4 million lines of BASIC." One writer pointed out that 99 percent of the audience wouldn't get the reference to an old programming language. Producer-writer Eric Kaplan responded, "Fuck them!"


Friday, January 25, 2008

Lambda the Ultimate! Mayest thou wrap with great haste.

While reading this interesting thread about "concept [representation?] programming", I immediately became frustrated at the massively long lines which forced me to scroll left to right and back constantly.

I started to search the web for a fix, tried using Google Translate (Chinese to English) to see if it would somehow fix the problem and when this failed, took a quick look in Opera's "view" menu. There I saw the obvious solution, "Fit to width". I kind of expected this to zoom the whole page out so small that I wouldn't be able to read anything, but nope; it just forces the page layout to conform to your browser window's width, effectively forcing word-wrapping. I love Opera.

Saturday, January 12, 2008

Dude, where's my fonts?

After a bad crash on my MacBook, I rebooted via the power button and logged in again to find my fonts banjaxed (i.e. most of them missing, notably Chinese character fonts). A cursory investigation led me to check the Font Book application, which should contain two libraries called User and Computer, which contain the default set of fonts.
In my case, only the All Fonts and Gaeilge libraries were left, both empty. Trying to add more fonts had no effect, until I eventually realised I had to create a new library as a workaround and add fonts to that.
This worked, although due to the aforementioned .CFUserTextEncoding problem I had to open Font Book every login before applications that used interesting fonts, or they wouldn't find any.

Just for the sake of it, I opened up a bug report with Apple, not really expecting to hear anything back. A few weeks later though, I did hear back from them, with a solution that worked:

"Look for a directory called: inside of /var/folders

Once you find it, copy this directory to another location and then remove it."

Doing this and rebooting the MacBook, I logged in again and started Font Book to find, lo and behold (drumroll and angel choir) that the User and Computer font libraries were automatically added again and all the fonts loaded back into them. BRILLIANT, thanks Apple, I totally didn't expect that. Thumbs up from me!

Friday, January 11, 2008

The middle finger of .CFUserTextEncoding

Recently, I had a bad crash on my MacBook while it was downloading some torrents. When I came back, I had to use the power button to restart the machine, and after the reboot, some things were broken. First, Font Book contained no fonts. Second, LyX didn't run. Third, Atlantis (a MUD client) didn't run either.

The LyX error looked like this:
LyX: Creating directory
Same as entered returned
Failed to create directory. Exiting.

And Atlantis didn't give me any error message. So, after a long time fiddling around with directory permissions, changing my group from admin to user and chowning a bit, I noticed from a dtruss log of failed and successful (by simply running as another user with sudo) runs of the affected programs that the file ~/.CFUserTextEncoding was being accessed at some point.
So I had a quick look at this file in the failure (first) and success (...second) cases:
Macintosh:~ oisin$ more .CFUserTextEncoding
Macintosh:~ oisin$ more ../yunqing/.CFUserTextEncoding
../yunqing/.CFUserTextEncoding: Permission denied
Macintosh:~ oisin$ sudo more ../yunqing/.CFUserTextEncoding

Replacing mine with 0:0 and su'ing to myself to get a new shell, I was able to run LyX and Atlantis with no problems. So, I'm not sure what this means - maybe the crash wiped out an encoding method or wrote the wrong data to that file, and when applications read from .CFUserTextEncoding they tried to look for/save their settings in the wrong place.

Confusing, but at least there's a fix.