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

4 August 10

[JS] Fastest way for searching a monodimensional array?

var myAr = ['apple', 5, 6];
if(String('^' + myAr.join('^')).indexOf("^5") != -1)
  console.log("found!");
else
  console.log("not found :(");

Tags: javascript
Comments (View)
27 July 10

[JS] jQuery random number plugin

I’ve taken this little piece of code around the Web (sorry, I forgot the original source) and it’s a good example on how to develop a plugin for jQuery:

/** Usage:
* $.random(int);
* $.randomBetween(min, max); */
jQuery.extend({
	random: function(X) {
		return Math.floor(X * (Math.random() % 1));
	},
	randomBetween: function(MinV, MaxV) {
	  return MinV + jQuery.random(MaxV - MinV + 1);
	}
});

Comments (View)
1 June 10

fglrx patch arch_fglrx_2.6.34.patch fails

user@host:~$ sudo updatedb 
user@host:~$  locate arch_fglrx_2.6.34.patch 
/usr/src/fglrx-8.732/patches/arch_fglrx_2.6.34.patch
/var/lib/dkms/fglrx/8.732/build/patches/arch_fglrx_2.6.34.patch

# substitute first two lines of each file with these lines (without #)
# --- a/kcl_wait.c 2010-04-13 20:02:46.494496561 +0200
# +++ b/kcl_wait.c 2010-04-13 19:52:00.054563389 +0200 
user@host:~$ sudo vim /usr/src/fglrx-8.732/patches/arch_fglrx_2.6.34.patch
user@host:~$ sudo vim /var/lib/dkms/fglrx/8.732/build/patches/arch_fglrx_2.6.34.patch
user@host:~$ sudo apt-get --no-download install fglrx fglrx-amdcccle
Via: Ubuntu forums

Tags: ubuntu
Comments (View)
24 May 10

A view fro MySQL triggers

Here it is a small view to see all triggers stored in the DBMS. IMHO it’s more usable than going into INFORMATION_SCHEMA database and browse TRIGGERS records.

CREATE VIEW `List_triggers` AS
SELECT `TRIGGER_NAME` AS `Name`, `TRIGGER_SCHEMA` AS `Database`,
	   `EVENT_OBJECT_TABLE` AS `Table`,
	   CONCAT_WS(" ", ACTION_TIMING, EVENT_MANIPULATION) AS `Action`
FROM `INFORMATION_SCHEMA`.`TRIGGERS`

Comments (View)
20 May 10
When you’re without words…a facepalm says it all

When you’re without words…a facepalm says it all

Tags: lol
Comments (View)
14 May 10

How to restore Ubuntu gnome panel and menu items

As simple as:

gconftool-2 --shutdown
rm -rf ~/.gconf/apps/panel
pkill gnome-panel
If you want to restore, in example, Games menu from Applications, you have to:
cd ~/.config/menus
vim applications.menu
and then remove (in my case) Deleted node:
        <Menu>
                 <Name>Games</Name>
                 <Exclude>
                         <Filename>mahjongg.desktop</Filename>
                 </Exclude>
                 <AppDir>/home/chris/.local/share/applications</AppDir>
                <!-- remove this node </Deleted> -->
         </Menu>
Via Ubuntu forums here and here.

Tags: ubuntu gnome
Comments (View)
7 May 10

Chosing java-6-sun instead of OpenJDK on Ubuntu

I was disappointed when I figured out that Vuze didn’t work anymore after having upgraded to Lucid Lynx. So I launched the program in the shell and I discovered it couldn’t find some Swing stuff for creating the GUI. Back to Java Sun 6, so:

chris@sirio:~$ sudo update-java-alternatives -l
java-6-openjdk 1061 /usr/lib/jvm/java-6-openjdk
java-6-sun 63 /usr/lib/jvm/java-6-sun
chris@sirio:~$ sudo update-java-alternatives -s java-6-sun

Comments (View)
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)
Themed by Hunson. Originally by Josh