Wednesday 28 December 2011

5 tips running drupal 7 site rackspace cloud sites


#1 - Increase the PHP memory limit

In your Drupal .htaccess file add a line at the top of the file that says:
php_value memory_limit 128M
Rackspace Cloud Sites default memory limit is 32MB which is the minimum recommended amount for a Drupal 7 site, but way too small for a full featured Drupal 7 site. My opinion is that 128MB is the minimum and sometimes 256MB is necessary on a large site with many modules.
If I don’t increase the memory limit, I’ll usually get an error on most sites the first time I try to run update.php after updating some contrib modules.

#2 - Uncomment “RewriteBase /”

For clean URLs to work on Drupal in Rackspace Cloud Sites, you must uncomment the line in your .htaccess files that says “RewriteBase /”. Without this line, Drupal won’t give you the option of turning on clean URLs during installation.
For Beginners: uncommenting in the .htacces file simply means deleting the “#” character at the beginning of the line.

#3 - Disable the Overlay Module

This is really just a general tip for Drupal 7. The overlay Module, while cool, definitely slows down the admin side of a site. If you can live without the niceness, it will make building and managing the site much quicker.

#4 - Write Shell Scripts for Repetitive Tasks

One of the biggest negatives of Rackspace Cloud Sites is the lack of shell access. The best alternative we’ve found for repetitive tasks is to write shell scripts, then set up a cron job to run the script. A couple of examples of shell scripts we use are zipping and unzipping archives, dumping and restoring databases, and mirroring a live site back to a development site if they are in the same Cloud Sites account.

#5 - Turn on Caching

This tip really goes for any production site, but especially in Rackspace Cloud Sites. A Drupal site without caching on can seem slow in this hosting environment, but once caching is on, it’s much faster. If you are using Cloud Sites as a development environment, then leave caching off or you’ll pull your hair out wondering why your site changes are showing up. But once the site is live, turn it on.
The cache settings in Drupal 7 are found at: /admin/config/development/performance
Check the boxes next to:
  • Cache pages for anonymous users.
  • Aggregate and compress CSS files.
  • Aggregate JavaScript files.
And select the options:
  • Production (minified)
  • Google
Also, remember that Rackspace Cloud Sites charges based on “compute cycles,” so turning on cache will help keep costs down once the site is live.
Try these tips with your Drupal 7 site on Rackspace Cloud Sites and we guarantee your experience will be much improved. Also check out these other helpful articles we’ve written about Drupal.

A trick to find unused PHP files (Drupal template files)


Drupal registers every single theme implementation, including template files, in the theme registry. You could create a custom module and implement hook_theme_registry_alter() to inspect the theme registry to find what templates are being used by your theme. From there, you could compare your theme folder with the list you generated.
Example implementation:
function mymodule_theme_registry_alter(&$theme_registry) {
  global $theme_path;

  $templates_used = array();

  foreach ($theme_registry as $theme) {
    if (!empty($theme['template']) && $theme['path'] === $theme_path) {
      $templates_used[] = $theme['template'] . '.tpl.php';
    }
  }

  // Display the list (requires Devel module)
  dsm($templates_used);
}

Tuesday 20 December 2011

Play With Google Gravity

just search "google gravity" on the google
u shuld found a result
http://mrdoob.com/projects/chromeexperiments/google_gravity/

Root HTC Amaze 4G On Android 2.3.4 Gingerbread Permanently With ‘One Click Root’


Good news, folks! The critically acclaimed HTC Amaze 4G can now be rooted! If you’ve got one and want to be able to install root-only apps like Titanium Backup, then follow our guide after the jump!

