31 May 2002

How to create a random CSS background image

I found a rather annoying side affect of using the useful background image CSS property was that it was actually very difficult to programmatically change at runtime. Although I use Castalian, any web programming language can be used to dynamically serve HTML, but how can you serve dynamic CSS?

The only solution I could think of, but I'm sure there must be others, involves have a separate CSS file for each image you are using. To manually write a CSS file for each image is time consuming and problematic, so the solution would have do it automatically.

Solution Steps

1. I exposed the code that I wanted to randomize in a separate CSS file

body { background-image:url(/css/test1.jpg); }

2. Created a directory structure for the images and generated CSS files, so that it was easy to managed. I chose

/css/random/image

for the images

/css/random/css

for generated css files

3. Wrote the python code that took each file in the image directory and created a CSS file of the above format for it.

def createCSSFiles(self):
dirlist = os.listdir(self.root_dir + self.image_dir)
dirlist.sort()

for i in range(len(dirlist)):
outfile = os.path.join(self.css_dir, 'ri_' + os.path.splitext(dirlist[i])[0] + '.css')

f = open(self.root_dir + outfile,'w')

f.write('body { background-image:url(')
f.write(self.image_dir + '/')
f.write(dirlist[i])
f.write('); }')

f.close()

4. Wrote the python script that would pick a random css file

def serveRandomCSSPath(self):
dirlist = os.listdir(self.root_dir + self.css_dir)
dirlist.sort()
rndnum = random.choice(range(1,len(dirlist)+1))
return os.path.join(self.css_dir, dirlist[rndnum-1])


5. Created the castalian code to dynamically generate the html that calls the CSS file

<?cas
from randomImage import randomImage
ri = randomImage()
response.write('<link rel="Stylesheet" rev="Stylesheet" href="')
response.write(ri.serveRandomCSSPath())
response.write('">')
?>

You can either run the createCSSFiles method each time you move an image into the directory, or as a cron job (or even every time you run the Castalian page I suppose) trading off how quickly you want it to get the image against making the system automatic.

The index page displays one of three random images.

Posted at 22:20

20 May 2002

Star Wars Movie Order

Seems nearly everyone is asking this question.

Despite the fact that Episode III will be out in four years time, neither George nor Emilia will be old enough to watch a Star Wars movie until they are all out (unless Mr. Lucas goes back and actually does do 7,8,9).

So, when they are old enough to watch them, should I start them with 4 or 1? What would you do?

If you start with 4, you do get the best story first. (New Hope is the best story, ESB is the best film)
If you start with 1, you get to see it in order. Will it make more sense?
If you see 1 first, will it be better than if you watched 4-6 first ?
Will going from the special effects brilliance of 1-3, to the 70's effects of 4 ruin the film?
Will they both go "This is rubbish Dad, put on Spiderman III"?

Which order would you go for? (bet no one even likes Star Wars)

Posted at 17:12

Obscure Links

What links myself, this website, my son, vacuum cleaners, God and very very large spherical objects?

Answer :
Freeman Dyson, who called his son George.
I own a Dyson Vacuum Cleaner.
Finally, in the Doctor Who novel "The Also People" God, a super computer, rules a Dyson sphere visited by Bernice Summerfield, lecturer at the University of Dellah.

I thank you.

posted because I saw "George and Freeman Dyson" in NTK, and thought it was kind of odd. No other reason.

Posted at 16:57

16 May 2002

Separated at birth?

ruudgroo.jpg

The Groosalugg vs Ruud Van Nistelrooy

One's an all action hero and has a big chin, the other got it on with Cordelia and has a big chin.

Posted at 15:27

14 May 2002

Redesign spreads

The front page design is now covering the rest of dellah.com; including the weblog and journal.

Please let me know what you think of it. Likes, dislikes, requests for improvemenst. Just need to get the journal entries up to date and I'll be ready for some real stuff. (xPlod 2)

Posted at 14:11

9 May 2002

List of Entries or Latest Entry

In a slow attempt to move the site over to the new dellah.com format, I designed a page. And then I stopped.

Should it be like this, or should be just a list of entries like Avocadia? After all this index links to the actual stories.

What do you think?

UPDATE: Too late. It's all been done for Vent. Orient and Continual next week. I've run out of time.

Posted at 16:53

8 May 2002

Pictures of George, Part 1

From birth to First Feed. These images capture the first few hours of George's life.

24th April 7:49am - 4 minutes after the birth and George is being checked over by a nurse.
Checking out George

8:09 - The nurses finish cleaning George, and dress him in a baby grow. He promptly falls asleep.
George asleep

8:24 - George is swaddled and handed back to mother. All attempts at eye contact fails as George is still asleep.
George swaddled

12:20 - Mother and son now out of the labour room and in the maternity ward. George is unimpressed by the change of surroundings and remains asleep.
Sleeping George

16:36 - I'm awake! Looking hungry George wakes up and is about to have a feed.
George awake

More tomorrow.

Posted at 13:45

Hoopla500

Textism has started a Google Bomb on Verisign.

Now, there are two reasons for me to make a Vent about this. Firstly, Hoopla500 was a damn fine read, one of seven writing websites I checked daily. It is good to see it is back at Harpold500.

Secondly, I was thinking about internet presence whilst I was away. What would happen if dellah.com vanished in the same way? What is there was some random reader out there who liked the site but wasn't in any of the other circles that I frequent. Given time, I'd get the site back up in a new location and tell my friends and all three people I thought read the site. I'd post to the newsgroup and the message board and everything would be fine. Except for the poor guy who doesn't know any of those circles. Dellah.com gone and forgotten. Lost forever.

I'm sure it has happened with Hoopla500. There must have been people who had read Hoopla without also reading Textism, or somewhere else and will never read it again. That's why it is important, even if this particular issue isn't resolved. To try and stop it happening again.

Posted at 11:06