lunatechian (lunatech-ian)

one relating to, belonging to, or resembling lunatech

php manual on your hdd

One of the strong points of PHP is its well annotated online manual, which is peppered with useful code snippets and hints. How many times have you pointed your browser to php.net/manual/ to look up that at-the-tip-of-your-mouth function's argument list ? If you or your company use the manual frequently, it might be a good idea to mirror the manual in your internal network. I have mirrored the manual in my office, and the two benefits that I see are

  • Faster manual lookup - Living in a bandwidth starved country(India), this is a major win for us.
  • A peek at well written code, again a major win if you are always looking for new and nifty way for doing things

The process of how to go about mirroring the manual is surprisingly well documented at Mirroring The PHP Website. As suggested by the documentation, You may want to exclude out certain non essential things ,like the manual in different languages. I also excluded the tar.gz and the zip files in the extra directory.

After downloading the manual pages, I created the virtual host (a simple copy-paste with some minor modifications) for the manual and that was it. To keep the manual uptodate I run the rsync command once a week.

For the record, my rsync command is rsync -avzC --timeout=600 --delete --delete-after --include='manual/en/' --include='manual/en/**' --exclude='manual/**' --exclude='distributions/manual/**' --exclude='distributions/*.exe' --exclude='extra/*.zip' --exclude='extra/*.tar*' --exclude='distributions/*' rsync.php.net::phpweb ./ Of course, you will need to change this to suit your needs.

Defined tags for this entry:

using google api from PHP

Now available for your downloading pleasure, is my GoogleSoap class. have you eveer felt the sudden need to use the Google's web APIs through PHP ? Worry not as help is at hand. You can use the GoogleSoap class to make your job easier. I have put the code and related documentation/examples in the public domain, so you can hack it up further. Some rudimentary instructions are included in the README file, I will add more to it as and when time permits me. Any additions/suggestions are always welcome.

Get the code here

Defined tags for this entry: ,

why code maintainance sucks

I have had to work on updating someone else's code for a few days now. The code was a headache to read because

  • It was not formatted to conform to my coding standard ... in fact it did not conform to any coding standards.
  • There was no version control ... oh wait, yes there was version control. It was version control by commenting out unwanted code. So I had to scroll through screenfuls to commented out code. I must take a moment to thank the programmers of Anjuta IDE, which helped me a lot a with their excellent syntax highlighting. Here is how you delete code.
  • Did I say there was no version control. There was a version control system. It looked almost like this
  • There was no comments.
  • There were spelling mistakes in variable names
  • PHP code and HTML were mixed
  • there was more .. i have forgotten it.

Defined tags for this entry: ,

Hyperlinks with LaTeX

I am big fan of Texinfo for writing articles or any other documentations work (yes, I do sometimes try to write the specification document). For a few weeks now, I have been trying to learn LaTeX, sice it can be used to typeset good quality presentation slides and letters too.

A problem that I faced when writing the articles in LaTeX was on how to make a hyperlink to a webpage. I was using latex2html to convert the latex file to HTML format. LaTeX comes with a hyperref package which can be used to create links. It has a \href command which can be used to create hyperlinks, but the links did not come out in the HTML page. I found that this was a known problem with hyperref and latex2html. However, the solution, as I found out, is much easier. The command to use is \htmladdnormallink{link text}{universal resource locator} You have to include the package html in your document to use it

\usepackage{html,makeidx}
....
The text of this article can be downloaded from our
\htmladdnormallink{web site}{http://www.example.org}.

Defined tags for this entry: ,

Search Google from command line

As I had pointer out in my previous entry, I had not been able to search google from within my emacs environment. Hence the "need" to write a command line script which I would be able to call from within emacs

The code is not the best I have written and any decent Python programmer would be able to make more improvements to it. If you do something clever with the code, it would be very kind of you to let me know about it too (raj at rajshekhar.net).

You need to have Pygoogle module installed. In its unaltered form, the script will require Python2.3 to run. However, if you remove the #--ugly hack part (see the comments in the code), it will run with Python2.2 too.

Code now available at mouse click from here.

Defined tags for this entry: ,

to GET or to POST

As Macbeth would have said "To GET or to POST , that is the question". The general consensus is :

  • Use GET when you want to give the user the ability to bookmark a page (as all the data is held in the URL and does not rely on an existing session on the server.) The "get" method should be used when the form is idempotent (i.e., causes no side-effects).
  • Use POST when a form causes side effects (for example, if the form modifies a database or subscription to a service).

formed discussion over this topic in this usenet thread. Some words from the bible covering this topic. A more lengthy but not boring discussion on this topic is URIs, Addressability, and the use of HTTP GET and POST
Defined tags for this entry: ,