Tuesday, September 20, 2011

MySQL - How to reset the MySQL root password?

If you forget the MySQL root password and are locked out of the system, don't panic - there's still hope! All you need to do is follow the simple steps outlined in the following:


  1. Shut down MySQL, and then restart it.When restarting MySQL, add the following two options to the mysql_safe command line:

    $ /usr/local/mysql/bin/mysqld_safe --skip-grant-tables --skip-networking &

  2. Log in to the MySQL server as root using the MySQL client. Because MySQL was started without the grant tables, you can use an empty password to gain access.$ /usr/local/bin/mysql -u root

  3. Once logged in, set a new password for the root account by directly modifying the grant tables as follows:

    mysql > UPDATE mysql.user SET Password=PASSWORD('new-password') WHERE User='root';
    Query OK, 1 row affected (0.06 sec)

  4. Log out of MySQL, and then shut down and restart the server in the normal manner. You should now be able to log in as root user, with the new password you set in Step 3.
Hope this post helps.

Wednesday, August 31, 2011

JavaScript - How to display array values without knowing the array size?

There are times that we don't know the exact length or size of an array and we want to display it using any loop statements but to do this we need to know the exact length of the array.

So this snippet will make it possible for you to display even if you have no idea on the length and size of your array using the length() method of an array.

<script type="text/javascript">
  var animals = ("dog","cat","elephant","snake");

  for (var i=0;i<animals.length;i++) {
    document.write(animals[i] + "<br />");
  }
</script>

Good luck and Enjoy coding.

Wednesday, August 10, 2011

Windows - How to password protect Microsoft Word file?

You ever wanted to password protect your documents due to its private contents? Well, this post is for you. This will show you how to password protect your Microsoft Office Documents like Word, Excel, and Powerpoint.

To do this, follow the instructions below:
  1. Create your file/document. If your file already exist, open it and add anything that you want to add in the document.
  2. When you are ready to save, click on [File] and choose [Save As].
  3. A new window will pop-out. Enter your desired file name. On the lower left of the pop-out window, there is a button that named [Tools], click that. A drop down menu will come out and select [General Options].
  4. After clicking the [General Options] menu, a new window will come out asking for your password to open and password to modify the document. If you wish to put a password to open the file, put your desired password in the [Password to open] textbox. Likewise, if you want to put a password before someone could edit the file, key in your desired password for modification in the [Password to modify] textbox. After you decided on all this, click on [OK] button and you are DONE!.


Follow the same process in working with your Excel and Powerpoint files. I hope this guide helped in any way. Enjoy and have fun.

Thursday, August 4, 2011

Windows - How to shutdown computer using command line or batch file?

There are times that we want to insert codes in our program to automatically do things in a different instance other than your running program. For example, we want to insert batch file in our program to automatically shutdown a workstation. To do this here is the simple code.

  1. Run a simple editor like notepad.
  2. To create our batch file, write down the following code below:
    @echo off
    %windir%\system32\shutdown.exe -s -f -t 20

    LEGEND:
    -s = shutdown
    -f = force close any running application
    -t = timer
    20 = no. of seconds left before the system shutdown

  3. Save your work as a ".bat" file.
  4. Done.
You can now call on a batch file to shutdown your computer. However, in Windows 2000, there is a slight difference in making this happen. See the instructions below.

  1. Run a simple editor like notepad.
  2. To create our batch file, write down the following code below:

    @echo off
    shutdown /l /t:2 /y /c

    LEGEND:
    /l (Note that this is a lowercase "L" character) = Use this switch to shut down the local computer
    /t:xx = Use this switch to specify the time (in seconds) after which the computer is shut down. The default is 20 seconds.
    /y = Use this switch to force a "yes" answer to all queries from the computer.
    /c = Use this switch quit all running programs. If you use this switch, Windows forces all programs that are running to quit. The option to save any data that may have changed is ignored. This can result in data loss in any programs for which data is not previously saved.

  3. Save your work as a ".bat" file.
  4. Done.

NOTE: This will only work on Windows 2000 with System Resource Kit that comes with its installation CD. BUT, I have managed to find the exact tool in the Windows 2000 Resource Kit to let us shutdown our Windows 2000 running computer. Download it here. After downloading the file, extract it and put the shutdown.exe in "C:\WINNT\system32\" folder. Your batch file should be working after that.

Enjoy the snippet and have fun.

Continue coding.

Tuesday, August 2, 2011

Windows - Auto Log on

You ever wonder how to log on automatically in a computer that has multiple user accounts and only use specific ones? Well, this article might be helpful for you.

In this article, we will tackle on how to make windows log on automatically without entering your credentials like username and your password. We can do this by tweaking the registry, but we must be very careful about it. Registry is where all the magic happens in a windows platform so we must take good care of it. Back up before doing something with your registry.

We will be using our registry editor to add our log on information. To do this, follow these steps.
  1. Click "Start" then click "Run", type in "regedit" and then press "OK" button or press "ENTER". After pressing "ENTER" a new window will come out - the registry editor.

  2. In the registry editor, locate the following registry key:

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon

  3. Using your desired account name and password, double-click the "DefaultUserName" entry, type your user name, and then click "OK".

  4. Double-click the "DefaultPassword" entry, type your password under the value data box, and then click "OK".

  5. If there is no "DefaultPassword" value, create the value. To do this, follow these steps:
    • In Registry Editor, click "Edit", click "New", and then click "String Value".
    • Type "DefaultPassword" as the value name, and then press "ENTER".
    • Double-click the newly created key, and then type your password in the Value Data box.

    Note: If the DefaultPassword registry entry does not exist, Windows XP automatically changes the value of the AutoAdminLogonregistry key from 1 (true) to 0 (false) to turn off the AutoAdminLogon feature after the computer is restarted.

  6. Double-click the "AutoAdminLogon" entry, type 1 in the Value Data box, and then click "OK."

  7. If there is no "AutoAdminLogon" entry, create the entry. To do this, follow these steps:
    • In Registry Editor, click "Edit", click "New", and then click "String Value".
    • Type "AutoAdminLogon" as the value name, and then press "ENTER".
    • Double-click the newly created key, and then type 1 in the Value Data box.

  8. Exit Registry Editor.

  9. Restart your computer and see the magic.

Enjoy the tweak and remember to back-up everything before doing anything.