Subesh Pokhrel

Magento Developers Blog

Get Latitude and Longitude of User From Simple Javascript!

I am a big fan of Latitude and Longitude, as you all might know, I have other post related to Latitude and Longitude and Google Maps. I came across one of the greatest feature of Mozilla Firefox 3.5, and that was to get the latitude and Longitude of user using simple Javascript. No API to use, No query to Google or anything. Here’s the code. [source language=”javascript”] [/source] Remember this only works on Mozilla Firefox 3.5. I’ll later come up with using this method to plot user on Google Maps, So follow on !

Googling “Google” on Google

Have you ever tried searching for ”Google” on Google? You might have or not, I don’t know, but when I asked to one of my friend he gave me a very humorous answer. He said it would go into a ”infinite loop”. Mathematically speaking R=G(G), here R is Result and G stands for searching in Google, where the searching parameter is itself Google (G). So, when you break it up or simplify this we can see as follows: R=G(G) R=G(G(G)) R=G(G(G(G)))… So there is a never ending loop. I don’t know if this is the “most absurd” deduction, but still you can think about it and just laugh :D Those were all the fancy part of the post. I mean just to make the post seem humorous. Now I actually Googled for Google on Google. Google showed up with some of these “interesting” results. Result Analysis I: This is the first result shown. As you can see it shows up with a www.google.com, with meta-description or title or the striped content Enables users to search the Web, Usenet, and images. Features include PageRank, caching and translation of results, and an option to find similar pages. And when you carefully observer the HTML codes of www.google.com, then you can see no such text (not even hidden) in the page, not in its meta content as well. So how is this possible, untill… someone injects that… someone who has the authority. You can think of anyone.. notes,books,page or heart,lungs,brain.. any one… There were similar things happening with googlemaps,googlevideos,googlereader……. Result Analysis II: google2 Another interesting site that comes up is http://www.thechurchofgoogle.org. This site claims Google to be the nearest to God where mankind have ever been to. It does not blindly worship Google as God but gives you 9 scientific/spiritual proof, for believing that. It says Google as Omniscient (all-knowing) and Omnibenevolent in a most logical fashion that no one can argue. The most interesting proof is proof#8 Google Trend According to Google trends, the term "Google" is searched for more than the terms "God", "Jesus", "Allah", "Buddha", "Christianity", "Islam", "Buddhism" and "Judaism" combined. Result Analysis III: google it You can find this on http://justfuckinggoogleit.com. It is just a site.. reminding the power of Google or claims “All Smart people user Google”. Nice to own such a domain. Result Analysis IV: www.googlefight.com. This site makes a fight amongst the two keywords on the basis of total number of search results of the respective keywords returned from Google. It was fun.. at least to me while comparing with my name and friends name. Guess this would be my last post for this year… and I would take a chance to wish you all a very HAPPY NEW YEAR... Keep Googling.. on Google.

Newsletter Email Tracking: Read or Not?

I have completed first phase of a simple, yet useful Newsletter System. When I demonstrated to the clients, they came up with a question if the newsletter being send was opened or not by the newsletter subscribers ? I then thought.. let see how its done. Then I came with this simple tracking trick, most of the spammers used to verify if the email address was valid or not. The first thing I did was adding 1px by 1px image on the footer of the newsletter, whose source was set something like this http://subesh.com.np/newsletter/track.php?identitycode=CLIENTID_SENDEMAILID. Here CLIENTID = Your Clients ID and SENDEMAILID = Id of the Newsletter sent. Now, when the image is loaded while viewing the newsletter on the mail or say when the client reads the newsletter email. The track.php page is requested with identitycode as the GET parameter. And when you get the request from the mail to your server’s page, you can do anything you want. What I did was setting the mail_read column of the database field as 1. And echoed the source of the image file on the last line. The code below is for the track.php. [source=”php”] [/source] Isn’t this the easiest idea anyone could ever come up with. Yeha! Thumbs up to me!!

Facebook Chat on a Side Bar of Mozilla

These days I am using Facebook a lot and no wonder everyone is using Facebook a lot. And the number of online users on Facebook are sometimes more then my MSN Messager online friends list. I get so much of words from my friends saying I did not reply to their message on Facebook Chat. In fact I open so much of mozilla window and tabs while working that, I come across the Facebook page once in a while. Then I came up with this idea of opening Facebook Chat on the side bar (i.e Bookmark Side Bar), and to my delight….. IT WORKED!…. Here’s is what I did on Mozilla. It’s a simple trick. I just added a new bookmark on mozilla. Step 1: BOOKMARKS>>ORGANIZE BOOKMARK Step 2: ORGANIZE>>ADD NEW BOOKMARK STEP 3: Add Name: (Any Name) STEP 4: Add Location: http://www.new.facebook.com/presence/popout.php STEP 5: Don’t Forget To Check the Load this bookmark in sidebar Now you are done. Go to Recently Bookmarked and Open this bookmark. The bookmark then open in the sidebar of you mozilla. No matter which page you are browsing you are chatting on Facebook. My recommendation is to use wide screen display, so that you will have enough room to chat and browse page. How did you like the idea? I am sure most of you all will give me a thumbs up!

