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.
Robot updated
by Kevin on January 21, 2009
in Robot Army
Just a quick post to say that my robot code has been updated to communicate with my arduino. Learned some more about Python as well, mostly relating to how badly I suck at it. Can’t get object orientation to work with modules but objects are not necessary for this. Straight procedural code is all that is required, for the moment.
Wordpress functions in other pages
I have rediscovered a cool thing that can be done with Wordpress involving static pages. I run my site with a static index.php as the front page. It would be a massive pain in the ass to re-theme it every time I changed my Wordpress theme, along with any other pages I make. I remembered something in the documentation about adding a line of code to your php files and being able to access all the functions available in Wordpress and went looking, unsuccessfully.
I then remembered that the index.php file of a Wordpress install contains something like what I was looking for. I copied it (require(‘./path/to/wp-blog-header.php’) ) into the front page along with the functions to display the header, sidebar and footer (get_header(), get_sidebar() and get_footer() respectively) and found that it worked.
Full code for this is below (assumes that your wordpress install is in /wordpress and your page is in the root of your site)
<?php require('./wordpress/wp-blog-header.php'); ?>
<?php get_header(); ?>
<div id="container">
<div id="content">
<!--your stuff goes here-->
</div>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
</div>
</body>
</html>
Fail, ASP and other misc stuff
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.
Upload Reloaded
I did a bit more hacking of my upload script (note the exension change) to tweak some things and make it more secure. The updated code is available for criticism/comment.
I still consider the script to be in beta. It would be nice if folk could test it and report on any errors you encounter (particularly file size related).
I am blocking php asp and python scripts as they are most likely to run on the server and are capable of owning me (which I do not want happening. What other extensions should be blocked on a Linux server?