You are currently browsing the archive for the Computing category.

To kill a singleton: I found this to be a useful discussion on how to write a singleton class in C++ that ensures the singleton is properly destroyed (for even multithreaded applications).

18 May 2009 | No comments

Update: Thank you to all who have contributed to the discussion below. For the impatient, here is a summary of what you might like to do:

  • If you hate Sydney Mail, fear not: you have options.
  • To redirect your Sydney Mail email to another email account, you can either a) use a “redirect” rule in Sydney Mail or b) get your email client (such as Gmail) to pick it up via POP3 (for this, see the main post below). Both a) and b) do the job.
  • To send email from within Gmail as if you were sending it from Sydney Mail, add your Sydney Mail address under the Addresses tab in Settings in Gmail.
  • However, some recipients, such as those using Outlook, may see that the sender of your email is “ on behalf of”. If you don’t like this, you can fix this by getting Gmail to send email via SMTP. To find out the address of the SMTP server, see these instructions.

“Sydney Mail is a new and significantly improved student email service,” announced the email from the university proudly.

The truth is that the university has delivered something that’s better, but is rather deficient in its own right: they’ve outsourced email to Microsoft so it’s all now run off Outlook Web Access. I could go on and on about why I would never use it, but I’ll just show you how to avoid using it.

The existing email system allows you to forward to a personal email address, and the university provides instructions for how to do it on the new system. Don’t follow those instructions! It is true that email will be forwarded from Outlook to your personal email but what happens is that the emails are literally forwarded! If Bob sends you an email, when it pops up in your personal email, the From field will show your university email as opposed to Bob, which is incredibly inconvenient.

The solution? Get your mail client to retrieve mail from Outlook via POP3. If you’re using Gmail like me, go to Settings > Accounts. Look for the “Get mail from other accounts” section and click the “Add a mail account you own” link. A window will then pop up; try the following settings:


Email sent to your university email won’t get forwarded instantly like it used to, but it’s a much better solution than the one offered by the university.

Tags: , , , , ,

Here are the solutions to the C++ maps exercise I posed in this post.

The first set of problems relates to the fact that the Employee class has no default constructor. Here’s why. In the line

	id[0] = Employee("John Smith");

what doesn’t happen is that the key 0 gets associated with the new Employee object you just created. What does happen is that the id[0] part tries to default initialise an Employee object, and then assign using operator= the Employee object you created on the right hand side. That’s all fine if you have a default constructor, but our Employee class doesn’t have one (because I’ve defined another constructor but not the default constructor). Without changing the class definition to add a default constructor, you will need to explicitly insert the key-value pair into the map, like this:

	id.insert(make_pair(0, Employee("John Smith")));

But what about this line?

	cout << id[0].name << endl;

Surely, it wouldn't be trying to call the default constructor here, because I am merely retrieving the value of id[0], which I know has already been constructed? But at compile time, how would the compiler know whether the call to id[0] will result in a new object being constructed or not even if you do? To get around this problem, you'll have to go around the long way:

	cout << id.find(0)-> << endl;

So the moral of the story is write a default constructor (if it makes sense to do so)! Note that operator[] is also unavailable when you have a const map. (Why?)

For the second lot of problems, the root of the problem is that you are using Employee as the key type of the map. You can only use a class as a key if you can order objects of that class, so you'll have to write an operator< for Employee.

Tags: ,

Why doesn’t the following code compile? Without changing the definition of the struct Employee, can you make it compile so that it does what it’s meant to do?


using namespace std;

struct Employee
	string name;
	Employee(const string& s) : name(s) { }

int main()
	map id;
	id[0] = Employee("John Smith");
	id[1] = Employee("Mary Jane");
	cout << id[0].name << endl;
	map id2;
	Employee a("A"), b("B");
	id2[a] = 100;
	id2[b] = 200;
	return 0;

Answers here.

(I gave this exercise to my C++ students a couple of weeks ago.)

Tags: , ,

Lenovo wins $150m NSW schools deal: It’s great to see the NSW government giving form to the “digital revolution” by providing laptops to schoolchildren, but the dominance of Microsoft and Adobe software denies NSW kids the chance to see beyond the Windows straitjacket — and taxpayers more bang for their buck.

16 Apr 2009 | 2 comments

a2ps is a fantastic little utility for pretty-printing source code. On Windows, you can get it as part of Cygwin.

To illustrate how to use it, let’s suppose you have a bunch of .cc and .h files in the current directory that you want to print all at once. To pretty-print these files to a printer, consider using:

a2ps -P printer_name *.cc *.h -MA4 -Afill

Read the rest of this entry »

Tags: ,

“What are the factors of 336?” I pondered, staring at the KENKEN puzzle on the screen of the computer in the SciTech library I was seated at.

Cursed computer! No calculator!

I’ve been annoyed by how locked down the computers at Sydney Uni’s libraries are for a while, so I set out to find out whether I can, in fact, bring up the humble calculator.1

Read the rest of this entry »

Tags: , , , , ,

My mobile’s battery is flat, so to call my mum to pick me up from the station, I’ve turned on my work laptop, connected to Telstra NextG, connected to VPN using my secure token, logged into Cisco IP Communicator (which emulates the IP phones we have on our desks at work) and then made a call using that. That’s pretty cool (but not quite as cool as this).

Tags: , ,

An open source, standards compliant CMS from Microsoft? That sure is trippy enough to deserve a smiling mushroom high up in an aeroplane.

14 Jan 2009 | 1 comment

I’m a PC, and I like what I see.

21 Sep 2008 | No comments

« Older entries § Newer entries »