Thursday 24 November 2011

Wherefore Art Thou, Superglue?

As my old Superglue bottle had gone dry, it was time to buy another.

Problem. I went to 3 shops in my local village and all they had was a 'tube', not a bottle. But I knew there must be hope!

So I went all the way to town and went in a large store which sells everything. Luckily, I found it - a Loctite bottle with a brush.

The brush turned out to be a bit small, so it's harder to apply the glue to your 'broken thing'.

However, I went with my instincts and got what I wanted by going afar.

Saturday 12 November 2011

The zPad

Clive Sinclair released a portable computer in 1987, the 'Z88'. With a silent rubbery keyboard and a long battery life, journalists loved it for making notes on at meetings.

The funny thing is that Apple executives were reported to use them in board meetings.

So forget the iPad, let's hail the zPad!

Saturday 17 September 2011

Robert E.Howard / Conan drinking game

First get a copy of 'the Conan Chronicles' which is a leather-bound collection of all REH's Conan stories.

Start reading from the first story. When you come across a 'giant ape man', take a sip of whisky and move on to the next story.

Soon you'll be very drunk! ;-)

Thursday 21 July 2011

Beverly Hills Cop 2: Whodunnit?

At the end of the bank robbery scene in BHC 2, we see a limo pull away; the license plate says "DENT". Later, a Mr. Dent is revealed as a main character. So now you have no reason to watch the last 98 minutes of the film!

Friday 15 April 2011

Escaping control characters (programming)

Basically, in C, there is a control character "\" which is a slash. \n is one character, \r is another, \t is a tab, etc. Now, what do you think the control character itself should be? Well typically it is "\\". But this involves some silly search-and-replacing to change "\\" to "\".

My solution is to escape the control character itself. So you say "\e" which is replaced with a "\". Now you can process the string without first replacing all the slashes. Much better - and it doesn't even take up any more space.

Update on American hanging-up-without-saying-goodbye

I figured it out when watching a film. Basically, there is a click on the line when someone hangs up. That's how they know someone has gone without having to say goodbye.

Tuesday 22 February 2011

No Such Number, No Such Tailor

In the film Die Hard, the bad guy says he has 2 suits from "John Phillips, London". But a Google search reveals there is no such tailor. It doesn't exist!

Still, we can forgive writer Steven E. de Souza this minor detail.

Thursday 6 January 2011

First version of my custom-written C++ string replacement function to be more like Perl's

Here's the code. Use it how you like.

I don't know what'll happen with any inputs a blank string, but try not to pass blank strings in.

string myreplaceall(string input,string match,string replace)
{
//first find out how many matches in input
long i;
long mysize = 0;
for (i = 0; i < input.size(); i++)
{
if (!strncmp(input.c_str()+i,match.c_str(),match.size()))
{
i += match.size()-1;
mysize++;
}
}

//mysize tells us how many matches there are

//first deduct the match strings * mysize
long finallen = input.size() - mysize * (match.size());
//add on the replace strings * mysize
finallen += mysize * (replace.size());

//allocate a string of finallen
char *outbuffer;
outbuffer = (char *)malloc(finallen+1);

string retval;

long ptr = 0;

//copy text into outbuffer
//either a single letter, or replace the 'match' string with the 'replace' string
for (i = 0; i < input.size(); i++)
{
if (!strncmp(input.c_str()+i,match.c_str(),match.size()))
{
i += match.size()-1;
long j;
for (j = 0; j < replace.size(); j++)
{
outbuffer[ptr+j] = replace[j];
}
ptr += replace.size();
}
else
{
outbuffer[ptr] = input[i];
ptr++;
}
}

//terminate string
outbuffer[ptr] = 0;
//make string of return value
retval = outbuffer;
//free outbuffer memory
free(outbuffer);

//return replaced string
return retval;
}