Thursday, March 24, 2011

Disable history back if pressing backspace

If you press backspace on the website page (but not on textbox) it will go to its previous page
This is to disable them

Taken from here, then I modified
http://www.sitepoint.com/forums/javascript-15/disable-back-javascript-168890.html

These is javascript coding
//DISABLE "GO BACK TO PREVIOUS HISTORY" IF PRESSING "BACKSPACE"
if (typeof window.event != 'undefined')
    document.onkeydown = function()
    {
        if( event.keyCode == 8){
            theEvent = event.srcElement.tagName.toUpperCase();
            if( theEvent == 'HTML'){
                return false;
            }
            else if( theEvent == 'INPUT'){
                theType = event.srcElement.getAttribute('type').toUpperCase();
                //alert(theType);
                switch(theType){
                    case 'TEXT':
                        return true;
                        break;

                   default:
                        return false;
                }
                return false;
            }
            else{
                switch( theEvent){
                    case 'TEXTAREA':
                        return true;
                        break;

                    default:
                        //alert('Backspace pressed on ' + theEvent + ', return false');
                        return false;
                }

                return false;
            }
        }
    }
else
    document.onkeypress = function(e)
    {
        if( e.keyCode == 8){
            theEvent = e.target.nodeName.toUpperCase();
            if( theEvent == 'HTML'){
                return false;
            }
            else if( theEvent == 'INPUT'){
                theType = e.target.getAttribute('type').toUpperCase();
                //alert(theType);
                switch(theType){
                    case 'TEXT':
                        return true;
                        break;

                   default:
                        return false;
                }
                return false;
            }
            else{
                switch( theEvent){
                    case 'TEXTAREA':
                        return true;
                        break;

                    default:
                        //alert('Backspace pressed on ' + theEvent + ', return false');
                        return false;
                }

                return false;
            }
        }
    }

Saturday, March 19, 2011

javascript detect and capture keyboard keycode

These is how to capture what user have type in their keyboard
The captured data is the "keycode" which is an integer

Like 'enter' key, the code is 13

Some data that I have discover and might be usefull to others and myself
These was tested and the same for IE, Firefox, Google Chrome and Safari
a until z keycode 97 until 122
A until Z keycode 65 until 90
0 until 9 keycode 48 until 57


Lets get to the code

function whatKeyCodeHaveIType( theEvent)
{
    charCode = (theEvent.which) ? theEvent.which : theEvent.keyCode

    theTempoElement = document.getElementById('thisiswhatyouhavetpye');
    theTempoElement.innerHTML = theTempoElement.innerHTML + ', ' + charCode;

    //This is to ignore "ENTER" key. Its usefull to prevent a form from autosubmit if you press enter
    return (charCode != 13);
}

//Later in HTML, use these
<input id="whatyouhavetype" style="width: 500px;" onkeypress="return whatKeyCodeHaveIType(event);"/>
<textarea id="thisiswhatyouhavetpye" cols="70" rows="5"></textarea>

Type something here :


javascript detect finish typing keystroke delay autocomplete

Okay, the title might be confusing but here is what these about

You want to execute certain function, right after the user has finish its typing

These is different from normal 'keypress' or 'keyup' or 'keydown' event detection because these will execute a function every key is press. Right now you want to give certain delay so that the function only execute at the right time

These is important if you developing an autocomplete (AJAX) because you dont want to execute the script too much. Typing "HELLO" means you do the SQL statement 5 times
H
HE
HEL
HELL
HELLO


But if you do a proper keystroke delay (detect user finish typing) you will only execute the SQL statement once
HELLO


Cut to the story, hopefully understand what I was trying to explain at the top

Here is the function
var typingTimer;
var doneTypingInterval = 700;

//Detect keystroke and only execute after the user has finish typing
function delayExecute()
{
    clearTimeout(typingTimer);
        typingTimer = setTimeout(
        function(){somethingExecuted('typesomethinghere')},
        doneTypingInterval
    );

    return true;
}

function somethingExecuted( theInputName)
{
    alert( "You have type '" + document.getElementById(theInputName).value + "'");
}

//Later in the HTML code, put these
<input onkeypress="return delayExecute();" id="typesomethinghere">

Type something here : (These input id is 'typesomethinghere')
The script will only execute after you finish typing. By assuming when you have stop typing for 0.7 seconds, means you have finish typing

Type something here :
These is what happen if you dont use the script



Tuesday, March 15, 2011

Ubuntu restore panel to default

Keyword
  • Accident delete top panel
  • Restore panel

Okay, I made a mistake like others always do "DELETE THE TOP PANEL!!"

