Linux like development environment in Windows

6 11 2009

I am a fan of Linux based OS. I love Ubuntu a lot. In fact I started my programming in Redhat. So from the beginning I am comfortable using Linux than Windows. The only reason I use windows is to check IE browser compatability.

Recently I attended Drupal Sprint India 2009. I want to attend the sprint, so I need one Laptop to go there and work. My company provided me Laptop with Windows. So I need to work on drupal core issues in windows. Hmm it looks very hard for me to work in Windows. I want to have following things in my Windows machine.

  1. Cygwin to get the linux like terminal, so that I can see paths with forward slash.
  2. Xampp Lite to get Apache, Mysql, PHP.
  3. cvs, I am going to work on drupal core so I need it
  4. I should able to create patches, apply patches.
  5. I want to use Drupal Drush module, which provides some command line utilities
  6. Emacs. I am more comfortable with this editor. It is very hard to work with other editors once we are comfortable with Emacs

First I installed the things I know like Cygwin, Xampp Lite.

Installing Emacs

I Installed Emacs by following instructions at http://www.claremontmckenna.edu/math/ALee/emacs/emacs.html .

Installing UnxUtils

To be able create patches and apply patches I installed unxutils from http://sourceforge.net/projects/unxutils/ . With this unxutils I got most of the Linux commands. The commands like ls, mkdir, wget, diff, patch, tar, zip etc… are working. I am very happy after installing unixutils.
Installing UnxUtils is nothing but setting the path variable in Windows. I extracted the unixutils directory in C folder and Add C:\unixutils\usr\local\wbin path to the Path variable. In Windows XP we can set the Path variable by going to control panel > System > Advanced > Environment Variables. Select the Path and click Edit and add your path to the existing path.

Installing Drush

There is a documentation about installing Drush in Windows http://drupal.org/node/594744 . This document explain Drush installation by using GnuWin32. But I already installed UnxUtils so I don’t require GnuWin32. So first 3 steps in the http://drupal.org/node/594744 can be ignored. I extracted drush in C folder. As specified in the step 4 of http://drupal.org/node/594744 I edited drush.bat with the path of php.exe and path of drush.php. I added following statement in drush.bat file
@E:\xampplite\php\php.exe C:\drush\drush.php %1 %2 %3 %4 %5 %6 %7 %8 %9

Because I used xampplite to install php, php is there at path E:\xampplite\php\php.exe.Now I executed drush command from the windows terminal by specifying -r and -l attributes.
After that I got an idea why can’t I keep this php, drush paths also in path so that I can directly drush.bat file as it is. Yes I added php, drush, mysql paths in Windows Path variable. The everything works file.

Installing cvs

I downloaded TortoiseCVS from http://www.tortoisecvs.org/download.shtml. This is a exe file, I can simple double click and execute.

That’s it, Now I installed all the things necessary to work on drupal with a linux like environment. Now I am happy to work on windows.





Interesting css3 selectors nth-child, :target

5 11 2009

When I am reading the css documentation in W3c site. I met with some of the interesting selectors like nth-child and :target.

With the nth-child selector we can add different css for the even and odd elements. For example in a table we want to display different background color for the alternate rows. This we can do simply with the css. I used to write in the code to add odd class for the odd row, even class for even row using if conditions. This is really cool. We can see example at http://www.w3.org/Style/Examples/007/evenodd.

With the :target selector we can create a tabs view without using any javascript code. We can see an example at http://www.w3.org/Style/Examples/007/target

Unfortunately these selectors does not work with IE.  I was very happy by seeing these selectors but it IE disappointed me a lot.  Just because of IE  I need to write code to add different classes for the even and odd rows.  I tested with IE8 also but no luck, might need to wait till next release of IE. Just because of IE I can’t use these selectors.

 





Drupal Sprint India 2009

4 11 2009

I am a drupal developer, my drupal profile can be seen at http://drupal.org/user/43559. Drupal Sprint India 2009 event details can be found at location http://drupalindia2009.plug.org.in/namaste. From my organization 3 people attended this event. Asif (Project Manager), Chakrapani (Application Developer) and myself (Application Developer). I and Chakrapani attended this event to participate in the Sprint. Asif Participated in Talks and Workshops.