The root tool comes from developer xboarder56 over on popular forum for Android hacking / development XDA-Developers.
From XDA:
Hi,
guys this is a One Click Perm Root tool and its verified working. Even after reboot no more bricks like the old one Crack eyes made. It will root your phone and it will stay rooted after multipule (sic) reboots. Enjoy.
How To Root HTC Amaze 4G With One Click Permanent Root Tool
DISCLAIMER: Redmond Pie is not to be held responsible for any loss of data as a result of the malfunctioning of your HTC Amaze 4G in the following of this guide. Follow at your own risk.
Note: This root will be permanent or temporary based on the state of your bootloader. If it is locked, the root will be temporary and you will have to re-root every time you restart your device. However, if it has been unlocked, root will be permanent. You can follow this guide on XDA to unlock your bootloader.
Alright, so before we get down to it, we suggest you download these files beforehand so that the actual rooting process can be done quickly.
Although the process shouldn’t take more than 5 minutes to complete, be sure to ensure that your HTC Amaze 4G has enough charge to last through the rooting process. If your device runs out of battery during rooting, there is a chance that you might brick it.
Step 1: Install HTC Drivers on your computer so that One Click Perm Root can detect your HTC Amaze 4G properly.
Step 2: Connect your device to your computer through USB.
Step 3: Enable USB Debugging on your HTC Amaze 4G from Settings > Applications > Development.
Step 4: Extract Zerg_Root_OneClick.zip (which you downloaded before Step 1) to C:\ and launch ZergRushTempRoot.bat
Step 5: Your HTC Amaze 4G will now be rooted. The process will take up to 3 minutes.
Step 6: Reboot your device.

If you need help or have any queries, visit the official threadGood news, folks! The critically acclaimed HTC Amaze 4G can now be rooted! If you’ve got one and want to be able to install root-only apps like Titanium Backup, then follow our guide after the jump!




The root tool comes from developer xboarder56 over on popular forum for Android hacking / development XDA-Developers.

From XDA:

Hi,

guys this is a One Click Perm Root tool and its verified working. Even after reboot no more bricks like the old one Crack eyes made. It will root your phone and it will stay rooted after multipule (sic) reboots. Enjoy.

How To Root HTC Amaze 4G With One Click Permanent Root Tool

DISCLAIMER: Redmond Pie is not to be held responsible for any loss of data as a result of the malfunctioning of your HTC Amaze 4G in the following of this guide. Follow at your own risk.

Note: This root will be permanent or temporary based on the state of your bootloader. If it is locked, the root will be temporary and you will have to re-root every time you restart your device. However, if it has been unlocked, root will be permanent. You can follow this guide on XDA to unlock your bootloader.

Alright, so before we get down to it, we suggest you download these files beforehand so that the actual rooting process can be done quickly.

HTC Drivers [MultiUpload Link]
One Click Permanent Root tool [MultiUpload Link]
Although the process shouldn’t take more than 5 minutes to complete, be sure to ensure that your HTC Amaze 4G has enough charge to last through the rooting process. If your device runs out of battery during rooting, there is a chance that you might brick it.

Step 1: Install HTC Drivers on your computer so that One Click Perm Root can detect your HTC Amaze 4G properly.

Step 2: Connect your device to your computer through USB.

Step 3: Enable USB Debugging on your HTC Amaze 4G from Settings > Applications > Development.

Step 4: Extract Zerg_Root_OneClick.zip (which you downloaded before Step 1) to C:\ and launch ZergRushTempRoot.bat

Step 5: Your HTC Amaze 4G will now be rooted. The process will take up to 3 minutes.

Step 6: Reboot your device.



If you need help or have any queries, visit the official thread on XDA-Developers. on XDA-Developers.Good news, folks! The critically acclaimed HTC Amaze 4G can now be rooted! If you’ve got one and want to be able to install root-only apps like Titanium Backup, then follow our guide after the jump!






The root tool comes from developer xboarder56 over on popular forum for Android hacking / development XDA-Developers.


From XDA:


Hi,


guys this is a One Click Perm Root tool and its verified working. Even after reboot no more bricks like the old one Crack eyes made. It will root your phone and it will stay rooted after multipule (sic) reboots. Enjoy.


How To Root HTC Amaze 4G With One Click Permanent Root Tool


DISCLAIMER: Redmond Pie is not to be held responsible for any loss of data as a result of the malfunctioning of your HTC Amaze 4G in the following of this guide. Follow at your own risk.


Note: This root will be permanent or temporary based on the state of your bootloader. If it is locked, the root will be temporary and you will have to re-root every time you restart your device. However, if it has been unlocked, root will be permanent. You can follow this guide on XDA to unlock your bootloader.


Alright, so before we get down to it, we suggest you download these files beforehand so that the actual rooting process can be done quickly.


