quick update – my bad

I haven’t posted all week, my bad. I’ve been in the midst of interview preparation reading and actually doing interviews. I’m meant to be hearing back mid next week, so hopefully have a “nice” update then.

In the meantime, I have been working on some more tutorials, so I’ve just got to format them and then I can get them posting. Offline the rest of the weekend, as I’m visiting my grandmother (cue soppy sighs….), but I should be able to get most of the tuts finished tonight and then get them uploaded on Monday.

Meanwhile, check out:

And remember, always behave, but sometimes behave badly.

Advertisements

quick update – April Fools around the web

Just a brief list of some of the April Fools going on around the web today

There’s heaps more out there, so get hunting  and add them to the comments.

quick update – what I’ve been up to

Well, obviously, I’ve been knocking out quite a few tutorials over the past week or so, but not so much about moi. Basically, I’ve been working hard and prepping for interviews. A couple of promising leads ahead, with possible offers due in from a few options in the next week or two. I have some opinions about which I want, or don’t; but I’m waiting for paper before I decide.

Last weekend, as I posted, I was down in Napier for the wedding of my good friends Hamish and Julie. It was a great day, and the weather held absolutely perfect for all of Saturday. I’m yet to post photos to facebook, but I will this weekend as soon as I get some decent internet time. My blogging recently has been in offline mode, with updating when connected.

Looking forward to Easter weekend, with some gardening and chores, but mainly chilling out and relaxing; as well as ongoing interview prep and reading. Also attempting to keep my various languages active, so I’ll probably focus on XML and C# over the weekend. Clash of the Titans is out today, so I may make it to the cinema for that also.

No-one’s announced iPad availability in New Zealand yet either, so it’s just a waiting game here. At least none of the telcos have announced a bundled deal yet either, which is great as that’ll just destroy half the point of it. Still hoping Apple sells it directly un-contracted, so we can actually use it as intended.

Anyway, no major developments in my life this week, just the ongoing job hunt really. I’ve got a couple more PHP tutorials to post, and then I’ll deal to a few others in various languages.

automatic file listing in PHP

Displays a hyperlinked list of all the files contained in a specified folder. A really simple way to have your own directory browser, just drop the file in the folder as index.php and it will show an index of all folders in the directory on your webspace.

<?

/*
 * Change the path to your folder.
 *
 * This must be the full path from the root of your
 * web space. If you're not sure what it is, ask your host.
 */

    // Define the full path to your folder from root
    $path = "/home/user/public/foldername/";

    // Open the folder
    $dir_handle = @opendir($path) or die("Unable to open $path");

    // Loop through the files
    while ($file = readdir($dir_handle)) {

    if($file == "." || $file == ".." || $file == "index.php" )

        continue;
        echo "<a href=\"$file\">$file</a><br />";

    }

    // Close
    closedir($dir_handle);

?> 

automatic folder listing in PHP

Displays a hyperlinked list of all the folders contained in a specified folder. A really simple way to have your own directory browser, just drop the file in the folder as index.php and it will show an index of all folders in the directory on your webspace.

<?php
$projectsListIgnore = array ('.','..');
$handle=opendir(".");
$projectContents = '';
while ($file = readdir($handle)) 
{
	if (is_dir($file) && !in_array($file,$projectsListIgnore)) 
	{		
		$projectContents .= '<li><a href="'.$file.'">'.$file.'</a></li>';
	}
}
closedir($handle);
?>

<html>
<head>
<title>base scripts</title>
<style type="text/css">
* {
	margin: 0;
	padding: 0;
}
html {
	background: #ddd;
}
body {
	margin: 1em 10%;
	padding: 1em 3em;
	font: 80%/1.4 tahoma, arial, helvetica, lucida sans, sans-serif;
	border: 1px solid #999;
	background: #eee;
	position: relative;
}
h2 {
	margin: 0.8em 0 0 0;
}
ul {
	list-style: none;
	margin: 0;
	padding: 0;
}
a {
	color: #024378;
	font-weight: bold;
	text-decoration: none;
}
a:hover {
	color: #04569A;
	text-decoration: underline;
</style>
</head>
<body>
<h2>directory of folders</h2>
<ul class="projects"><?php echo $projectContents; ?></ul>
</body>
</html>

I’ve raided some of the Apache CSS to make it pretty, so credit goes there for the looks.

convert links into clickable hyperlinks with PHP

This function changes an email address or URL into a clickable HTML hyperlink using eregi_replace.

<?php

function makeClickableLink($text) {
    $text = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)', '<a href="\\1">\\1</a>', $text);
    $text = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&//=]+)', '\\1<a href="http://\\2">\\2</a>', $text);
    $text = eregi_replace('([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})', '<a href="mailto:\\1">\\1</a>', $text);
    return $text;
}

// Usage 

// Email address example
$text = "you@example.com";
echo makeClickableLink($text);

// URL example
$text = "http://www.example.com";
echo makeClickableLink($text);  

// FTP URL example
$text = "ftp://ftp.example.com";
echo makeClickableLink($text); 

?>

It’s pretty self-explanatory at a high level, but when you delve into the regex it does get a bit baffling. Let me walk you through it.

The Explanation:

Step 1:

$text = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)', '<a href="\\1">\\1</a>', $text);

The first eregi_replace checks whether the supplied string contains an ‘f’ or ‘ht’, followed by ‘tp://’ then a string of characters restricted to those allowed by W3 specifications. This string is then inserted into a link phrasing, both as the href and as the link text.

Step 2:

$text = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&//=]+)', '\\1<a href="http://\\2">\\2</a>', $text);

The second eregi_replace checks whether the supplied string begins with any spaces, then ‘www.’ followed by a string of characters restricted to those allowed by W3 specifications. The spaces clause is then inserted before a link phrasing, the string beginning ‘www.’ is then inserted in the link phrasing both as the href and as the link text preceded by ‘http://’. This overwrites $text.

Step 3:

$text = eregi_replace('([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})', '<a href="mailto:\\1">\\1</a>', $text);

The third eregi_replace checks whether the supplied string begins with characters, is followed by an ‘@’ , followed by more characters, a full-stop, and then either 2 or 3 lower-case alpha characters. This again matches W3 specifications. This matched pattern is inserted into a string which formats it as a mailto link.

A-Team van on display at NY Auto Show

What more can I say??

A-Team Van (credit: NY Times)

It’s at the entrance to the Jacob K. Javits Convention Center. The original was a 1983 GMC Vandura G15, but for the upcoming movie (June 11th release) they’ve used a GMC G20 Vandura.

Because, when you’re running from the military, what better vehicle to cruise around in than a souped-up van with a massive red wing?

Sourced via NY Times