The development release of Chrome allow to install extension as for Firefox, but the process of installation (and even of creation as I heard from some developers) is faster.
Here it is my list:
function isValidEmail($email)
{
if(version_compare(PHP_VERSION, '5.2.0', '>=')
return filter_var($email, FILTER_VALIDATE_EMAIL);
else
return eregi('^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$', $email);
}
Regular expressions are a very powerful weapon for the developer if he can deals with all the pain of testing, debugging and learning the quirks of this matter.
I’m collecting some links to be red one day, when I’ll got time to dive more deeply in the argument:
I’ve asked Twitter user what kind of PHP class would have used for a project and I was (and I am) in doubt between MDB2 (a PEAR Abstraction layer class) and mysqli extension.
Someone has pointed out PDO, so I’m collecting some links to see what does this extension do:
Suppose you have an URL like this: www.host.com?m=5&lang=it. If you want to retrive the value of lang, you could simply use this function:
function parseURL(url,key)
{
var reQS = new RegExp("[?&]"+key+"=([^&$]*)", "i");
var offset = url.search(reQS);
return ( offset >= 0 ) ? RegExp.$1 : null;
}
// usage
var myKey = parseURL("www.host.com?m=5&lang=it","lang")
Via
blog.falafel.com
Self explanatory code:
var T = {
getUnixTime: function() {
return parseInt(new Date().getTime().toString().substring(0, 10));
},
// format hh:mm:ss
getTime: function()
{
var d= new Date();
var time = new Array();
var hours = d.getHours();
time.push(hours);
var minutes = d.getMinutes().toString().length < 2 ? "0"+d.getMinutes() : d.getMinutes();
time.push(minutes);
var seconds = d.getSeconds().toString().length < 2 ? "0"+d.getSeconds() : d.getSeconds();
time.push(seconds);
return time.join(":");
}
}
Update: I’ve just discovered that
Syntax Highlighter code doesn’t work well with < > symbols in javascript code….
The code is self explanatory: you have an array and you want to know what index has the element “pippo” or “5”. So I extended the array object with prototype keyword to scan the array and to return the index if found, -1 otherwise.
var points = [56,12,36];
Array.prototype.getIndex = function(aVal)
{
for(item in this)
if(aVal == this[item])
return item;
return -1;
}
console.log(points.getIndex(36));
If you have Firefox or Safari (maybe in IE8 too, I dunno), watch at the console and you’ll see2 as result.
ps -aylC geany |grep "geany" |awk '{print $8'} |sort -n |tail -n 1