HTC Drivers [MultiUpload Link]
One Click Permanent Root tool [MultiUpload Link]
Although the process shouldn’t take more than 5 minutes to complete, be sure to ensure that your HTC Amaze 4G has enough charge to last through the rooting process. If your device runs out of battery during rooting, there is a chance that you might brick it.


Step 1: Install HTC Drivers on your computer so that One Click Perm Root can detect your HTC Amaze 4G properly.


Step 2: Connect your device to your computer through USB.


Step 3: Enable USB Debugging on your HTC Amaze 4G from Settings > Applications > Development.


Step 4: Extract Zerg_Root_OneClick.zip (which you downloaded before Step 1) to C:\ and launch ZergRushTempRoot.bat


Step 5: Your HTC Amaze 4G will now be rooted. The process will take up to 3 minutes.


Step 6: Reboot your device.






If you need help or have any queries, visit the official thread on XDA-Developers.

How To Root T-Mobile Samsung Galaxy S II On Android 2.3.5


Great news, folks! All variants of the Samsung Galaxy S II on US wireless carriers AT&T, Sprint and T-Mobile are now root-able. We’ve already covered how to root the Epic 4G Touch, and today we’ll go through the method with which you can root T-Mobile’s Galaxy S II variant.
20111020161559123
The root method comes from Rootzwiki – a popular forum for Android hacking/development – in a post from developer slayher where he goes through the different modalities of the whole procedure.
How To Root T-Mobile Galaxy S II On Android 2.3.5 Gingerbread
DISCLAIMER: Redmond Pie isGreat news, folks! All variants of the Samsung Galaxy S II on US wireless carriers AT&T, Sprint and T-Mobile are now root-able. We’ve already covered how to root the Epic 4G Touch, and today we’ll go through the method with which you can root T-Mobile’s Galaxy S II variant.






The root method comes from Rootzwiki – a popular forum for Android hacking/development – in a post from developer slayher where he goes through the different modalities of the whole procedure.


How To Root T-Mobile Galaxy S II On Android 2.3.5 Gingerbread


DISCLAIMER: Redmond Pie is not to be held responsible for any loss of data as a result of the malfunctioning of your Samsung Galaxy S II for T-Mobile.


Download the following files first:


Samsung Kies [Official Website]
ODIN v1.85 [XDA Thread]
ClockworkMod Recovery for T-Mobile Galaxy S II [Direct Link]
Superuser zip file [Goo-Inside Page]
Step 1: Install Samsung Kies on your T-Mobile Galaxy S II. This is to ensure that ODIN can detect your phone with correct drivers in the next step.


Step 2: Launch ODIN v1.85.


Step 3: Turn off your phone, hold Volume Up + Volume Down and plug in your device to a computer via USB cable.


Step 4: Once your device is recognized, select the PDA button from ODIN and navigate to recovery-cwm-hercules.tar. Click on Start. recovery-cwm-hercules.tar will now be flashed to your phone and it will reboot.


Step 5: After rebooting, pull down notification drawer and mount USB storage by tapping connect USB storage.


Step 6: Transfer the su-3.0.5-efgh-signed.zip you downloaded before Step 1 to your SD card.


Step 7: Turn off your phone once again and unplug USB cable. Hold Volume Up + Volume Down and click the Power button.


Step 8: You should boot into ClockworkMod (CWM) Recovery. From here, navigate to backup and storage > backup to take a nandroid backup of your device which may be used in case anything goes wrong. 


Step 9: From CWM, navigate to install zip from sd card > choose zip from sdcard > su-3.0.5-efgh-signed.zip


Step 10: Reboot your phone by choosing reboot system option from main menu.


