Computing

You are currently browsing the archive for the Computing category.

To kill a singleton: I found this to be a use­ful dis­cus­sion on how to write a singleton class in C++ that ensures the singleton is prop­erly des­troyed (for even mul­ti­th­readed applic­a­tions).

18 May 2009 | No comments

Update: Thank you to all who have con­trib­uted to the dis­cus­sion below. For the impa­tient, here is a sum­mary of what you might like to do:
  • If you hate Sydney Mail, fear not: you have options.
  • To redir­ect your Sydney Mail email to anoth­er email account, you can either a) use a “redir­ect” rule in Sydney Mail or b) get your email cli­ent (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 with­in Gmail as if you were send­ing it from Sydney Mail, add your Sydney Mail address under the Addresses tab in Set­tings in Gmail.
  • How­ever, some recip­i­ents, such as those using Out­look, may see that the sender of your email is “xyz@​gmail.​com on behalf of abcd1​2​3​4​@​uni.​sydney.​edu.​au”. If you don’t like this, you can fix this by get­ting Gmail to send email via SMTP. To find out the address of the SMTP serv­er, see these instruc­tions.

“Sydney Mail is a new and sig­ni­fic­antly improved stu­dent email ser­vice,” announced the email from the uni­ver­sity proudly.

The truth is that the uni­ver­sity has delivered some­thing that’s bet­ter, but is rather defi­cient in its own right: they’ve out­sourced email to Microsoft so it’s all now run off Out­look Web Access. I could go on and on about why I would nev­er use it, but I’ll just show you how to avoid using it.

The exist­ing email sys­tem allows you to for­ward to a per­son­al email address, and the uni­ver­sity provides instruc­tions for how to do it on the new sys­tem. Don’t fol­low those instruc­tions! It is true that email will be for­war­ded from Out­look to your per­son­al email but what hap­pens is that the emails are lit­er­ally for­war­ded! If Bob sends you an email, when it pops up in your per­son­al email, the From field will show your uni­ver­sity email as opposed to Bob, which is incred­ibly incon­veni­ent.

The solu­tion? Get your mail cli­ent to retrieve mail from Out­look via POP3. If you’re using Gmail like me, go to Set­tings > Accounts. Look for the “Get mail from oth­er accounts” sec­tion and click the “Add a mail account you own” link. A win­dow will then pop up; try the fol­low­ing set­tings:

Settings

Email sent to your uni­ver­sity email won’t get for­war­ded instantly like it used to, but it’s a much bet­ter solu­tion than the one offered by the uni­ver­sity.

Tags: , , , , ,

Here are the solu­tions to the C++ maps exer­cise I posed in this post.

The first set of prob­lems relates to the fact that the Employ­ee class has no default con­struct­or. Here’s why. In the line

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

what doesn’t hap­pen is that the key 0 gets asso­ci­ated with the new Employ­ee object you just cre­ated. What does hap­pen is that the id[0] part tries to default ini­tial­ise an Employ­ee object, and then assign using operator= the Employ­ee object you cre­ated on the right hand side. That’s all fine if you have a default con­struct­or, but our Employ­ee class doesn’t have one (because I’ve defined anoth­er con­struct­or but not the default con­struct­or). Without chan­ging the class defin­i­tion to add a default con­struct­or, you will need to expli­citly 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 try­ing to call the default con­struct­or here, because I am merely retriev­ing the value of id[0], which I know has already been con­struc­ted? But at com­pile time, how would the com­piler know wheth­er the call to id[0] will res­ult in a new object being con­struc­ted or not even if you do? To get around this prob­lem, you’ll have to go around the long way:

	cout  id.find(0)->second.name  endl;

So the mor­al of the story is write a default con­struct­or (if it makes sense to do so)! Note that operator[] is also unavail­able when you have a const map. (Why?)

For the second lot of prob­lems, the root of the prob­lem is that you are using Employ­ee 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 Employ­ee.

Tags: ,

Why doesn’t the fol­low­ing code com­pile? Without chan­ging the defin­i­tion of the struct Employ­ee, can you make it com­pile so that it does what it’s meant to do?

#include 
#include 
#include 

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 exer­cise to my C++ stu­dents a couple of weeks ago.)

Tags: , ,

Len­ovo wins $150m NSW schools deal: It’s great to see the NSW gov­ern­ment giv­ing form to the “digit­al revolu­tion” by provid­ing laptops to school­chil­dren, but the dom­in­ance of Microsoft and Adobe soft­ware denies NSW kids the chance to see bey­ond the Win­dows strait­jack­et — and tax­pay­ers more bang for their buck.

16 Apr 2009 | 2 comments

a2ps is a fant­ast­ic little util­ity for pretty-print­ing source code. On Win­dows, you can get it as part of Cyg­win.

To illus­trate how to use it, let’s sup­pose you have a bunch of .cc and .h files in the cur­rent dir­ect­ory that you want to print all at once. To pretty-print these files to a print­er, con­sider using:

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

Read the rest of this entry »

Tags: ,

“What are the factors of 336?” I pondered, star­ing at the KENKEN puzzle on the screen of the com­puter in the SciTech lib­rary I was seated at.

Cursed com­puter! No cal­cu­lat­or!

I’ve been annoyed by how locked down the com­puters at Sydney Uni’s lib­rar­ies are for a while, so I set out to find out wheth­er I can, in fact, bring up the humble cal­cu­lat­or.1

Read the rest of this entry »

Tags: , , , , ,

My mobile’s bat­tery is flat, so to call my mum to pick me up from the sta­tion, I’ve turned on my work laptop, con­nec­ted to Tel­stra Nex­tG, con­nec­ted to VPN using my secure token, logged into Cisco IP Com­mu­nic­at­or (which emu­lates 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, stand­ards com­pli­ant CMS from Microsoft? That sure is trippy enough to deserve a smil­ing mush­room high up in an aero­plane.

14 Jan 2009 | 1 comment

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

21 Sep 2008 | No comments

« Older entries § Newer entries »