[HOW TO] Convert tabs to spaces in Eclipse and File (in Linux)


Tux, the Linux penguin

This is a quick tip that helped me save a lot of time – this is the reason why I love LINUX because of it’s simplicity.

I was working on a legacy code (referred as old-age code – a simple procedural coding style) for a client. In general, coding standard suggests you to have spaces instead of tabs to make it look better in all kinds of IDE, we (generally every developer) uses tab key a lot (to make our life easier) thinking it gives us the space but it inserts an actual tab (which usually jobs off from one end to the other). This legacy code was filled with tabs which looked pretty ugly in our code-review tool, though it looks perfect in the IDE, when you try to open it in Linux the favorite VI editor it looks ugly YUCK it is.

HUH, initially when my folks reported me I was like yeah go ahead and change it – what’s a big deal. But then when I came to know it not just one file but a lot (yes a lot) – it was almost more than 100 files, which had tabs instead of spaces (not GOOD – yeah I know).

Continue reading “[HOW TO] Convert tabs to spaces in Eclipse and File (in Linux)”

[HOW TO] Convert tabs to spaces in Eclipse and File (in Linux)

Route a domain by Zend-Router-Route-Hostname in Zend Framework


Zend Framework logo.
Image via Wikipedia

In my company most of our projects we have been using custom-zend framework and I love their routing concepts. It gives you various options of handling many different routes to get the data based on your needs – just amazing.

Let me get straight with the topic. With Zend Framework, it is easy to route your URL in a nice way without having an head-ache of working with .HTACCESS file. Thanks a bunch.

Most of us know how to route an URL with routes.ini, for example:

routes.contact.route                           = “contact-us”
routes.contact.defaults.module      = “contact”
routes.contact.defaults.controller = “contact”
routes.contact.defaults.action        = “index”
– this will route a URL http://example.com/contact-us into “contact” module >> “ContactController.php” controller >> “indexAction()”  action.

What’s the big deal? We know this, yes I agree, have you tried routing a domain?.. 😉 Most of us may not, definitely I have not it does not stop there yet, Zend Framework also gives you an option to route an URL based on host/domain name and that is cool!.

Continue reading “Route a domain by Zend-Router-Route-Hostname in Zend Framework”

Route a domain by Zend-Router-Route-Hostname in Zend Framework

Session data disappears in FLASH – SWFUpload


Gnome-mime-application-x-shockwave-flash
Image via Wikipedia

Recently we had to get rid of this strange problem in one of our project due to some security concern. It was a nightmare that we had used a funny method to overcome this problem (by-passing real login session & allowing SWFUpload to upload any image), strange!. But, now we have a solution to this problem thanks to my mind & the time.

The problem is….

When you submit a form (here it’s uploading an image) everything seems to be fine (session data) till the control reaches session_start(), right-after that call $_SESSION array becomes empty and it assigns a new session_id, gotcha!. The problem is with the new session being created each time when SWFUpload try to upload an image, but WHY?

As you know SWFUpload uses flash to do it’s magic in uploading an image asynchronously and flash has an user-agent of “Shockwave Flash”, hence apache thinks it’s a new request from a new browser and it assigns a new session, means it doesn’t really destroys the old session but creates a new session.

The solution is….

to keep the original session_id somewhere either in cookie or in a table, then pass the stored session_id to session_id() before calling session_start().

So simple ah!

Happy coding.

Session data disappears in FLASH – SWFUpload

Code Re-factor


Recently we have made code re-factoring for one of the project. It was a wonderful experience I have ever had, learned interesting pieces of writing code.

How do we define this? OK, Here you go

Refactoring is a disciplined technique/process of changing a project’s/program’s internal structure without modifying its external functional behavior or existing functionality

Things to keep in mind:

  • Understand the flow of whole project.
  • Collect the URL’s for all the modules.
    • Define SEO friendly URLs.
    • Make sure you have reused URLs with multiple modules.
  • Define the controller & models which relates to the URL.
  • Make sure the project is secure.
  • Enhance the use of error handling.
  • Don’t compromise for anything; change the rules if necessary.
  • Follow strict coding-standards.
  • Make sure you have optimized the code at a higher level.
  • See some suggestion/tips on writing OOPS code.

continues….

Code Re-factor

Coding OOPs


Well, we all know the features of OOPS – it serves a lot of advantages for a complex system – Code reuse, Security, and many more…

Oops
Oops (Photo credit: dingler1109)

But does just writing/implementing the module with OOPS complete your job? No.  It should also be meaningful when you define a variable/method for the Class.

Keep the following points very clear when you write a code in OOPS.

  • Make use of the real features of OOPS – Method Overloading, Data Encapsulation and Inheritance.
  • Understand OOPS principle here – Code Reuse Principle.
  • Give meaningful name for any variables/methods used in the class.
  • Make sure that when anyone looks at your code they should not have any doubts/questions except for the business requirements.

Naming Convention

A good naming convention is more than a nicety. It lets you write program that don’t need to be told about the relationship among variables and methods. Talking about coding convention reminds me one thing which helps understand the purpose of the script, called File/Method Description.

It is best explained here about coding-standard. It also have few examples which will help you to improvise the way your program should look like.

File/Method Description

  1. Give brief introduction about the script/method.
  2. Add any example which will help the reader to understand the syntax (if any) better.
  3. Add the date of the script when it is created.
  4. Give author name along with EMail ID – this helps if the reader/developers needs to clarify any doubts.
  5. Give @Copyright message if any.
  6. Give the design pattern if applicable.

help me extend this….

Have a happy coding!

Coding OOPs