PHP Script to list and display all images in a directory

<?php
 
$path = "./";
$dir_handle = @opendir($path) or die("Unable to open folder");
 
while (false !== ($file = readdir($dir_handle))) {
 
	if (strpos($file,'.jpg') ||strpos($file,'.gif')||strpos($file,'.png')) {
		echo "<img src='$file' alt='$file'><br />";
	}
}
closedir($dir_handle);
 
?>

Demo

Javascript Count Up Timer With Hours, Minutes, and Seconds

Here is a script that takes a given time and increments each second to make it appear to update in realtime.

Time given, must be in hh:mm:ss format and the div id must be realtime

<span id="realtime">12:12:12</span>

12:12:12

Script that makes everything happen, needs jquery, but could be easily re-written in pure javascript.

$(document).ready (function () {
    startCount();
});
 
function startCount()
{
	timer = setInterval(count,1000);
}
function count()
{
	var time_shown = $("#realtime").text();
        var time_chunks = time_shown.split(":");
        var hour, mins, secs;
 
        hour=Number(time_chunks[0]);
        mins=Number(time_chunks[1]);
        secs=Number(time_chunks[2]);
        secs++;
            if (secs==60){
                secs = 0;
                mins=mins + 1;
               } 
              if (mins==60){
                mins=0;
                hour=hour + 1;
              }
              if (hour==13){
                hour=1;
              }
 
        $("#realtime").text(hour +":" + plz(mins) + ":" + plz(secs));
 
}
 
function plz(digit){
 
    var zpad = digit + '';
    if (digit < 10) {
        zpad = "0" + zpad;
    }
    return zpad;
}

Create Global Function In Magento

This code will allow you to add a function that can be called from anywhere within Magento. It extends the helper class

1) Create a file named ‘Mycode.xml’ and copy it to app/etc/modules/ – it should look like this:

<?xml version="1.0"?>
<config>
    <modules>
		<Mycode_Function>
			<active>true</active>
			<codePool>local</codePool>
		</Mycode_Function>
    </modules>
</config>

2) Create the directory
app/code/local/Mycode/Function/etc
and then create a file named ‘config.xml’
In it copy:

<?xml version="1.0"?>
<config>
 
    <modules>
        <Mycode_Function>
            <version>1.0.0</version>
        </Mycode_Function>
    </modules>
 
    <global>
 
        <helpers>
            <function>
                <class>Mycode_Function_Helper</class>
            </function>
        </helpers> 
 
    </global>
 
</config>

3) Create the directory
app/code/local/Mycode/Function/Helper
and then create a file named ‘Data.php’
In it copy:

<?php
 
class Mycode_Function_Helper_Data extends Mage_Core_Helper_Abstract
{
 
	public function test(){
 
	return 'works';
 
	}
 
}

You can now call this function like so

		<?php 
 
		 echo Mage::helper('function')->test();
 
		 ?>