Saturday, July 28, 2012

Array Unique in Jquery

Here is the code to remove the duplicates from an array in Jquery.

in below code countries is an array which contains all the elements.

var unique_countries = countries.filter(function(itm,i,countries){return i == countries.indexOf(itm);});

Array Difference in Jquery

Hi

Here is the snippet to find the difference between the two arrays in JQUERY.

var array1 = ["test1", "test2","test3", "test4"];
var array2 = ["test1", "test2","test3","test4", "test5", "test6"];

var _array = new Array();

_array = jQuery.grep(array2, function (item) {
     return jQuery.inArray(item, array1) < 0;
});

Friday, March 30, 2012

Cisco VPN in Ubuntu

Hi

Here is the command to install Cisco VPN type in Ubuntu.

# sudo apt-get install network-manager-vpnc

For Detailed Procedure please see the below link:

http://www.ubuntugeek.com/how-to-install-cisco-vpn-client-on-ubuntu-11-10.html

Thursday, March 1, 2012

Create VirtualHost in Ubuntu

Hi All

Here is the Procedure to Create the VirtualHost in Ubuntu.

1. Create the folders that will host your new site. By default, Apache in Ubuntu serves from /var/www. So create this:

mkdir /var/www/site1

2.Copy the current default setting found in /etc/apache2/sites-available/default and name it the same as your new site.

cp /etc/apache2/sites-available/default /etc/apache2/sites-available/site1

3. Edit the new config files for each site using your preferred text editor. Add the line ServerName server1 right below the ServerAdmin line and change both DocumentRoot and Directory to point to your new site.
File:/etc/apache2/sites-available/site1

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName site1

    DocumentRoot /var/www/site1
    <Directory />
        Options FollowSymLinks
        AllowOverride All
    </Directory>
    <Directory /var/www/site1/>
        Options -Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

4. After you have edited the config file, just tell Apache to start serving the new domains

sudo a2ensite site1


5. Add the entry in your hosts file for new site.

file: /etc/hosts
127.0.0.1       site1

6. Now reload apache and you should be able to get new domain:

sudo /etc/init.d/apache2 reload

check the URL:- http://site1.


Note:-
If you have the .htacess files in your project and if you face any problems like NotFound and Internal Server Error Make sure rewrite Module available in "/etc/apache2/mods-enabled" if not please create the Symlink to the rewrite module, here is the code.

ln -s ../mods-available/rewrite.load rewrite.load


Thursday, January 12, 2012

Placing the Contents of a Block in any Location

If you want to embed the contents of a block into a node, a custom block, or a page template, you can use the following snippets.

D6 and earlier:

$block = module_invoke('module_name', 'block', 'view', 'block_delta');
print $block['content'];

D7:

$block = module_invoke('module_name', 'block_view', 'block_delta');
print render($block);

To specify which block from which module, you simply edit the two following variables in the first line:

'module_name' = The machine name of the module (i.e. the module's folder name). This is true for core modules too, so for instance 'search', 'user' and 'comment' would all work here.

'block_delta' = The machine name of the block. You can determine what this is by visiting the block administration page and editing the block.
The URL for editing a webform block, for instance, would be something like:

Drupal 6: admin/build/block/configure/webform/client-block-11
Drupal 7: admin/structure/block/manage/webform/client-block-11/configure

In this example, 'client-block-11' is the block's delta.

Custom blocks will have module name of 'block' and a number for a delta, which you can also find by editing the block.

For More Information Please Click Here

Wednesday, December 28, 2011

SQL Queries

Create A Table with Constrains

CREATE TABLE IF NOT EXISTS `publisher_media_types` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `publisher_id` int(11) NOT NULL,
  `media_type_id` int(11) NOT NULL,
  `created` datetime NOT NULL,
  `modified` datetime NOT NULL,
  `created_by` int(11) NOT NULL,
  `modified_by` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_publisher_media_types_publisher_id` (`publisher_id`),
  KEY `fk_publisher_media_type_id` (`media_type_id`),
  KEY `fk_publisher_media_types_created_by` (`created_by`),
  KEY `fk_publisher_media_types_modified_by` (`modified_by`),
  CONSTRAINT `fk_publisher_media_types_publisher_id` FOREIGN KEY (`publisher_id`)
  REFERENCES `publishers` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `fk_publisher_media_type_id` FOREIGN KEY (`media_type_id`)
  REFERENCES `media_types` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `fk_publisher_media_types_created_by` FOREIGN KEY (`created_by`)
  REFERENCES `logins` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `fk_publisher_media_types_modified_by` FOREIGN KEY (`modified_by`)
  REFERENCES `logins` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;


To Remove the Constrain

ALTER TABLE `publisher_media_types` DROP FOREIGN KEY `fk_publisher_media_type_id`;
ALTER TABLE `publisher_media_types` DROP INDEX `fk_publisher_media_type_id`;


To Add the Index

ALTER TABLE `publisher_media_types` ADD KEY `fk_publisher_media_type_id` (`media_type_id`);
ALTER TABLE `publisher_media_types` ADD
CONSTRAINT `fk_publisher_media_type_id` FOREIGN KEY (`media_type_id`)
REFERENCES `media_types` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

Thursday, December 15, 2011

Commands in Ubuntu

Here are the list of commands to install the additional packages in Ubuntu.

For CURL
sudo apt-get install php5-curl

For Chrome Browser
sudo apt-get install chromium-browser