Tuesday, February 15, 2011

Remove item from array with jQuery

Remove item (number or string) from array, using jQuery (method grep).

arr = [1, 2, 3, 4, 5] // array initial
var removeItem = 2;   // item do array que deverá ser removido

arr = jQuery.grep(arr, function(value) {
        return value != removeItem;

// new array

Friday, December 31, 2010

How many Drupal sites are there in the world?

How do you find "all" the Drupal sites that Google knows about?
A post on drupal.org suggests Add New Comment, but that wont be entirely accurate. So far I have come up with a search that lists all sites with a User Account page on user/login:
intitle:"User account" inurl:"user/login"
Or you can use this link to search for drupal sites in Google.
I am aware this only lists sites with user login linked to somewhere and not blocked by Robots.txt.
I have also seen suggestions that looking for a CSS file might work, however with Drupal's CSS aggregation, this could be difficult.
Please share any alternatives, my search above (currently) shows around 2,620,000  (on Google UK). How can we make this better?

Wednesday, December 22, 2010

How to display sub menus (children) of primary links in drupal?

Step 1 : Since we'll be using php codes in a block to display menu, the first thing to do is to enable the PHP Filter under modules.
Step 2 : Go to administer->block->add block and create a new block. Add a description (i use submenu). Choose PHP Code as the filter and paste the code below in the body textarea.

$menuItems = menu_tree_page_data('primary-links'); 

foreach($menuItems as $key => $m) {
      //check current active menu
   if ($m['link']['in_active_trail'] && $menuItems [$key]['below']) {
       $menu = menu_tree_output($menuItems [$key]['below']);

//print the menu
print $menu;
Make sure you include the php delimiters in your code. Press save.
Step 3 : Place your block in a region you want. and that's it. next time you select a menu item in the primary links, the children menu items will show in this block.
You can use active-trail to style the selected menu item.

Alternatively, you may use Menu Block module which can do the same without writing a single line of code. Let me know if you need any guidence.

Sunday, November 21, 2010

25+ Must-Have Cheat Sheets for Web Developers

Who wants to go to Google or break out the library of programming books every single time you get stuck on something? Below is a compilation of extremely useful cheat sheets, which can be printed, laminated and placed nearby for easy reference while doing your web development and design. Everyone has moments where a function cannot be remembered, and that is where these cheat sheets can be lifesavers. Bookmark this page for an easy portal to all of the cheat sheets, or an individual page if you find it helpful. Please don’t hesitate to post any cheat sheets we neglected to include, for this is about sharing knowledge. 

With Courtesy: Chris Strosser.

1. PHP

PHP Cheat Sheet


2. MySQL

MySQL Cheat Sheet

3. JavaScript

JavaScript Cheat Sheet

4. CSS

CSS Cheat Sheet

5. Regular Expressions

Regular Expressions Cheat Sheet


6. Apache’s mod_rewrite

mod_rewrite Cheat Sheet

7. jQuery

jQuery Cheat Sheet


HTML Cheat Sheet

9. HTML Character Entities

HTML Entities Cheat Sheet

10. RGB Hex Color Codes

RGB Color Codes Cheat Sheet

11. .htaccess

.htaccess Cheat Sheet

12. Apache

Apache Cheat Sheet

13. SEO

SEO Cheat Sheet

14. Gmail

Gmail Cheat Sheet

15. HTML5

HTML5 Cheat Sheet

16. Google Analytics

Google Analytics Cheat Sheet

17. WordPress Cheat Sheets

WordPress Cheat Sheets

18. Subversion

Subversion Cheat Sheet

19. Eclipse

Eclipse Cheat Sheet

20. Google Search Engine

Google Cheat Sheet

21. Twitter

Twitter Cheat Sheet

22. CakePHP

CakePHP Cheat Sheet

23. Joomla

Joomla 1.5 Cheat Sheet

24. CodeIgniter

CodeIgniter Cheat Sheet

25. Drupal

Drupal Cheat Sheet

26. Firebug

Firebug Cheat Sheet