Blog moved to tumblr
I have moved my blog to tumblr. If you are interested have a look at it from here
setting up php , xdebug and NetBeans
As developers, we often come across with code debugging. When it comes to debugging, my preferred option is to utilize the facilities given by the IDE (In my case its NetBeans (6.9.1)). I find it more easy, accurate and useful way of investigating the program flow rather than printing lines in the code and having looking at the server log.
Today I wanted to debug one of my php codes. As I’m fairly new to php I haven’t used any debugging mechanisms. So I had a little googling and found out the most preferred way is to have x-debug setup with NetBeans.
even though the setup is fairly easy, I had to make use of several resources in several different locations. So I thought of summing up everything in an one place will help someone.
For this guide, my set up is as follows
I’m on linux, with apache2, php5 and NetBeans (6.9.1) . I assume you all have php running on your apache server
Ok lets starts.
1 - download the xdebug (http://www.xdebug.org/download.php). make sure you download the correct (or most matching) source. (I downloaded the source file) 2 - extract the source file to any directory you want and browse to that directory 3 - while you are inside that xdebug directory type 'phpize' in your console. you should see something like following Configuring for: PHP Api Version: 20041225 Zend Module Api No: 20060613 Zend Extension Api No: 220060519 But if at all you get an error like 'bash: phpize: command not found' that means you are missing the ' php-devel' package. to install it run 'apt-get install php5-dev' as root 4 - Once done run ./configure 5 - and make and make install (building the xdebug is their in the README file) 6 - after you run the above command you will get 'xdebug.so' which is under <your xdebug folder>/modules 7 - copy that in to any place you want. 8 - then open-up your php.ini file if you cant locate this file, best way is to create a php file in any name (in my case index.php) and add the following php code to it. <?php phpinfo(); ?> , then view it using the browser. that page should display where is your active php.ini file is located. 9 - open that file and add the followings zend_extension = "/home/sameera/tools/web/xdebug/xdebug.so" xdebug.remote_enable=on xdebug.remote_log="/var/log/xdebug.log" xdebug.remote_host=localhost xdebug.remote_handler=dbgp xdebug.remote_port=9000
**** zend_extension path should be same as the path you have your xdebug.so
Thats it. restart apache and load your php.ini file. Then you should see a separate section for ‘XDebug’. By this time you should
be able to start debug your applications with NetBeans.
- open NetBeans
- open your php prject
- add a break point
- run your project in debug mode
Rails Best Practises
Today when I’m browsing through some rails stuff I found this very helpful resource on best practices in rails development by ihower
http://www.slideshare.net/ihower/rails-best-practices
enjoy
undefined method `manage_gems’ for Gem:Module (NoMethodError)
OK, if you are looking for a solution to the above error hopefully this post might help you. This happens normally if you upgrade your gems.
(Please note – I’m talking about ubuntu here, If you are on windows then try Ubuntu
)
Then ruby gems will create a new file called ‘gem1.8′ and it will conflict with your older ‘gem’ file. You can find both these files in /usr/bin
So when ever you say gem list (or something with gem) it gives the error ‘/usr/bin/gem:11: undefined method `manage_gems’ for Gem:Module (NoMethodError)’
As a workaround , I have done following and it worked for me. My solution was to create a symbolic between ‘gem’ file and ‘gem1.8′ file.
Here’s how I did it,
first copy your ‘gem’ file (as a backup)
cp /usr/bin/gem /<my other path>/
Now delete the ‘gem’ file
sudo rm -f /usr/bin/gem
OK, now create the symbolic link
ln -s /usr/bin/gem1.8 /usr/bin/gem
Thats it, now time something like
gem list and it should work.
Hope this quick note will help
Net::SMTPSyntaxError (501 : missing or malformed local part )
If you are on Rails and tried to send a mail from ActionMailer, you might have got this error, Recently I did,
With a little bit of googling I came across the solution, This mostly happens because of the sending recipients,
Mostly you have mistyped the e-mail address (es), In my case, my recipients list was like this
email1@google.com, email2.yahoo.com,
and the last ‘,’ had caused the problem, So I changed it to
email1@google.com, email2.yahoo.com
and everything was back to normal
Following links are also useful to have a look
http://www.ruby-forum.com/topic/79053
render :action and passing parameters
in rails, I think most of you have come across with render action (Ex: render :action => “index” etc..). And have you ever wanted to render an action which expect some parameters ?!. OK.. Let me be clear, I have following controller actions
def new
@project = Project.find(params[:project_id])
end
– here my new action is expecting a parameter called project_id to load a project. And in down deep in my controller I have a create method. There I’m going to save a user object for a given project. I want it to save with out a problem and if so it will redirect to root url and if not it should render the new action again (with error messages).
def create
if @user.save
#if user object successfully saved then redirect
redirect_to root_url
else
#but if saving failed then redirect beck to new action.
render :action => ‘index’, :params => { :project_id => <project id> }
end
end
But this render action fails. Problem is even though we pass the parameters rails actually dont run the action method again (http://dev.rubyonrails.org/ticket/11037), so your parameters will not be used anyware.
Is there any alternative ?
Yes, there are many, and one would be loading the required objects before render the action again. So as per my example it should adjust like,
def create
if @user.save
#if user object successfully saved then redirect
redirect_to root_url
else
#lets load the project object before rendering the action
@project = Project.find(<project id>)
render :action => ‘index’
end
end
this would do the trick , Hope this helps..
recursive find and delete on linux
Today I have come across a problem where, I have a folder (say users) and inside users i have folders for each user (Ex Jhon, Seena etc..) and inside each user folder i have a svn folder. (I’m running Ubuntu)
Users ->
Jhon
-> a.svn
seena
-> b.svn
And my requirement was to remove all the svn folders. So heres how i did that (this code spinet was given one of my collegues). And heres how you can do it
go to the required folder (Ex: Users)
and open up a command prompt
type this command
find . -name “*.svn” -exec rm -rf ‘{}’ \;
and that should do the magic
So let me explain the command
find . -name “*.svn” -exec rm -rf ‘{}’ \;
find -> will find the files we are requesting
. -> means the current folder (you can give any folder you want)
-name -> what is the characteristic to find (in this case its find by name)
“<you files>” -> name of the files (*.svn means all the files which has .svn extension)
-exec -> this will execute the next command which we give
rm -> remove command
-rf -> r means recursive (since these are folders) and f means FORCE since .svn files are read only
‘{}’ -> this tells the system to get what ever the parameters which sent by our earlier find command
\ -> do this action recursively
hope this helps ![]()