Random images as a background in HTML

by Kevin on February 6, 2009
in Random Knowlege

A nice wee gem that Alex Peake informed me was possible. The problem: you want a randomly chosen image as a background but don’t want duplication in your css.

In your css file:

background-image: url('images/background.php');

Create the file referenced above with this code:

<?php
    $numofimages = count(glob("*.jpg"));
    $imagenum = rand(1, $numofimages);

    header("Content-Type: image/jpeg\n");
    header("Content-Transfer-Encoding: binary");

    $fp=fopen("headerimage". $imagenum .".jpg" , "r");
    fpassthru($fp);
?>

and voila, random images as a background with the bonus of being able to throw in a new image without having to do any more coding.

This code assumes that your images are called headerimageX.jpg where X is a number.

Well that was a random night

by Kevin on November 16, 2008
in Journal

Last night, I got a phone call asking If I wanted to go bowling. I replied positivly an had my tea. Sortly afterward, another which changed the plan to seeing a band in Glasgow. Fair enough, seeing a random band would be ok.

Franny and Stu picked me up and we sped (pretty quickly) off to Glasgow. Little did I know how interesting this night would be.

The first time we got lost was interesting. I think we went round a roubdabout about 5 or 6 times trying to pick an exit. My phone with its gps capabilities was pretty useless. Franny picked an exit and we drove, further getting lost. Eventually we saw a sign for the city center and followed that.

About 500 meters away from the venue (Carling Academy), a dog ran out into the street. Thankfully, the car infront of us slowed down in time so I don’t think it was hit though I could be wrong. Round the corner, we saw a fox (never seen one before, let alone in the middle of a city) doing its thing. Very strange.

We abandoned the car in a private car park, got our tickets and went in to the gig.

Caught the tail end of the support band, I think they were calld Hotleg. Think hair metal with Justin Hawking as the singer. Not bad but the singing was too high pitched.

The main band were a group called Extreme. With a name like that, I thought it would be death metal or some derivative which had me a bit worried, we were in prime mosh pit space. Thankfully, they were less heavy than I thought.

Two phrases that spring to mind when describing the vocalist are “bust a move” and “strike a pose”. The guy was working the entire stage, swinging the mic stand about, climbing on stacked boxes and even riding the bass amps like a horse at one point.

Not sure hoe to describe their music. Good chunky riffs (for the most part) but the singing was a bit naff in my opinion. Eventually after over an hour and a half of playing, they departed the stage for good and we left for the next interesting phase of the trip, getting home.

We got lost. Franny had no idea how to get back to the motorway so we drove about, taking random roads, almost running a red light (again). After 15 mins of random driving, we found the motorway and got on thinking it would take us back to Perth. Oh how wrong we were.

To give you an idea, we crossed the Fourth Road Bridge.

Eventually we got back to Perth, cruised about for a bit and then I crashed at my house leaving the stoners to do what they do at 1am.

Next time we do this, I’m bringing a real sat-nav.

Fail, ASP and other misc stuff

by Kevin on October 9, 2008
in Journal

Today was a mixed bag as far as things go. First off, I had some car trouble. The engine malfunction light came on, there was some beeping and the engine started shuddering while going over 60mph. So I pulled over and switched off. Started again and the light came on. So I called AA, got my dad to take my brother to uni and hung about until the AA arrived.

They found nothing wrong so I moved off the motorway at the nearest junction. No problems. The guy was on his way to Dundee so he escorted me until my turn off. No problems. Got back with no problems as well.

What I think happened (I am not a mechanic, this is not meant to be accurate info) is that the lambda sensor (monitors CO2 emissions) went wonky and the engine computer decided to let me know. In the time waiting for recovery, the system reset and all was good. A similar situation happened a couple years ago, took my car to the garage and they said it was the sensor misfiring.

While in Dundee waiting for the last class of the day (3 hour gap is a bit of a pain) I went for a bit of a shop. I have been needing some new shaving soap as the stuff I have has pretty much run out. I went to Lush to see what they have and the assistant suggested to use some “snowcake” soap which seems to be made from almonds. The lady said it lathers up well so I went with it. I also got a sample of some “Prince” soap stuff. Will report on how well they work.

In the union, I found some Ubuntu Cola (site needs flash), 80 pence for 2 cans which is not bad. It is not the same folk who make the linux distribution but they do use fairtrade sugar. Unfortunatly, the taste is the same as a certain cola maker who will not be named. Had caffeine as well which is a downer for me (causes headaches, I don’t drink much caffeine at all). I have a can on my desk, not sure what I will do with it. Anyone want it?

Now for some more technical stuff. As part of my uni course, I have a module called “Enterprise Internet Solutions” which involves using ASP.Net. Initially I balked at using it but I am warming up to it. There are some niceitys to it, such as piss easy form creation and processing. It is mainly drag and drop (as is typical of Microsoft development) but you can use the code window exclusivly if you want.

What I really like about ASP.Net is that the processing code is seperated from the html/xml code used for output in the browser. ASP uses xml tags for the user interation widgets (buttons, input boxes etc) in the form

<asp:controltype ID="something" attribute="something"></asp:controltype>

This can be shortened to

<asp:controltype ID="something" attribute="something" />

so you have well formed xml empty tags. If you remember all the different attributes and control types then you can use a plain text editor which brings me neatly to my next point.

ASP.Net aparrently works with Mono on linux so that is where I will be going if it works. Won’t be using a huge clunky expensive IDE, I will be using vim instead (emacs users, direct flames to /dev/null). Hopefully I can get it working with MySQL as well.

On a further tech note, Stanford university has released a bunch of courses online.