It is a nice experience to attend this event. Met cool people like Addison Berry, and had chance to share my views about drupal testing and documentation. Learned new things from her. It is really nice experience. With this event I started contributing to drupal core, which I love to do.

Through this sprint some of the drupal 6 modules are ported to drupal 7 and some new translations for the languages are added. Some of the patches are added.

Day 1

Took registration and attended the welcome session. After that went to participate in the sprint. This spirnt is headed by Addison Berry, Lead of drupal documentation project.

I wanted to work on drupal7 core issues, to work on core issues I read the documentation about how to set up the development environment, Review the patches etc.. before attending the sprint itself. I checked how people work on drupal7 core issues by joining the #drupal IRC channel.

For a practice I did some of the reviews for the drupal7 core issues, and added one patch for the admin_menu module which is committed to all versions of admin_menu module.

I tried to work on the drupal7 issues, but I noticed that some of the drush commands are not working well with drupal7 head. So decided to fix these issues of drush module and provide patch to drush module.

In the lunch time I introduced myself with Addison Berry and had good talk about the next plans of drupal documentation, drupal 7 release plan. Discussed about Drupal7 UI changes. Also Talked about plans about using bazaar for drupal and migration plans from cvs to bazaar. It is really a nice discussion. Addison Berry explained the complexities involved in implementing pathauto module for the documentation.