If you followed the steps correctly, your T-Mobile Galaxy S II should now be rooted on Android 2.3.5 Gingerbread not to be held responsible for any loss of data as a result of the malfunctioning of your Samsung Galaxy S II for T-Mobile.
Download the following files first:
Step 1: Install Samsung Kies on your T-Mobile Galaxy S II. This is to ensure that ODIN can detect your phone with correct drivers in the next step.
Step 2: Launch ODIN v1.85.
Step 3: Turn off your phone, hold Volume Up + Volume Down and plug in your device to a computer via USB cable.
Step 4: Once your device is recognized, select the PDA button from ODIN and navigate torecovery-cwm-hercules.tar. Click on Start. recovery-cwm-hercules.tar will now be flashed to your phone and it will reboot.
Step 5: After rebooting, pull down notification drawer and mount USB storage by tappingconnect USB storage.
Step 6: Transfer the su-3.0.5-efgh-signed.zip you downloaded before Step 1 to your SD card.
Step 7: Turn off your phone once again and unplug USB cable. Hold Volume Up + Volume Down and click the Power button.
Step 8: You should boot into ClockworkMod (CWM) Recovery. From here, navigate to backup and storage > backup to take a nandroid backup of your device which may be used in case anything goes wrong. 
Step 9: From CWM, navigate to install zip from sd card > choose zip from sdcard > su-3.0.5-efgh-signed.zip
Step 10: Reboot your phone by choosing reboot system option from main menu.
If you followed the steps correctly, your T-Mobile Galaxy S II should now be rooted on Android 2.3.5 Gingerbread

Root Samsung GALAXY Note On Android 2.3.5 Gingerbread


No sooner does Samsung release its smartphone-cum-tablet Galaxy Note does it become root-able. With a 5-inch, 1280×800 screen with Super AMOLED HD Plus display, it certainly makes abig first first impression, and is a unique entry to the fiercely competitive mobile devices market.
samsung-galaxy-note-lead
Courtesy of the guys over at AndroidNZ, those owning the large yet small device can root it – and we’ve enclosed a simple tutorial to help you en-root.
How To Root Samsung Galaxy Note On Android 2.3.5 Gingerbread
PLEASE NOTE: Redmond Pie will not be held responsible for any loss of data as a result of the malfunctioning of your Samsung Galaxy Note. Follow instructions at your own risk! There’s currently no way to reset the flash counter, so by continuing, you agree to kiss any warranty goodbye.
With the formalities behind us, you’ll need assemble the necessary files:
Step 1: Install Samsung Kies on your PC (download link above) for your Samsung Galaxy Note, which will ensure that ODIN is able to detect your device.
Step 2: Launch ODIN v1.85.
Step 3: Switch your device off, hold Volume Up and Volume Down to place your device intoDownload Mode and plug in your device to your computer via USB cable.
Step 4: Once ODIN recognizes your device, click the PDA button and navigate to netchip-cwm-update2.tar. Click on Start. netchip-cwm-update2.tar will now be flashed to your phone and it will reboot.
Step 5: Once you’ve rebooted, press and hold Volume Up, the Home Button and the Power Button to enter recovery mode.
Step 6: If everything is running smoothly, you should now have entered ClockworkMod (CWM) Recovery.
Step 7: Navigate to install zip from sd card > choose zip from sdcard > su-2.3.6.1-ef-signed.zip
Step 8: Finally, Reboot your Note by choosing reboot system option from main menu.
Provided you followed the steps correctly, then congratulations – your Samsung Galaxy Note should now be rooted on Android 2.3.5 Gingerbread.

Saturday 17 December 2011

Drupal 7 theme structure

