IP-to-Country lookup, for free and 95% accurate

April 21, 2009 by AcidRaZor · Leave a Comment
Filed under: JavaScript, Programming 101 

One of my recent posts showed you how to convert an IP address to an IP number so you could do a lookup on a IP-to-Country database.

However, I’ve found the next best thing. Maxmind.com is one of the leaders in GeoIP location and sports a database that is more than 99% accurate. That’s the paid version. For my project though, I only needed to know the country, and had to be pretty accurate.

Welcome Maxmind’s free JavaScript addon API! 95% accurate and does what I want it to do.

1
2
3
<script type="text/javascript" src="http://j.maxmind.com/app/country.js"></script>
var countryCode = geoip_country_code();
alert(countryCode);

And that’s IT! You don’t have to host the database, you don’t have to do the number conversion yourself and pretty much everything else is taken care for you. The free service also included City lookups! Include and enjoy!

Here’s the link to their site: http://www.maxmind.com/app/javascript_city

Looping through a 2-dimensional array with jQuery

April 21, 2009 by AcidRaZor · Leave a Comment
Filed under: JavaScript, Programming 101, jQuery 

I recently opened my eyes to the wonderful world of jQuery. *drifts off into a fantasy*

Here’s an example of how to loop through a 2-dimensional array using jQuery. Fun & Easy:

1
2
3
4
5
6
7
var currencyTocountryName = [['USD','U.S. Dollar (USD)','$'],['GBP','British Pound (GBP)','&#163;'],['EUR','Euro (EUR)','&#8364;'],['AUD','Australian Dollar (AUD)','$'],['CAD','Canadian Dollar (CAD)','$'],['NZD','New Zealand Dollar (NZD)','$']]
$.each( currencyTocountryName,
           function( i, value ){
                   alert(value[0]);
                   alert(value[1]);
            }
);

As you can see it’s pretty straight forward. No need to have “i” be the place holder, a simple value[0] will get you the first value in the array. This must be the easiest implementation of a loop and array I’ve done in years. Sure, by now I can do a simple JavaScript loop in my sleep. But without thinking and a lot less code, jQuery allows me to leverage off that power. *Drifts off into a fantasy once again*

toLowerCase() not a function error

February 16, 2009 by AcidRaZor · 5 Comments
Filed under: JavaScript, Programming 101 

What I found most annoying was that IE perfectly handled this, but not FireFox.

Here is what this “toLowerCase() not a function error” really means:

The object you’re trying to lowercase is NOT a string object. By using

1
alert(typeof(object));

you can determine what type the JavaScript engine thinks the object is. A simple solution is:

1
object.toString().toLowerCase;

I hope someone finds this information helpful as it took me several hours of research on the internet to come up with a clear concise and TO THE POINT answer of what it actually could be and in fact, was.

I wish all the know-it-all’s would stop pretending they know anything about anything and just piss off of the internet.

SEO Powered by Platinum SEO from Techblissonline