After lunch I talked with Addison berry about the samepage(http://samepage.in) product which I worked. Worked on drush module, Discussed with other guy about the best practices of themeing and drupal project development issues.

Day2

Morning I tried to finish my drush module task that I started yesterday, Finally it is a very small change added patch to the drush module.

After that had discussion with Addision Berry about how to properly maintain the our module code in cvs. Asked her about how multiple people work on same project when they are using cck, views. How to deploy code properly using update hooks. And also discussed about my views on drupal7 testing issues. She suggested me to contact other person who can give more input on testing. Took feedback from Addison Berry about my drupal module contributions, php contributions and jquery contributions.

After lunch I worked on porting my accordion_blocks module to drupal7, but noticied that there is a lot of change related to javascript api. Had talks with other guys who attended the sprint.

Finally came out from the event with good experiences and learnings.





Drupal:Displaying sub menus of primary link

23 10 2009

I want to display the sub menus of the currently accessing primary link as a block. Drupal provides Primary links, Secondary links blocks but does not display sub menus of currently accessing primary link.

When I search, I got following code snippet which lists the sub menus of currently accessing primary link. I directly created block using Add block by adding this php code snippet. It works a charm.

$tree = menu_tree_page_data('primary-links'); //substitute your menu name for primary-links
foreach($tree as $key => $mi) {
if ($mi['link']['in_active_trail'] && $tree[$key]['below']) {
$menu = menu_tree_output($tree[$key]['below']);
}
}
print $menu;

I hope this will help others to find easily.





Remove applied patch using patch command

23 10 2009

Today I am doing patch review of drupal7. I tested one patch, Now I want to remove this patch and go back to previous latest version of drupal. Unfortunately there is no cvs revert command which revert the files like in svn, bazaar, git etc..

I used same patch command to revert the applied patch.

I used following command to revert.

patch -p0 -R < patch_file_path.patch

In the above command -R option Assume patches were created with old and new files swapped. So it do the reverse operation of patch.





SVN: How to commit as a different user

23 09 2009

Today I spend some time to find out how to commit as a different user in SVN.

I did a checkout using svn+ssh by specifying username in the url for example svn+ssh://<username>@server/path/to/repos . The code was checkouted by user1, and this code can be accessed by user2. user2 edited some files and want to commit as user2. Every time when user2 is trying to commit, it is always asking the user1 password.

Actually if we use http or svn protocol, we can use –username attribute in the svn commit but this did not work for svn+ssh.

I tried by using –username, –no-auth-cache parameters in the svn commit but it does not work, always asking the user1 password.

After some time googleing, I went to svn IRC channel and asked there. Finally I am able to solve the problem by seeing the thread http://ubuntuforums.org/showthread.php?t=748131

1. We should change the svn root url to svn+ssh://server/path/to/repos. To change this I used svn switch command. I used following command.

svn --relocate switch svn+ssh://user1@server/path/to/repos svn+ssh://server/path/to/repo

2. Edit /home/user2/.subversion/config. Change the line that reads
#ssh = $SVN_SSH ssh to:

ssh = $SVN_SSH ssh -l <username>

<username> can be any user on the remote machine, but in my case it was user2.

That’s it from now on when I do commit it is asking user2 password.

The second step is not required if logged in username is same as svn+ssh username that you want to use. Suppose if you login to system as user2 and your svn server ssh username is also user2, then you can skip the 2nd step. It will ask user2 password when you try to commit.





== operator behaves strange in java

23 07 2009

Yesterday I was helping my sister to write one java program. I don’t know java, I was working on php, python, javascript from long time. But I could figure out the logic by seeing any code. So I am checking my sister java code. She wrote one if statement like this.

if(input_data == "Y"){
// some code
}

There is nothing wrong but the if condition is failing every time even I give the value “Y” for the input_data. This is correct syntax and correct logic, but it is still failing. It is looking very strange and weired for me. When I google for how to compare 2 strings in java then I figured out that “==” operator compare the object references not the content of the variables. In my case if write I should write if condition like this.

if(input_data.equals("Y")){
// it works fine
}

This is much difference from other languages. Why it is like this I could not understand.





Why I fail to submit my phrase to engineyard contest

23 07 2009

There is a programming contest which is conducted by engineyard. The contest is interesting so I planned to participate. I wrote program but could not submit the phrase to it. When I analyze why I could not submit, these are the mistake that I did.

1. I calculated wrong time of submission. I am living in IST and the content submission time is based on PST. I am not very familiar with these timezones, so I calculated wrong time. By the time I wanted to submit, the submission time is closed. I learned calculate the time properly and keep alerts

2. Lazy in writing program. I wrote program which will just take the 12 random words from the dictionary and calculate the hamming distance as specified in the contest. There are 2 more things I missed I can add 5 letter word at the end and each letter in the word can be of any case(upper or lower). I wrote these 2 case after the contest time start. I learned finish the task at that time, don’t postpone any piece of work to another day.

3. Lazy in knowing about SHA1 algorithm. I know that taking random words from the dictionary does not work. I know I need to know more about SHA1 but could not find or spend time on knowing more about SHA1. I depend on luck I know this is not correct, still I am lazy and couldn’t read about SHA1. I leaned that do not depend on luck just know more and work.





Drupal – Advertisement module

21 07 2009

Today I got a chance to work on advertisements feature in one of our project. I found Advertisement module. This module is having lot of features, I just need a way to add advertisement with the banner and need to show the ads in a block. I did following steps to get what I need.

1. Download and place Advertisement module in modules directory. I use drush

drush dl ad

2. Enable the ad, ad_image module through admin build modules page. I used drush

drush enable ad

drush enable ad_image

3. Go to admin/content/ad/configure/image page and set the maximum image size for the default group and checked Allow remote hosted images. Here I used default group. If we want we can create groups and assign ads to different groups. When we create a group, the specific group block will be created automatically.

4. Enable the default ad group: default block. Enable respective group block if create groups

5. Create advertisement by going to node/add/ad page. Specify the title and group details

6. Select the Add type in the Select Ad type section and click select then one new section will add at the bottom of Select Ad type section.

7. Specify the destination url and specify Romote Image path if the image is from remote path. We can also upload the image at the bottom of the page in file attachment section.

8. We can set the ad activation, expiration settings at scheduling section.

9. Set the status of the ad and save. Choose the active status if you want to display ad in the block. Save the advertisement.

10. Repeat the steps from 5-9 to add more ads.

11. Now the block will display the ad image that we created now.

12. By default block display 1 ad. we can configure the number of ads to be displayed in the block in block configuration page.

That’s it. I can able to create ads with image and displaying them in a block. Hope this might be helpful for others(I used drupal 6)





Drupal – Restrict access to menu item per role

20 07 2009

When I am working on one project, I created some content types. The view permissions for some of the content types should be restricted only for some roles. There is no view access peromission specific to content type. There are  add, edit, delete permissions for the specific content type.

Any how I am using only one node of that content type. So I used menu_per_role module. Through this module we can restrict the access of a particular menu item. I did following steps to restrict access to one menu item for some roles.

1. install menu_per_role module

2. enable the module

3. Go to menu item edit page, you can see Restrict access permission section. Select the roles which you want to give permission for this menu and save.

That’s it. It worked for me for now, but I need to find out how to restrict view access of particular node type. If some one know please send me comment.