Sai Prasad
(6 comments, 43 posts)
This user hasn't shared any profile information
Home page: http://www.saionline.co.in
Yahoo Messenger: saiprasad_35
Jabber/GTalk: saiprasad.ch
Posts by Sai Prasad
Firefox Addons: Little Housekeeping Tips
0I’m working on a Firefox addon in the last few weeks and this is my 1st experience with Firefox addons. During my tiny experience, I came across some of those little things that helps you when you’re in trouble & here I’m writing about those simple tips. Of course, I mixed some changes in Gecko 2.0 also along with these….
I know these are very basic, and almost everyone who worked on the addons might be knowing them, but hey, didn’t I mention you that this is my first encounter with building firefox addon?
How can I be sure if a Binary XPCOM component is loaded / attempted to load from Firefox?
Close all Firefox windows and run the following from command line:
set NSPR_LOG_MODULES=all:5
set NSPR_LOG_FILE=c:\ff.log
C:\Program Files\Mozilla Firefox\firefox.exe
What does it do? Line 1 sets the modules to load & the log level. In the above commands, we are asking to log all modules with log level 5 (meaning all logs). Line 2 sets the path to log file. Now, just launch the Firefox from command line (so that the variables are set)
Troubleshooting Tip: Do not use quotes around the log file name, like set NSPR_LOG_FILE=”C:\ff.log”. I tried it the 1st time and it doesn’t work.
References: Troubleshooting XPCOM components registration, NSPR Logging
How can I sure if an XPCOM component is successfully registered?
This works for both binary & JS components.
Enable Chrome errors in Error Console, if you haven’t done already! To enable, set javascript.options.showInConsole to true in about:config preferences.
Open Error Console (Ctrl+Shift+J)
Evaluate Components.classes["components-contract-id"].name. Use with the components’ contract id.
If it gives no error, the component is successfully registered.
References: javascript.options.showInConsole, Troubleshooting XPCOM components registration
How to log errors from the XPCOM components?
This is simple thing, and I realized a bit late about it. This is currently how I’m debugging my components (need to see if there is a better way). You can report error messages to the Error Console with:
Components.utils.reportError(“This is the description of the error”);
References: Error Console
nsIConsoleService
The inconvenience with the reportError API is that it logs all messages as errors. To log at various levels (debug / warning / info), we can use the nsIConsoleService. The logStringMessage() function of this service looks very handy.
I haven’t used it yet, so I cannot give any more information on this!
References: nsIConsoleService Reference
UnPack option
If you are using binary components in the addon, you MUST set the unpack value to true in install.rdf file.
References: unpack in Install Manifests
Bootstrap Addons
This feature introduced in Gecko 2.0 answers one of my long-time questions – Why should I restart the browser everytime I add / update / disable / remove an addon?
Though this feature is good, it looks complicated to do all the manual work. I’ve skipped trying this feature for now, but I’ll look into this some other time.
References: Bootstrapped Extensions
Gecko 2.0 XPCOM Changes
Though there are many changes, I’m listing the few which I came across.
- Javascript component must export NSGetFactory() instead of NSGetModule() function. Binary component must export NSModule() instead of NSGetModule() function. I’ve explained this in detail in the next section.
- Components in components/ folder are no longer auto-registered & auto-loaded. Components registration will be done through the manifest file.
- Category Registrations are done through manifest file. Also, category names are modified.
- You’ll have to use the XULRunner SDK 2.0 for Gecko 2.0
Troubleshooting Tip: Use the sample CPP file (from the references) to get started for binary components. I got a few compilation errors initially, and then I has to add MOZ_NO_MOZALLOC to preprocessor definitions as read somewhere, and it worked..
References: XPCOM Changes in Gecko 2.0, nsSampleModule.cpp source code
Component Registration in Firefox 4.0
All the components to be registered has to mentioned in the chrome.manifest file.
- All the interfaces (xpt files) are to be registered using interfaces command
- A JS component must use component command. It needs to mention its class id also. The contract id can be assigned to this JS component by a separate contract command.
- A binary component can be registered with binary-component command. A binary component registration need not specify any class-id or contract-id in the manifest file, since they are available through the exported NSModule() function.
References: Chrome Registration
If you have felt all the content is copied from somewhere, its ok because its true. I’ve learned many things from MDC itself, I’m just aggregating those things here!!
If I’ve got something wrong in here, please do mention them in the comments as I have to correct them in the post as well as in my mind…
Troubleshooting XPCOM components registration
Quotes I like:: Vol. III
0Some random quotes / one-liners, I liked.
- Great minds are always feared by lesser minds
- … there’s a gap between what science knows and what business does (Dan Pink)
- All those who wander are not lost.
- What we have done for ourselves alone dies with us; What we do for others dies with them. What we do for the world is too insignificant to count.
- Even if an analog clock is broken, it shows correct time at least twice a day.
- A happy man is not the one who has everything, but who makes most of everything he has.
- Keep your face to sunshine and you can’t see the shadows.
- Make sure the thing you’re living for is worth dying for.
- Speaking without egos, Loving without intentions, Caring without expectations, Praying without selfishness is the sign of True Relation
- I decided to send you the cutest n sweetest gift of the world. But the postman shouted at me sayin – Get out of the postbox
- If you don’t count any of my failures, I’m quite successful.
- To live is the rarest thing in the world. Most people exist, that is all.
- The biggest fools are those who seek an interpretation for everything
- You’ll never have a quiet world till you knock the patriotism out of the human race
You can find my previous favorite one-liners posts at: Quotes I like:: Vol. II & Quotes I like:: Vol. I
Debug PHP: Setup
0Okay! I forgot how to set up debug for my PHP, so I had trouble today trying to set it up today and had to spend about an hour to do so… So, I decided I should note it down for future reference and hence I’m here now!
Tools: PHPEclipse, PHP 5.3.3, XDebug
- Make a PHP file with content as <?php echo phpinfo(); ?> and browse the page on localhost.
- Copy the source of the above page from the browser and paste it in http://xdebug.org/find-binary.php and click “Analyze my phpinfo() output”. This step will give you tailored instructions on how to setup, especially points to the right DLL to use.
- Be careful with the editing php.ini file. Prefer to add the zend_extension line at the top of the file. (It doesn’t work if its the last line)
- And start debugging from the Eclipse IDE !!
C++ Quickies #I : Long live the STL
0Its been quite some time (16+ months) I’ve been out of college and started using STL. Trust me, I didn’t know much about STL in college, though I used std::string & std::vector everywhere I could. Now, it seems like I couldn’t (wouldn’t ? ) write a program without using STL at all. A few snippets that I really found useful (and simple) and I regularly use where ever possible.
To output the elements (all / subset) in a container (lets say vector), separated by a delimiter, say new line:
#include <algorithm> std::copy(v.begin(), v.end(), std::ostream_iterator(std::cout, "\n"));
Want to sort an array? No problem …
#include <algorithm> std::sort(array, array + lengthOfArray);
Read from the standard input into a vector until the end-of-stream?
#include <algorithm> #include <iterator> #include <vector> typedef std::istream_iterator<int> istream_iterator_int; std::vector<int> v; istream_iterator_int start (std::cin); istream_iterator_int end; std::back_insert_iterator<vector<int> > dest (v); std::copy (start, end, dest);
Count the no. of instances an object is found?
#include <algorithm> size_t count = std::count(v.begin(), v.end(), 42); // Returns no. of elements in v with value 42.
And let me inform you… This is just a grain of what STL can do….
References:
Just Friends! It got something !!
0If you’re wondering what it is, ‘Just Friends‘ is a novel by an Indian writer. I think it is his debut novel, but don’t take my word on this. You need to google (or bing, for Bing fans) it to be sure. By ‘It got something’, I don’t mean to say, its an awesome book. I wouldn’t even say its a good book, its just another book (add some 18+ masala content to the recipe) . What impressed me in the book are the quotes (quoted by the author himself, I believe) in it. They are not inspirational or something, but I liked them (not that I like only inspirational, in general). So, I decided to put my favorites here and share with you.
- Sleep is deadly and love is lethal. The combination is so powerful that it leaves you helpless, forcing you to sleep later.
- A sleepless night is a lover’s right
- Restless nights, drowsy mornings, confused afternoons, lonely evenings…
- Eyes are like prostitutes – they reveal more than they can conceal.
- I laughed, she laughed. Problem solved.
- I smiled, she smiled. All problems could wait.
- You pose a great competition to sugar for its characteristics of deadly sweetness and mixing quickly and easily in unknown waters.
- I wasn’t superstitious. It was just… love.
In case they don’t make sense to you, you need to read the novel then coz they all are situational, though you can identify the situations from the statements itself for many of them.
Until next post, have a peaceful life (great would be great, though)…