RSS | Archive | Random | E-mail

About

Hi, I'm Christian Castelli, a 28 years old italian programmer located in Pisa (Italy). Here I post small snippets of code which can be useful in my work.

Links

Codepuzzling main site
Development site
ByteStrike italian blog
Follow me on Twitter

My Life Style

while(passion) {
  try {
    myLife.run();
  }catch(LifeExceptions) {  
    stronger++;
    continue;
   }
}

Following

14 January 10

[Browser] My favourite Chrome extensions

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:

Comments (View)
7 January 10

[PHP] Email validation considering PHP version

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);
}

Comments (View)
17 November 09

[Links] Online services and tools for regex testing

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:

Comments (View)
Posted: 12:07 PM
placidiappunti:


caturday:

LCD (Lot of Cats Display)

placidiappunti:

caturday:

LCD (Lot of Cats Display)

Reblogged: placidiappunti

Comments (View)
21 October 09

[PHP] Resources for programming with PDO

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:

Comments (View)
5 October 09

[JS] How to get a querystring value given the key

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

Comments (View)
Posted: 4:54 PM

Reblogged: placidiappunti

Comments (View)
22 September 09

[JS] How to get the time and unixtime

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….

Comments (View)
Posted: 10:15 AM

[JS] How to extend Array object to get the index of an its value

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.

Comments (View)
17 September 09

[Bash] How much memory consume a process

ps -aylC geany |grep "geany" |awk '{print $8'} |sort -n |tail -n 1

Tags: bash memory awk
Comments (View)
Themed by Hunson. Originally by Josh