So would anybody be interested in obtaining a mySQL import file containing the complete contents of fortune-mod? If you have need of such a thing, you'll know what to do with it. I whipped this up after finding that the latest fortune-mod package now takes about 7 seconds on a fast machine to produce a cookie. This is totally unacceptable. The reason for this is that some recently added command line switches let you specify the probability that any particular category will be chosen. In order to calculate this number, the program by default loads in all the fortunes from all the category files so it can count them all.
This collection belongs in a database. Randomly selecting one element from within a collection of elements and then from within a collection of flat files (after counting each entry and then assigning probability weighting to each file) is ludicrous.
So I looked all over the web for a mySQL table containing the fortune database but couldn't find a single one. Weird. In my travels I found a tool to add fortunes to mySQL but it was pretty badly written. So I started over and did all the dirty work for you. Use these tables as you wish.
First file is fortune-mod.1.99 in a table named 'fortune' with two elements, 'id' and 'fortune'. 'id' auto-increments.
Second file is the 'offensive' tree in a table named 'fortune2' which is otherwise identical to the first. You can keep them separate, merge them, whatever.
You can pull out a fortune cookie with the following SQL - just point $table at either fortune or fortune2.
SELECT `fortune` FROM `$table`ORDER BY RAND() LIMIT 1
To display on the web, you'll need to escape the HTML entities and translate linefeeds (or it will look like mush). I use something like this... where $cookie is the raw fortune from the SQL query:
str_replace(array("&","<",">",'"',"\n"),
array("&","<",">",""","<br />"),
$cookie);The third file (fortune-mod.sql.gz) is the complete fortune-mod.1.99 in a single table. This table contains a couple of extra fields. The 'category' field contains the original fortune-mod category name, such as 'quotations' or 'zippy'. There is also an 'offensive' field which is an integer 0 for normal fortunes, 1 for offensive fortunes. Making use of these extra fields is left as an exercise for the reader. One more thing... the third file also has been stripped of all the fortunes containing backspace characters. These might be OK for a text terminal, but they look pretty ugly on the web.
Enjoy.
I tried to save myself the normal hassle of creating a regular expression to convert any relative URL's that appear in my RSS feeds to absolute form. Writing regex's is often a painful and time-consuming process. Besides, this is a problem that must've been solved before. Right?
Turns out that it has, but not as often as I would have thought. Buried on page 29 of the search results I finally found a cute little regex that did what I wanted.
Well, not quite. A beautiful function, but hopelessly broken. You see the author (I won't embarrass him by naming him in public) wrote something like '[^http|ftp|https]' to dig out an existing protocol string. Brackets in perl regex's (just like eregs) denote a character range. So this function didn't work if the relative URL began with any of the characters 'h,t,p,f,s, or |'.
So much for trying to save effort. Whenever I do this I end up with a function that is just plain broken. Sigh... You get what you pay for. Anyway, I fixed the function. If this applies to what you're doing, at least it works better than the one I originally found.
<?php
function reltoabs($text, $base)
{
if (empty($base))
return $text;
// base url needs trailing /
if (substr($base, -1, 1) != "/")
$base .= "/";
// Replace links
$pattern = "/<a([^>]*) href=\"(?!http|ftp|https)([^\"]*)\"/";
$replace = "<a\${1} href=\"" . $base . "\${2}\"";
$text = preg_replace($pattern, $replace, $text);
// Replace images
$pattern = "/<img([^>]*) src=\"(?!http|ftp|https)([^\"]*)\"/";
$replace = "<img\${1} src=\"" . $base . "\${2}\"";
$text = preg_replace($pattern, $replace, $text);
// Done
return $text;
}
?>
This went by on jwz's dnalounge blog the other day, but my feed processor doesn't import embedded videos from the wild, so you might have missed it.
Lucky you...
Something isn't adding up. Bush is expected tonight to request an additional 20-30 thousand soldiers for Iraq. And to meet this goal there are going to be more callups of the reserves and extensions of current duty tours - which also seem to be made up in large part by reserve troops.
But if you check the reference sources, the US military is supposed to have about 1.4 million active duty personnel - today. If these competent and trained soldiers aren't available to be put to work on the largest military task at hand, where are they? What are they doing?
I for one question the logic of adding an arbitrary number of troops to a situation that is tenuous at best. But a larger question emerges. If we're adding 20-30 thousand weekend warriors to a staff comprised largely of weekend warriors, why not just put a half million active duty folks over there tomorrow and act like we mean business? That would still leave us close to a million folks to handle any other world crises which might demand attention. Surely we don't have any immediate crises requiring close to a million active duty personnel.
It makes me wonder if we really have 1.4 million active duty soldiers. Maybe we don't.... Which brings up the question - how many do we really have? Given the gyrations the military is going through to keep 150,000 or so in Iraq (our most demanding campaign at the moment), it leads me to believe that the total active force must in fact be somewhat less than 300,000 (50% on standby for immediate national defense); and nobody is talking about this because it might point out how badly the volunteer army has failed and how vulnerable we really are.
Sex: Bush and friends try once again to define a 'marriage' in constitutional legalese. That means something a little more descriptive than two people who decide to hang out with each other. It also isn't good enough to say it's two people who sleep together. A man and a woman. Hmmm. This is the constitution, and we're still arguing over the right to bear arms because they didn't define a well-regulated militia very well. Ultimately this is going to require precise anatomical descriptions in order for there not to be any loopholes. The only problem is that the constitution is read and studied by school kids. It is going to be a very delicate balancing act.
Drugs: Troops in Afghanistan are going where the action is. That means to the poppy fields. There's a fresh crop. And the U.S. intends to control the valleys. You won't find this in a public policy statement, but to do this, they need to win the hearts and minds of the opium farmers. And the only way to do this is to become better at opium distribution than the Taliban.
Rock-and-Roll: Bill Wyman is more than just a survivor of 40 some odd years with the Rolling Stones. He's also a photographer, and has just published a book of photos which he took while hanging out in hotel rooms. Speaking of the Stones, it has been confirmed that none other than his satanic majesty Keith Richards will be playing Johnny Depp's (aka Captain Jack Sparrow) father in the next installment of Pirates of the Carribean. I have to hand it to the casting director - I think he's a good fit for the part. The only issue is whether or not he's got any acting talent.
Next we look for an ignition source. From the diagram:
It looks like we need neutrons. In fact what we need is a neutron gun. Here's one -
Your finished bomb:
One of Isabella's favorite songs at the moment...
Dashing through the bush, in a rusty Holden Ute,
Kicking up the dust, esky in the boot,
Kelpie by my side, singing Christmas songs,
It's Summer time and I am in my singlet, shorts and thongs
Oh! Jingle bells, jingle bells, jingle all the way,
Christmas in Australia on a scorching summers day, Hey!
Jingle bells, jingle bells, Christmas time is beaut !,
Oh what fun it is to ride in a rusty Holden Ute.
Engine's getting hot; we dodge the kangaroos,
The swaggie climbs aboard, he is welcome too.
All the family's there, sitting by the pool,
Christmas Day the Aussie way, by the barbecue.
Oh! Jingle bells, jingle bells, jingle all the way,
Christmas in Australia on a scorching summers day, Hey!
Jingle bells, jingle bells, Christmas time is beaut!,
Oh what fun it is to ride in a rusty Holden Ute.
Come the afternoon, Grandpa has a doze,
The kids and Uncle Bruce, are swimming in their clothes.
The time comes 'round to go, we take the family snap,
Pack the car and all shoot through, before the washing up.
Oh! Jingle bells, jingle bells, jingle all the way,
Christmas in Australia on a scorching summers day, Hey!
Jingle bells, jingle bells, Christmas time is beaut!,
Oh what fun it is to ride in a rusty Holden ute
Colin Buchanan / Nick Bland
There are three rather spectacular waterfalls within a few minutes of home. Here's the 'little' one...
Apologies for the lack of clarity. It's a cell phone picture.
When I was younger and got close to a pretty woman, I would have certain reactions. I'll leave it at that. But don't hang up yet, this post is actually going somewhere...
You know you've been spending too much time in the social networks when you see a pretty girl in the supermarket and your index finger starts to twitch. You want to click her.
Seems that I get about a hundred searches a week for this, so here it is.
there he goes....always thining of money again...
---
When a man and woman meet for the first time, men may be more likely to think about sex -- or at least more likely to admit it.
That's the core finding of a study in June's issue of Psychology of Women Quarterly.
The researchers included Maurice Levesque, PhD. He worked on the study while at the University of Connecticut and now works in the psychology department of North Carolina's Elon University.
---
There are two interesting things about this article:
First that Dr. Levesque apparently talked somebody into funding this research.
[You know what they say about a fool and his money...]
The second is that there is a magazine called Psychology of Women Quarterly.
[It's about bloody time...]
Ring, ring...
Hello?
You need what? A gold picture frame? Four feet by three feet? And you need it when?
Do you have any idea what time it is?
We open at ten.
Click.
Ring, ring...
This is precisely why I didn't want to use sessions for managing authentication state...
I started to notice my webserver getting really slloooooooow. Sometimes it would time out completely (I've got it setup with 60 seconds max execution time per page). How could this be? I designed the pages for maximum SQL performance. Why is it taking so long to get the database open?
Then I looked closer at the timeout message. Timeout on line 3. Line 3 hasn't even touched a database yet. It belongs to a function called 'session_open()'. Gak.
By default, PHP stores its session data in the /tmp directory. One file per session. I bop over to the session directory and do an 'ls'. It takes about fifteen minutes to list all the session files. I can't even easily count them because the shell chokes on the wildcard expansion. On a Unix filesystem, anything more than 1000 files in a single directory is bad news. It's gotten better over the years, but if you're talking about say 20,000 or 100,000 files, the operating system can't deal with it, plain and simple.
I shortened the session expiration time and made a mental note that this is going to have to be fixed. A couple of days later, timeouts again. This is right after google did a deep scan of my site. OK, something's got to give. So I look at alternatives. PHP can also use 'memory mapped' sessions. No files. OK. That sound like a winner. This is a small site, I shouldn't need that much memory. I recompile php with the necessary configuration and run it. Great. At least it works...
Then I make a mental note that I really need to figure out a way to measure the memory use because running out of memory is not a good thing. And I let it run. I figure about 100 bytes per session. The problem is that I don't know how much memory the mapper reserves for itself and what its built-in limits are. Might be 100 megabytes (roughly a million sessions). Might be a megabyte (roughly 10,000 sessions). I've got about 50 megs free. If it's well written, I should be able to manage a half a million sessions. But I didn't take the time to review the source and find the answers. I just wanted to get it working - pronto.
Big mistake. I come back the next day and I've got a blank screen. Boy this memory manager doesn't degrade gracefully. When the 'files' driver filled up, the program just hung up for a while. Using the memory driver, the page actually comes up, but there's nothing on it. The dreaded White Screen of Death. At least I now know it's reserving something considerably less than a megabyte - and not asking for more.
OK - now it's done gone and made me mad. Time to write an SQL session driver. Yeah, I know how to do it. I didn't think I'd need it, but it turns out I do. Took about twenty minutes to get it running.
The lesson here is that you can't use the built-in PHP session drivers even on a small site these days with all the crawlers running around. A few years back you might get a few hundred hits a day if you were lucky. Now it's in the thousands and tens of thousands. If you've got a weblog that pings one of the pinging services, you're guaranteed another 500-1000 hits every time you change a page. Since these are all coming from robots and aren't storing cookies, each page is going to get a new session.
So all you developers out there, if you want to use PHP sessions - hack, beg, borrow, or steal a database session driver and figure out how to use it.
Attached is a little driver I found on the web a couple years back. It's a good starting point if you've never dealt with session drivers before.

Updating all the timezone stuff one needs on a LAMP environment: (necessary in Australia because they changed the daylight savings start date once again). I haven't yet been able to convince my hosting provider to go through all this hassle; and the tables are outdated - so Aussie visitors may see an incorrect time on some of my websites for the next week.
Test:
# zdump -c 2009 -v Australia/Sydney | grep 2008
Australia/Sydney Sat Apr 5 15:59:59 2008 UTC = Sun Apr 6 02:59:59 2008 EST isdst=1 gmtoff=39600
Australia/Sydney Sat Apr 5 16:00:00 2008 UTC = Sun Apr 6 02:00:00 2008 EST isdst=0 gmtoff=36000
Australia/Sydney Sat Oct 4 15:59:59 2008 UTC = Sun Oct 5 01:59:59 2008 EST isdst=0 gmtoff=36000
Australia/Sydney Sat Oct 4 16:00:00 2008 UTC = Sun Oct 5 03:00:00 2008 EST isdst=1 gmtoff=39600
(If the first two lines contain 'Mar' instead of 'Apr' you've got old tables). e.g. this is what an unpatched system would report:
# zdump -c 2009 -v Australia/Sydney | grep 2008
Australia/Sydney Sat Mar 29 15:59:59 2008 UTC = Sun Mar 30 02:59:59 2008 EST isdst=1 gmtoff=39600
Australia/Sydney Sat Mar 29 16:00:00 2008 UTC = Sun Mar 30 02:00:00 2008 EST isdst=0 gmtoff=36000
Australia/Sydney Sat Oct 25 15:59:59 2008 UTC = Sun Oct 26 01:59:59 2008 EST isdst=0 gmtoff=36000
Australia/Sydney Sat Oct 25 16:00:00 2008 UTC = Sun Oct 26 03:00:00 2008 EST isdst=1 gmtoff=39600
Debian:
# apt-get update
# apt-get install tzdata
PHP5.x
# apt-get install php5-dev
[fetch and save] http://pecl.php.net/get/timezonedb
# tar zxvf timezonedb-xxxxxxx.tgz
# cd timezonedb-xxxxxxx
# phpize
# ./configure
# make
# make install
# echo "extension=timezonedb.so" > /etc/php5/conf.d/timezonedb.ini
# /etc/init.d/apache2 restart
MySQL:
# mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql -p
(ignore all the errors from Riyadh{NN}, iso3166.tab, and zone.tab)
Those two or three people who actually visit this website may have noticed that I haven't done much with it lately. I think it's time to declare it over and done with - though I'll leave the archives here indefinitely should anybody wish to see the timeline of happenings.
Blogging is so 2002. Social nets are so 2004. I'm tired of it all. Seems the world has tired of my writings as well (or more accurately it's just another channel of stuff amongst the 200+ million channels of stuff to choose from on the web). Thanks to the RSS fiasco and a host of other factors (e.g. search behaviour, PageRank changes, my use of a 'non-standard' community platform, etc.), traffic has plummeted way beyond rock bottom. We're now down to 3 visitors a day on average, down from 100,000 back in October and even the 20-30,000 around Christmas.
There's no point anymore writing into space - as I mentioned a few weeks back. The photo albums for friends and family are largely unseen. Except for two of you, friends and family are too intimidated by online spaces to touch the place.
The community site has been a dismal failure - a lot of hard work wasted.
It's coming up on one year since I arrived in Australia, and so much has changed. Work and family consumes my time, as it should (at least family). Work is what it is. Blogging and social nets are a thing of the past, and tremendous time-wasters at that.
It was fun. Now onto the next chapter - of a book which probably won't be written online.
I'm pretty much ranted out.

The school start of session turned out to be a non-event thanks to all the preparatory work we've done in the last few weeks. Yawn. Whew!
Gas prices in San Francisco hit $3.35/gallon. Which infers that peninsula prices are probably closing in on $3.50. Whatever. Don't whine. We pay a bit over $5 here.
The U.S. shoots down its errant Keyhole satellite. Seems that a load of hydrazine fuel may or may not be the hazardous substance they were warning us about - if indeed there was one. Likely this had something to do with posturing vis-a-vis China who shot a satellite to smithereens (actually large chunks) recently. If the thing smashed up over a major city it wouldn't really matter if it had a full tank or not. The death toll would be about the same either way. The real motive is probably that it was headed for a crash somewhere that the US couldn't get to and lock down the site.
Nader jumps into the presidential race. Why now? OK, better question - why at all? The media never took him seriously enough to do their routine mudslinging probes. Let's quickly figure out what skeletons are in his closet and get rid of him before he screws up yet another election.
Yesterday around lunchtime an entire subnet at the school went 'dark'. This is not good. The session ('semester' for my friends in the northern hemisphere) starts on Monday. This is the absolute busiest time of year for faculty and staff because we've got a lot of stuff to prepare for next week when the hammer falls.
The curious thing is that the subnet that went 'dark' was only one subnet, and another subnet which traverses the same wire continues to work fine. So only a random smattering of machines was affected. This made it very difficult to even track down what happened because it appeared as a random cluster of machines that suddenly could not route packets. As it turns out they're all related by having an equal third byte of the IP address. What made it even more difficult to troubleshoot is that two of these machines which went dark are the primary DNS servers, so when they vanished, nobody could see anything 'by name' until we patched a couple of machines over to an alternate.
Trying to get anything done by IP number is a minefield, because even if you don't use any hostnames directly, you might accidentally touch a server or service which does - and you're screwed; waiting for it to time out (if you're lucky). Some services just hang until you get tired of looking at the hourglass icon and then you have to go find another already logged-in session somewhere else to work. Can't start any new sessions because they mount home directories, which touch name servers and will hang.
So I'm chugging the morning coffee and heading off to work an hour early this morning to try and recover from this disaster. Spent half the night awake formulating a plan after spending the entire evening determining for certain where the problem was. The problem is a router that's locked in a closet, and only the main campus IT folks have keys. Coincidentally, they made some configuration changes in that closet yesterday. Around lunchtime.
Gentlemen, get over here right now and unlock that door.
Unfortunately it isn't that easy, as there are layers of bureaucracy to contend with. My backup plan is to move two of our absolutely critical machines out of the darkness and into the light. One of them I can unplug and carry away. The other is a virtual machine living on two networks (which can run elsewhere) but I've got to find a wire in another room/building that can talk to both subnets. Oh and a cooperative host with enough disk and memory, that won't mind being loaded up with an alien machine.
I've got this Minarik Goddess Special Edition guitar that I picked up to sell a few years back, and it never sold. So I kept it. It's really an awesome guitar, but I could never quite figure out why I didn't like it. It's 'meaty' (the best way to describe it). Not a speed demon. Should be great for jazz, rhythm, or chordings like heavy metal or ACDC. Beautiful to look at, exceptional tone quality. But it sounded like shit. I didn't do anything with it until recently because of this, and the fact that it was best left as-is as a collectible to hopefully sell some day. (Serial # 000025).
But finally I figured that it wasn't much good to anybody if it sat in the case year after year. So I put some decent strings on it, changed the neckstrap button to play it backward, and then did a setup (to match the new strings to the scale length). That improved things quite a bit. It no longer sounded horrible. But it was still lacking sustain. Curious because being so meaty you'd think that is where it would shine. The problem was the frets - big meaty badass frets that had been hand shaped. And therein lies the problem. The hand shaping left them a bit rough. It took a few weeks of playing for the strings to 'polish' both the frets and the intricate inlays and smooth them out. Now it sings like a bird. I can add it to the list of 'perfect' guitars that I've acquired over a lifetime of searching. It doesn't matter that it's 'meaty' because that's a quality that makes it suited for particular uses. No guitar is perfect for all uses. They all have their special qualities which makes them best suited for one thing or another.
Looks pretty much like this one, except hers is left-handed. Mine is right-handed but I play it backward (left-handed). Don't ask. The answer will make your brain hurt.
Coincidentally, my Phoenix acoustic (which is currently showing in the main macgirvin.com website banner) also has improved recently - although it was already near perfect. This was from a batch of guitars I bought a few years back that were all awesome except they all cracked and split. I've spoken about this previously. This one didn't actually split, but developed two hairline cracks on the backside (that didn't affect the sound or beauty). Anyway, I'm pleased to report that with relocating to a more humid environment, the hairline cracks completely vanished! It's perfect once again, and as far as I know, the only surviving specimen of this incredible line of guitars.
means I'm a member of the IA. That's Inamorati Anonymous. An inamorato is
somebody in love. That's the worst addiction of all."
"Somebody is about to fall in love," Oedipa said, "you go sit with
them, or something?"
"Right. The whole idea is to get where you don't need it. I was
lucky. I kicked it young. But there are sixty-year-old men, believe it or
not, and women even older, who might wake up in the night screaming."
"You hold meetings, then, like the AA?"
"No, of course not. You get a phone number, an answering service
you can call. Nobody knows anybody else's name; just the number in case
it gets so bad you can't handle it alone. We're isolates, Arnold. Meetings
would destroy the whole point of it."
-- Thomas Pynchon, "The Crying of Lot 49"
fortune.sql.gz
Digg
Delicious
Netscape
Technorati
reltoabs.php.txt
11-NOV-2005.mp3
preg_replace("/(href|src)=\"(?!http|ftp|https)([^\"]*)\"/", "$1=\"$base\$2\"", $text);Sup -
I thought about doing that but only wanted to apply the absolute reference to named anchors and images. The attributes 'href' and 'src' are used in other tags (href is used in link tags and src in script tags for example). But now that you've brought it up, a relative URL is a relative URL. It's probably a good thing to convert all of them, no matter what kind of element they might be attached to.