Ajaxified File Uploader Using IFrame

Today, while writing a code for AJAX file uploader, I was trying to do with [wiki]SALAJAX[/wiki]. But, with SALAJAX I could not manage to send the headers for $_FILES. So I thought of an alternative. And the alternative was to load the action page of the form on [wiki]IFrame[/wiki], whose display would be hidden and the work for uploading the file will be done on the background without refreshing the page. Yeha.. Its not [wiki]AJAX[/wiki], but it gives a user the feel of asynchronous working on the page. So, my code is Asynchronous Feel Without Javascript and XML (AFWJAX). What do think about this? So, Here’s the code.The code below is for the form. [sourcecode=”html”]
File:

[/sourcecode] You can see on #1 the action of the form is iframeinc.php. The code for this page is given below. There are some other things you should remember. Like the target for the form is set iframe, whose display is set none so that it is not seen. And this iframe is the of the iframe created on #6, whose source is the iframeinc.php. Now here’s its code. [sourcecode=”php”] [/sourcecode] Remember to set $newname value before running this. At first run you may see this as a regular post script, but try to reload with f5 or reload button of your browser, you will not be asked to retry or resend the post header. So, there are own ways of catching your nose. [Download Source]

Tabbed Infowindow in Google Maps

I wanted to show different categories of information on one GMarker. That is I wanted to show different types of information on a Infowindow for a point on Google Maps. For that I used a tabbed info window, which helped me to show different data on each tabs. Here is the code of what I have done. I have shown the latitude and longitude of a placed clicked on the map on the tabbed info window. This is just the script part. The demo and download links are given below. [sourcecode=”javascript”] [/sourcecode] Lets focus on the #17-#26 Lines of codes. Other Lines are already described on other posts. Please see the related post link below the post. #17: Creates a GMarker on the point where clicked on the Map. #18: Addes the GMarker over the Map. #19: Initiates an array of tabsinfoTabs with GInfoWindowTab function with tabname and its innerHTML as parameters. #20: Opens the infowindow calling openInfoWindowTabsHtml function and the array of tabs as parameters. [Download] [Demo]

Mapping the IP Address to Latitude and Longitude in Google Maps

At last I found hostip.info provides a service for getting the latitude and longitude of a place on the basis of the user’s ip address. Its light weight and free, rather than downloading bulky database and getting paid services, for getting latitude and longitude on the basis of IP. Here is the simplest way to do it. Requested to http://api.hostip.info/?ip=$ip&position=true it responds XML formatted output. So we need to parse XML code using DOM class of PHP.(#19-#23). Remember, the position=true should be set to get the latitude and longitude otherwise it will not show on default. Here is the code and I will soon upload the working demo. [sourcecode=”php”] load($uri); $name=$dom->getElementsByTagNameNS(‘http://www.opengis.net/gml’,’name’)->item(1)->nodeValue; $coordinates=$dom->getElementsByTagNameNS(‘http://www.opengis.net/gml’,’coordinates’)->item(0)->nodeValue; $temp=explode(“,”,$coordinates); $latlngValue[‘LNG’]=$temp[0]; $latlngValue[‘LAT’]=$temp[1]; $latlngValue[‘NAME’]=$name; return $latlngValue; } //calling the functions and setting on array $latlng $IP=getRealIpAddr(); //from roshanbh.com.np $latlng=IPtoLatLng($IP); ?> [/sourcecode] [UPDATE] [DOWNLOAD] Due to high request of the visitors I have posted the whole source code here.. just copy the PHP part above anywhere the script part and get the IP code from http://roshanbh.com.np/2007/12/getting-real-ip-address-in-php.html and run. Remember you need PHP5, because the DOM used is of PHP5. [sourcecode=”html”] Google Maps Plotting User By Refrence Of IP Address | Subesh.com.np [/sourcecode] Code #1 : Includes the tinymce files for the page. Code #4-#14: Initiates the tinymce instance for the page. Code#5-#6: TinyMCE has a lots of themes and mode which you can configure to exactly what you want. Let’s leave this for now. Just keep those two. Code#7: Now here’s the tricky part. You should keep here the name/Id of the textarea on which tinyMCE is decorated. If you want many editor’s instance on the same page, just add other textarea element seperated with commas. Code#8: Defines where the toolbar is placed. The other option is bottom. Code#9: Defines the tools avaliable. You can put custom tools wherever you like, either on button1 or button2 or button3. Code #12-#13: Defines the height and width of the editor. This is just a simple set up for tinyMCE, I am looking forward to adding more on this. Catch me later.