Blog - Free stuff)
Files and folders versionning software
Very often, we edit or replace (or delete!) a file while working. More often when the file is located on an external drive, shared by multiple users and when, sadly, two or more decide to work on the same file simultaneously.
So I've been looking around and trying a few solutions to this problem.
Subversion (SVN) is a good and reliable versionning software, but it requires a specific architecture to work, and http://sparko.ca is at a too early stage to use this solution. Everyone would have to work locally and then update/checkout/commit their work when done.
We decided to use AutoVer, a freeware Windows application developped by an australian guy. (http://beanland.net.au/AutoVer/)
The program is easy to install, we can set up as many folders as we want, filter what will be backuped, and decide what to do with older versions. We can also compare different versions together.
In our case, I set up the program to backup all our projects files (located on a network drive) and save the versions on an external drive.
Every single time a user presses "save" from any program (Notepad++, Photoshop, Office...), a before-save version of the file is created with the same path on the other drive. Thus, the file
E:\projects\project1\html\hello.php
is saved under
F:\projects\project1\html\hello.php.JJMMAAAAHHMMSS.php
So then, each time an individual (i.e. Joel) deletes by mistake a file, we can restore it immediately!
Image Email script, the spam solution!
Heres a useful trick if you dont want to receive spam in your email inbox when you display your email on a highly popular website.
Create an email.php page containing this script:
// Variables configuration
$emails[1] = "info@domain.com";
$emails[2] = "test@domain.com";
//$emails[n] = "anything@domain.com";
$pathToFont = "fonts/arial.ttf"; //System Font File
// Default variables
$maxWidth = 150;
$maxHeight = 16;
$paddding = 12;
$size = 10;
$background = "ffffff";
$color = "000000";
$emailAddress = "email@domain.com";
// Get variables
$maxWidth = (isset($_GET['width'])) ? (integer)$_GET['width']:$maxWidth;
$maxHeight = (isset($_GET['height'])) ? (integer)$_GET['height']:$maxHeight;
$paddding = (isset($_GET['padding'])) ? (integer)$_GET['padding']:$paddding;
$size = (isset($_GET['size'])) ? (integer)$_GET['size']:$size;
$background = (isset($_GET['background'])) ? ($_GET['background']):($background);
$color = (isset($_GET['color'])) ? ($_GET['color']):($color);
$emailAddress = (isset($emails[$_GET['email']])) ? ($emails[$_GET['email']]):$emailAddress;
// Color converter function
function hexToRGB($hex) {
$hex = str_replace("#", "", $hex);
$color = array();
if(strlen($hex) == 3) {
$color['r'] = hexdec(substr($hex, 0, 1) . $r);
$color['g'] = hexdec(substr($hex, 1, 1) . $g);
$color['b'] = hexdec(substr($hex, 2, 1) . $b);
}
else if(strlen($hex) == 6) {
$color['r'] = hexdec(substr($hex, 0, 2));
$color['g'] = hexdec(substr($hex, 2, 2));
$color['b'] = hexdec(substr($hex, 4, 2));
}
return $color;
}
// Create the image
$im = imagecreatetruecolor($maxWidth, $maxHeight);
$rgb = hexToRGB($background);
$backgroundColor = imagecolorallocate($im, $rgb["r"], $rgb["g"], $rgb["b"]);
$rgb = hexToRGB($color);
$fontColor = imagecolorallocate($im, $rgb["r"], $rgb["g"], $rgb["b"]);
// Add the background color
imagefilledrectangle($im, 0, 0, $maxWidth-1, $maxHeight-1, $backgroundColor);
imagecolortransparent($im, $backgroundColor);
// Size configuration
$coord = imagettfbbox ( $size ,0 , $pathToFont , "($emailAddress)" );
if($coord[2] > $maxWidth) $size = 9;
// Image Email creation
imagettftext ( $im, $size , 0 , 0 , $paddding , $fontColor, $pathToFont , $emailAddress );
// Display the image in the browser
header('Content-type: image/gif');
imagegif($im);
imagedestroy($im);
We use it like this:
email.php?email=1&color=F0F0F0&background=000000&width=220&height=16&padding=12
The variables are:
email: The email we want to display (declared in the script)
color: Font color
background: Background color
width: Image width
height: Image height
padding: Padding inside the image
Here's the final result of what it looks like:
NOTE: The GD2 library must be "enabled" in your PHP config.
Apache Error HTTPD: NoCase option for non-regex pattern is not supported and will be ignored.
An Apache error came to fill all our Apache error_logs. We (programmers) tend to use the [NC] flag in the .htaccess files that we create so that Apache doesn't consider the case when using RewriteCond.
The error is:
[warn] RewriteCond: NoCase option for non-regex pattern '-f' is not supported and will be ignored. [warn] RewriteCond: NoCase option for non-regex pattern '-d' is not supported and will be ignored.
So instead of using in .htaccess:
RewriteCond %{REQUEST_FILENAME} !-f [NC,OR]
RewriteCond %{REQUEST_FILENAME} !-d [NC]
prefer to use:
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !-d
Another (yet better!) solution is to use:
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule "." - [skip=100]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule "." - [skip=100]
.htaccess: URL without "www"
Some people say you shouldn't have two different URLs pointing to exactly the same place, without redirection.
However, it's an esthetic choice to show, or not, the "www" in front of the domain name. So, if you prefer not having the "www", use:
RewriteCond %{HTTP_HOST} ^www.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
If you rather prefer having the "www", use:
RewriteCond %{HTTP_HOST} !^www.(.*)$ [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
Note that your Apache server should have MOD_REWRITE enabled.
Categories
All articles, Design, E-Commerce, Free stuff, Internal, Mobile, Web Marketing,
Tags
htaccess, la presse, marketing, Montréal, rewriteCond, affaires, amazon, apache, apple, archambault, autoVer, back-up, backup, canada, commerce en ligne, Compétition, ebay, email, entreprises, fichiers,

1