Thursday 31 May 2012

How To Guide : Tata Docomo 3G on Ubuntu 11.10

It's pretty straight forward and follow below steps.
1. Connect your 3G stick and boot up Ubuntu.
2. Select network connections and click on the New Mobile Broadband Connection.
3. Now select continue in the dialog box and select India as country & then click continue.
4. Now it wil show list of service providers and DON'T select "Tata Docomo" as it's for Photon+ not for 3G. Instead select, I don't know my provider option and enter "TATA DOCOMO UMTS", click continue.
5. Under billing dialog, select "My plan is not listed" option and enter "tatadocomo3g" as APN, just click confirm and save your settings.
6.  Now under Network Connections, you could see "TATA DOCOMO UMTS connection" option and you can click on it. If it doesn't connetc to internet then just unplug & then re-plug you 3G stick.
That's it, you can use Tata Docomo 3G stick with your Ubuntu 11.10 :)

Monday 14 May 2012

How to Make Optionally Hidden Node Titles in Drupal (Using CCK)

To Make Optionally Hidden Node Titles in Drupal (Using CCK)
http://addoa.com/blog/how-make-optionally-hide-node-titles-drupal-using-cck

           -------------OR-------------
Now  to do this functionality  we have Drupal Module.
This module handles a very simple functionality, decide whatever to exclude a node title from full node page or node teasers.
http://drupal.org/project/exclude_node_title

Step By Step Instructions To Enable Clean URLs in Drupal

By default, Wamp Server doesn't support clean url feature of drupal cms.
To enable Clean URLs we need to manually edit the httpd.conf file of Apache server to support this feature.

1. Start WAMP Server. Click on the WAMP Server icon in the tray. Go to Apache -> httpd.conf as shown in the image below.
2. Find the following line in the httpd.conf file
   #LoadModule rewrite_module modules/mod_rewrite.so
3. Just remove the # symbol in the beginning of that line. Now it looks like in the below line.
    LoadModule rewrite_module modules/mod_rewrite.so
4. Now save the httpd.conf file and Restart your Wamp Server. Then open your browser and enable Clean URLs in your drupal cms.
   Enable Clean URLs From admin -> siteconfiguration.

sort an associative array by one of its keys

In case you need to sort an associative array by one of its keys, this function might be useful:

<?php
function sortByOneKey(array $array, $key, $asc = true) {
   
$result = array();
       
   
$values = array();
    foreach (
$array as $id => $value) {
       
$values[$id] = isset($value[$key]) ? $value[$key] : '';
    }
       
    if (
$asc) {
       
asort($values);
    }
    else {
       
arsort($values);
    }
       
    foreach (
$values as $key => $value) {
       
$result[$key] = $array[$key];
    }
       
    return
$result;
}

?>

Consider the following example:

<?php

$users
= array(
   
1 => array('name' => 'John', 'age' => 35),
   
2 => array('name' => 'Alice', 'age' => 23),
   
3 => array('name' => 'Bob', 'age' => 26)
);
       
$sortedByNameAsc = sortByOneKey($users, 'name');
$sortedByNameDesc = sortByOneKey($users, 'name', false);
       
echo
"Sorted by Name in ascending order: ";
echo
"<pre>" . print_r($sortedByNameAsc, true) . "</pre>";
echo
"<br /><br />Sorted by Name in descending order: ";
echo
"<pre>" . print_r($sortedByNameDesc, true) . "</pre>";

?>

The output will be the following:

Sorted by Name in ascending order:
Array
(
    [2] => Array
        (
            [name] => Alice
            [age] => 23
        )

    [3] => Array
        (
            [name] => Bob
            [age] => 26
        )

    [1] => Array
        (
            [name] => John
            [age] => 35
        )

)

Sorted by Name in descending order:
Array
(
    [1] => Array
        (
            [name] => John
            [age] => 35
        )

    [3] => Array
        (
            [name] => Bob
            [age] => 26
        )

    [2] => Array
        (
            [name] => Alice
            [age] => 23
        )

)