To recover it back was quite easy, can find on google http://ubuntuforums.org/showthread.php?t=1475584
gconftool-2 --shutdown
rm -rf ~/.gconf/apps/panel
pkill gnome-panel
Hope this will help

Monday, March 14, 2011

Install LAMP on Ubuntu

These is a double posting, the original was from here http://asipi.blogspot.com/2009/10/haih.html

I write it back here because the title and here will be the latest updated place
(Yes I do update these post again if got any changes)


1

Install apache & mysql & phpmyadmin : http://www.howtoforge.com/ubuntu_lamp_for_newbies

*Update 23 Jan 2010
My Software source was from Malaysia and it has problem!. So it set my source to "Main Server" (Software source download from Main Server)


2

Enable the www folder
This will make your be able to add new folder into the localhost
using terminal :

sudo chmod -R 777 '/var/www'

Please note that /var/www is your root for the website
/var/www/smellynomore means http://localhost/smellynomore


3

You will realize that u cant open the phpmyadmin on http://localhost/phpmyadmin
This is because when you see inside /var/www there is no "phpmyadmin" folder

Solve it by referring here http://ubuntuforums.org/showthread.php?t=1036836

Solve by doing this in terminal :

sudo ln -s '/usr/share/phpmyadmin' '/var/www'



4

Additional configuration for the mysql

When you first time install the mySQL, everything is working fine.
But then, after you reboot the PC, the mySQL server cant start.

The mySQL configuration file will be missing after boot
After some haih...checking, you will realize that file inside "/var/run/mysqld" is missing

I solve it by this link, http://ubuntuforums.org/showthread.php?t=386056
Try to chown to "mysql.mysql" if owned by root, and give it a 755
It is because of the folder write permission

How to chown and chmod, please note that I dont know what happen to security issue when I done this, just want to 'make it work!'

sudo chown -R asipo '/var/run/mysqld'
sudo chmod -R 777 '/var/run/mysqld'




5

Load the mod_rewrite module
I google here to solve it http://ubuntuforums.org/showthread.php?t=255556&page=2

Using terminal :

sudo a2enmod rewrite
sudo gedit /etc/apache2/sites-enabled/000-default


After that change AllowOverride None to AllowOverride All

Then, restart Apache

sudo /etc/init.d/apache2 force-reload



6

Additional, command to mySQL server (check, start, restart and stop)
http://abbysays.wordpress.com/2008/05/20/how-to-startstop-mysql-server-on-ubuntu-804/

Setting up the cakePHP 1.2.5
There will be 2 problem
1. Warning (512): /var/www/cakemake/app/tmp/cache/ is not writable [CORE/cake/libs/cache/file.php, line 262]
2. Your tmp directory is NOT writable.

Solve by : Once again chmod 777 is not secure, yeah!

sudo chown -R asipo '/var/www/smellynomore/app/tmp'
sudo chmod -R 777 '/var/www/smellynomore/app/tmp'




7

Install x-debug
http://ubuntuforums.org/showthread.php?t=525257

EDITED #2 (Feb 2011)
I dont know why lately my xdebug does not working. So I edit the php.ini file
I make the all to be "Deleopment mode" because its defaulted to "Production mode"
So I guess that is the reson, plus use this on ERROR Report
error_reporting = E_ALL & ~E_DEPRECATED & ~E_NOTICE


8

After that, it will read index.html
I dont know how to change it for the thing to refer into index.php

However, this is the index.php code (simple version of mine)

<p><b>Localhost</b></p>
<p>Select folder or file to navigate</p>

<?php

echo "<ul>";
if ($handle = opendir('.')) {
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != "..") {
            echo "<li><a href='$file'>$file<a></li>";
        }
    }
    closedir($handle);
}
echo "</ul>";
?>
If you have been wandering how I put this code into this blog. This is the place http://asipi.blogspot.com/2011/01/write-blog-post-using-tinymce.html

Thus when you open your http://localhost/index.php will get something like this


9

phpMyAdmin login might be annoying, solve it from here http://asipi.blogspot.com/2011/02/disable-phpmyadmin-login.html


10 Edit 28 Nov 2012
To install CURL. I follow this website http://buzznol.blogspot.com/2008/12/install-curl-extension-for-php-in.html

Basically, in terminal type : sudo apt-get install curl libcurl3 libcurl3-dev php5-curl
Then restart the LAMP server, then test it using var_dump(curl_version()); make sure to put -pre- html tag around it

Note that to restart the server. Using this command seems to be even better. Feel like it was relly restarting... sudo /etc/init.d/apache2 restart

Thats all
good luck, kupo!