I decided to create an explanatory graphic that ilustrate the different theming portions of Drupal 7 and how to access and modify them. This is not a theming tutorial but a quick guide to see the different parts of a Drupal theme.
Notes:
  1. Page.tpl.php is basically where your main layout is. If you are starting from an HTML file, you can do the same as me and rename it to page.tpl.php and start populating the necessary elements. You can see which elements here.

    This page needs to contain everything that goes inside the body (you shouldn't add the <body> tags here).
  2. In Drupal 7 everything that holds content is a region, even the region that holds the "content" block.
  3. Node.tpl.php is the themed representation of a content entry and when listing content this file will be called multiple times, one after another.
  4. A block is just a piece of content that can be plain HTML or be generated from a module. (Like the Login block)
  5. A region is what holds multiple blocks. These are the defined in the .info file and called in page.tpl.php
Worth mentioning:
  • When creating the theme.info file, starting from Drupal 7 you need a region called "content" or the theme will show up as incompatible in Appearance settings.
  • I'm not including all the TPL files but the ones I use the most.

AJAX tips and tricks in Drupal 7

I've been very inspired by Earl Miles' advanced code examples:
http://www.angrydonuts.com/drupal-7-advanced-ajax-tips-and-tricks
Very good stuff !
What I would like to achieve:
When a user clicks on the ajax link, I don't want the ajax stuff to be triggered right away.
I want to process several tasks before:
- remove some html tags
- remove drupal throbber
- create my own throbber and place it in a very specific div...
- then trigger the ajax stuff
I tried to write some js based on Earl's example where he creates a custom event and triggers it later in the code.
My code works correctly except for the ajax stuff. :)
Nothing is triggered (no POST in the firebug console)
I can't figure out what is wrong in my code:
        // Click on CTA button
        Drupal.behaviors.CTAclickbutton = {
  attach: function (context, settings) {

    /**
     * Use a class to bind custom behavior to a link. As it happens, the behavior
     * if this link is nearly exactly the same as with "use-ajax". But instead
     * we are ensuring that the throbber is active.
     */
       
    $('.ctabutton-use-ajax:not(.ajax-processed)').addClass('ajax-processed').each(function () {
      var element_settings = {};

      // Remove drupal throbber.
      element_settings.progress = {};
     
      // For anchor tags, these will go to the target of the anchor rather
      // than the usual location.
      if ($(this).attr('href')) {
        element_settings.url = $(this).attr('href');
        element_settings.event = 'DelayedClick';
      }
     
      var base = $(this).attr('id');
      var ajax = new Drupal.ajax(base, this, element_settings);
     
      $(this).click(function () {
    $('#slidesHolder').remove();
$(ajax.element).trigger('DelayedClick');

return false;

  });
     
  Drupal.ajax[base] = ajax;
    });


  }
         };

How to reset Drupal admin password?

There's nothing more frustrating than missing/lost your drupal admin password and you are locked in a situation where you don’t know what to do next. I have been in such situation and found a solution as well as wanted to share with you all.
The first thing to try is to click on the lost password link, and have the password emailed to you. There are, however, a couple scenarios where this will fail to work:
1. This won't work if you're unable to access the retrieve password page.
2. This won't work if you've stored an old, no longer in use email address for the admin user (user 1).
Resetting your Drupal admin password using phpMyAdmin
This is the best php tip I have found for reseting drupal administrator's password. You will need access to phpMyAdmin or some way to manage your database.
Follow the below steps to get your drupal admin password reset quickly:
1. Login to cPanel -> Databases box -> phpMyAdmin;
2. Select the Druapl database folder from the left navigation bar. The page will refresh and and the Drupal database’s tables will be displayed on it. (in case you don’t know the DB name, you can find it by looking into setting.php file)
3. Click on the SQL tab. In the text field write the following SQL query:
update users set pass=md5(‘NEWPASS’) where uid = 1;
You can replace “NEWPASS” with your new Drupal administrative password.
Restting admin password using Drush
If you are using Drush (a command line shell and scripting interface for Drupal), you can run the following line
drush php-eval 'db_query("UPDATE `users` SET `pass` = MD5(\"NEWPASS\") WHERE `uid` =1;");'
Note: Don’t forget to add table prefixes if your site uses them.
You can also find documentation  at Drupal.org for resetting admin password for Drupal 6 and Drupal 7

What to do when you can no longer login to your Drupal site

So the scenario is this: you notice that you are no longer able to login on your Drupal site:
  • the {users} table entry for your account looks just fine
  • the login and access timestamps on your account are just a few seconds old, matching your latest attempt to login
  • you reset your password in the DB, just in case, and it still does not work
  • the telltale is that Drupal will not even tell you your login failed: it actually works, as the {users} table shows, but yet you are not logged in
