Simple example how-to extend JavaScript built-in methods

Let say you want to replace all spaces in string by dashes,
of course you can implement distinct function that does it:



 function ReplaceByDashes(string){
    return string.replace(/\s/g,'-');
 }

 // run it
 var string = "Hello my beautiful world!";
 string=ReplaceByDashes(string);
 alert(string); 



However, we can add our custom method to string object that already built-in in JavaScript:



  if(typeof String.prototype.rbd==='undefined'){ // we have to check if someone hasn't added it already
     String.prototype.rbd = function(){
        return this.replace(/\s/g,'-');
     }
  }

 // run it

 var string = "Hello my beautiful world!";
 string=string.rbd();
 alert(string); 



Some useful example, capitalize first letter of string



String.prototype.ucFirst = function () {
  return (this.substr(0,1).toUpperCase() + this.substr(1,this.length));
}

Disable users list in login screen of Ubuntu 9.10

Run the following command in terminal:


sudo gconftool-2 --direct --config-source xml:readwrite:/etc/gconf/gconf.xml.mandatory --type Boolean --set /apps/gdm/simple-greeter/disable_user_list True

Wrong keyboard mapping in GNOME when working with VNC/XRDP

To fix the subj issue
add the following lines:


export XKL_XMODMAP_DISABLE=1
gconftool-2 -t bool --set /apps/gnome_settings_daemon/plugins/keyboard/active false


at the top of /etc/X11/Xsession

If you need any help with RDP on Linux, let me know

P.S Tested on Ubuntu 9.10

How to align window's control buttons in Ubuntu 10.4 to left


gconftool-2 --set "/apps/metacity/general/button_layout" --type string "menu:minimize,maximize,close"

print_r for Javascript


function print_r(theObj){
  if(theObj.constructor == Array ||
     theObj.constructor == Object){
    document.write("<ul>")
    for(var p in theObj){
      if(theObj[p].constructor == Array||
         theObj[p].constructor == Object){
document.write("<li>["+p+"] => "+typeof(theObj)+"</li>");
        document.write("<ul>")
        print_r(theObj[p]);
        document.write("</ul>")
      } else {
document.write("<li>["+p+"] => "+theObj[p]+"</li>");
      }
    }
    document.write("</ul>")
  }
}

Get current URL in PHP


<?php
function curPageURL() {
 $pageURL = 'http';
 if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
 $pageURL .= "://";
 if ($_SERVER["SERVER_PORT"] != "80") {
  $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
 } else {
  $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
 }
 return $pageURL;
}
?>


Test example:

<?php
  echo curPageURL();
?>


Source

After downgrade from Vista/win7 to WinXP you may see your HDD labeled as GPT

After downgrade from Vista/win7 to WinXP you may get your HDD inaccessible, if it's labeled as GPT
here is solution:

Start>Run>«cmd»>«diskpart»>«list disk»>«select disk x»>«clean»

Go back to disk management and you will then be able to format the hard drive and re-select NTFS partition

Backing up your mysql on linux box per each database


#!/bin/bash
MUSER="root"
MPASS="password"
MHOST="localhost"
MYSQL="$(which mysql)"
MYSQLDUMP="$(which mysqldump)"
BAK="/mnt/backupdir"
GZIP="$(which gzip)"
NOW=$(date +"%d_%m_%Y")
for i in `find $BAK -ctime +22`; do rm $i; done
[ ! -d $BAK ] && mkdir -p $BAK
DBS="$($MYSQL -u $MUSER -h $MHOST -p$MPASS -Bse 'show databases')"
for db in $DBS
do
 FILE=$BAK/$db.$NOW.gz
 $MYSQLDUMP -u $MUSER -h $MHOST -p$MPASS $db | $GZIP -9 > $FILE
done


it deletes every 22 days old backups if you want to change life-time,
you can change the value of ctime in the followed line: for i in `find $BAK -ctime +22`; do rm $i; done

How to Remove (Hide) Users list at login Screen in Ubuntu 9.10 (Karmic)


sudo -u gdm gconftool-2 --set --type boolean /apps/gdm/simple-greeter/disable_user_list true

Multiple tables deletion in Mysql using wildcards

I've found some solution on mysql website, how to delete multiple tables according to some condition, you will need it when you will want delete specific tables from your DB.



( Read more )