Monday, October 17, 2011

Determining if a Checkbox is Checked Using jQuery

A checkbox can be checked initially by using

<input type="checkbox" id="yourCheckBox" name="yourCheckBox" checked="checked" />

or

$("#yourCheckBox").attr('checked', true);


When one of the code above is used, the following two lines of code can fail in retrieving the correct value of the checkbox:

$('#yourCheckBox').attr("checked")

and

$('#yourCheckBox').val()


A better way is to use the following jQuery code instead:

$('#yourCheckBox').is(":checked")

My office mate and I took almost an hour to figure out that bug in our project code.

Saturday, October 8, 2011

Using and Creating a MySQL Dump

To use a database dump:
mysql -u <username> -p  <database_schema> < schema_dump.sql

To create a dump for the whole database:
mysqldump -u <username> -p  <database_schema> > schema_dump.sql

To create a dump of only a specific table of the database:
mysqldump -u <username> -p <database_schema> <table_name> > table_dump.sql

To create a compressed dump all of the databases on your MySQL:
mysqldump --all-databases -p | bzip2 -c > databasebackup.sql.bz2

Just make sure to enter the correct values on the parts enclosed between < and >.

Redirect to Login Page in Wordpress

Using PHP, you can use the following code to redirect a user to the log-in page before being able to access a page. It will go to the page the user is trying to access once he is logged-in.

<?php auth_redirect() ?>

Some say it doesn't work right for logged-in users.
Better add a checking just to make sure it works all the time:

<?php
  if ( !is_user_logged_in() ) {
    auth_redirect();
  }
?>

Refresh Web Page in JavaScript

Here's a very simple code:

window.location.reload(true);

So simple that you might not even care & easily forget about its syntax... that's why it's here. :)

List Recent Posts on Drupal 7 Using PHP

There's already a version 8 of Drupal but still, it's not easy to look for documentations of Drupal 7. They have a lot of methods from version 6 that I have to translate from my old code lately.

It almost frustrated me until I came up with the following code that works:

<?php
$query = db_select('node', 'n');

$nids = $query
    ->fields('n', array('nid'))
    ->orderBy('created', 'DESC')
    ->range(0, 7)
    ->execute()
    ->fetchCol('title');

$nodes = node_load_multiple($nids);
echo '<ul class="menu">';

foreach ($nodes as $recentNode) {
echo '<li class="first"><a href="?q='.drupal_lookup_path('alias',"node/".$recentNode->nid).'">'.$recentNode->title.'</a></li>';
}

echo '</ul>';

?>

Friday, May 6, 2011

Stop Enter Keyring Password Dialog on Ubuntu Start-Up

Problem
The prompt can be annoying when you see the Enter Keyring Password Dialog everytime you login om your computer. It usually happens when you just changed your Ubuntu user account password and your computer tries to connect to a new wireless Internet connection.

It says:
An application wants access to the keyring 'Default', but it is locked. 
Enter password for keyring 'Default' to unlock

Solution
1. Right click your mouse at the Network Connection applet at the task bar.
2. Choose Edit Connections...
3. On the Wireless tab, click your connection and click the Edit button.
4. A dialog will appear and check the Available to all users at the lower left.
5. Click Apply... and enter your password when prompted to.

Problem solved! :)

Wednesday, March 2, 2011

Apply Changes on .bashrc

There are times when changes to the .bashrc file does not take effect automatically.
To make sure all changes are applied, run the following command on your terminal:

source ~./bashrc

Monday, February 28, 2011

Don't Show Dashboard of SpringSource Tool Suite on Startup

The SringSource Tool Suite's Dashboard can sometimes be annoying as it appears everytime you open the application. To remove it,

  1. Choose Window | Preferences.
  2. Click Spring | Dashboard.
  3. Uncheck Show Dashboard On Startup.
Done.

SpringSource Tool Suite Dashboard