Friday 4 March 2011

Random Minute Generator

Had a need to turk some numbers for putting into a DATETIME field in MySQL so came up with this little script for generating a set of minutes:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
  <head>
    <title>Random Minute Generator</title>
    <script type="text/javascript">
      window.onload = function addNumbers(){
        for(var x = 0; x < 217; x++){
          if (document.createTextNode){
            var myNumber = Math.floor(Math.random()*60) + 1;
            if(myNumber < 10){
              myNumber = "0"+myNumber;
            }
            var myText=document.createTextNode(myNumber);
          }
          document.getElementById("myDiv").appendChild(myText);
          var newLine=document.createElement('br');
          document.getElementById("myDiv").appendChild(newLine);
        }
      }
    </script>
  </head>
  <body>
    <div id="myDiv">
    </div>
  </body>
</html>

Do enjoy if you use it and perhaps leave a comment...?

Thursday 3 March 2011

mod_expires on Ubuntu Server

I love Firebug, it's really the only reason I use Firefox rather than Chrome as my main browser.

I particularly like Google's Page Speed add-on for Firebug - except that I always ended up scratching my head about the "Leverage browser caching" messages I heard. This hasn't been a major problem as I've usually been working on a shared server - so couldn't do anything about it. After setting up an Ubuntu Server in EC2 however I realised that I could do something about it. After having a quick search around I found this post on Absolutely Tech which led me to this post on Absolutely Tech which enabled me to install mod_expires.

Basically the process I used was to check to see if mod_expires was installed using phpinfo(), after realising that it wasn't I did sudo a2enmod expires followed by sudo /etc/init.d/apache2 restart. Now I can cache all the images on my site by adding this to .htaccess in my root directory:

# Turn on the Expires engine
ExpiresActive On
 
# Expires a week after client accesses the file
ExpiresByType image/jpeg M604800
ExpiresByType image/gif M604800
ExpiresByType image/png M604800
ExpiresByType image/x-icon M604800

Job's a good'un!

My next job is to check out Google's mod_pagespeed.