Can you guess what can have been going wrong and fix it ?
Actually, in such cases, and at least on most sites without high-end technologies like Memcached or MongoDB sessions, there is one other table you should be looking at, and that is the {sessions} table. If, like most Drupal sites, you are running on MySQL, chances are that your {sessions} table has crashed. This is most common in Drupal versions up to 6, which use the MyISAM engine by default, typically unchanged on smaller sites, whereas Drupal 7 defaults to InnoDB, and larger sites will also have installed Drupal 6 on InnoDB too.
What is happening in such a case is that Drupal actually updates your login entry into the {users} table, but then when the page ends, PHP tries to invoke the Drupal DB-based session handler to write back information about your session into the {sessions} table, and fails because the table is crashed. If you look at your web server logs, you will then notice tons of messages like this (typical Apache: /var/log/apache2/error.log):
[Thu Aug 04 09:34:27 2011] [error] [client (IP masked)
PHP Warning:  Table './(site masked)/sessions' is marked as crashed and last 
(automatic?) repair failed\nquery: UPDATE sessions SET uid = 0, cache = 0,
 hostname = '(IP masked)', session = 'language|s:2:\\"en\\";',
 timestamp = 1312443267 WHERE sid = '1c3a573a10ff949d31c193c42365c7d7'
 in /(path masked)/includes/database.mysql.inc on line 174,
 referer: http://(site masked)/user
These happen when Drupal tries to update a session entry. And then tons of similar messages on SELECT queries instead of UPDATE for the attemps by Drupal at locating an existing session for the user.
The solution is then obvious: ssh to your server and run something like:
mysqlcheck -rev (your database) sessions
Do not forget to add the DB prefix if your are using one, like this:
mysqlcheck -rev mysingledb site1_sessions
This should restore your table to sanity. If you do not have access to a command line, as can often happen with smaller sites on shared hostings, phpmyadmin includes an option to "repair" a table, which does essentially the same thing.
One point to notice about this is that it will lock the table during the entire repair process, so your site will be frozen in the meantime.
Afterwards, you might want to consider taking a backup of your site, then converting it to InnoDB. Do not forget that this means a different configuration in /etc/mysql/my.cnf to attain good performance: you will likely want to reduce the memory space allocated to MyISAM and increase the InnoDB buffer pool, for a start ; then follow one of the InnoDB optimization tutorials available everywhere.
Oh, and if you are still running a Drupal 5 site, it is high time to upgrade: Drupal 5 has been out of support for over six months now ! Time to rebuild on Drupal 7 !

How to restore Unfuddle dumps: migrating to Drupal CaseTracker

Unfuddle is a very convenient and fairly cheap SaaS hosted Redmine (with extensions) and SVN/Git, which I use regularly on customer projects. Their service includes reassuring "Backup" options, going as far as to include the ability to backup to your own Amazon S3 bins in addition to their local backups.
Recently, however, I had to go back to an archived project for which I had dutifully taken a dump before closing it on Unfuddle, and looked for a way to restore it to my Unfuddle account. To no avail. Unfuddle support then kindly confirmed that the service did include a backup feature, but no restore:
Backups of projects within Unfuddle are for personal use only and cannot be restored into accounts via the interface. This however may be possible with some custom scripting on your part and with the use of our API (http://unfuddle.com/docs/api).
What then ? I will not comment on the business sense of such a "backup / no restore" proposition, but in this specific case, it prompted me to find a way to take my business elsewhere, and what better way than to Drupal ? Project and friends being a bit too complicated for these needs, I figured this would be a good occasion to flex my Migrate chops and built a Migration enabling the import of Unfuddle dumps to CaseTracker, the project management component in Open Atrium. So here it is:
Unfuddle backup restored to CaseTracker, main screen
As you can see, this code, even in its first incarnation, can restore a bunch of information from your Unfuddle backups to Casetracker:
  • Unfuddle Users, as Drupal users
  • Unfuddle Projects, as CaseTracker projects
  • Unfuddle Tickets, as CaseTracker basic cases
  • Unfuddle ticket Follow-ups, as CaseTracker comments
The image below shows the mapping of Unfuddle Ticket fields to CaseTracker Cases.
Unfuddle Ticket mapping to CaseTracker case
Of course, this being a one-off effort, the features are limited, but for anyone interested, the code is available from the OSInet Git repository for the migrateunfuddle module. Should anyone be willing to work on it, it could obviously be moved to Drupal.org, like my previous Migrate Remote Migrate extension for over-the-wire migrations using XML-RPC.
To use it, just install the module normally, uncompress your Unfuddle backup in the sites/(your site)/files/unfuddle directory, and head over to the Migrate v2 administration screen.