Dengar's Blog Logo

Dengar's blog...
We will see what I post, probably will be some random tutorials

Monday, 31 January 2011

My favourite Android Apps

I have an Android phone since the launch of the HTC Magic (in some countries Saphire) in July 2009. I have never found a phone more useful and, with 2.2 on most devices now, pity the people that are on Blackberry or iPhone when they had a chance to get an Android device.

I must admit, some models are just not as aesthetic than the iPhone and they don't seem to be as functional for business people, but that's where people are wrong...

I thought I give a quick run down, in separate posts, of my favourtie apps:

Astrid Tasks for Android phones

Astrid is, apart from standards such as email and calendar, my absolute must have app on Android. It syncs tasks with RememberTheMilk, Productee and Google Tasks.

Apart from it's easy to use interface and classic Android white-on-black theme, it's unbelievably useful for people that have a lot of things they want or need to do, but keep forgetting personal or work related tasks. I now slot everything - from watering the flowers or washing the laundry to preparing monthly KPIs - in my task list using Astrid.



It's a very handy app when in meetings, conferences and when you are on the road. I task that needs doing comes up and instead to jotting down notes that you probably won't ever look again, you get it on Astrid and sync it back with your online task list.



Constant reminders keep nagging and encouraging you to finish tasks and you can schedule due dates and tags on your tasks.


Geo IP lookup - ipinfodb.com API integration using PHP

(this also explains the PHP DOM parser)

For one or the other reason, and be it that you want to determine the home country of your visitor for localisation and language options, you might find yourself looking at integrating an IP lookup through an external API.

I suppose they all work very similar, but I have just integrated my shopping cart with the API from IPInfoDB.com. How it works is explained below...

A word up-front, though: When using third party APIs - think! Do you really need to hit the API with every page request? Especially in this case, would it not be fair to assume that the whole sessions would be coming from the same IP and therefore the same country? To an extend, could you not assume that it is one user you are tracking here and that he would probably come back to your site from within the same country, even though his IP might have changed? Could you therefore store the result from the API in a browser session or in a cookie?
- I actually do store it in the DB per cookie, but that's not important for this little tutorial.

First up, you will need to have access to the API, so you need an API key, token-code or something to identify yourself with the API. On the IPInfoDB.com site you can register and receive your free key within seconds.

Got the key? - off we go then: Thankfully this is a pretty simple API that doesn't use SOAP, but requires a simple HTML request and returns a nicely formatted XML. Here is a result:

<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Status>OK</Status>
<CountryCode>GB</CountryCode>
<CountryName>United Kingdom</CountryName>
<RegionCode>P9</RegionCode>
<RegionName>Windsor and Maidenhead</RegionName>
<City>Hillingdon</City>
<ZipPostalCode></ZipPostalCode>
<Latitude>51.5167</Latitude>
<Longitude>-0.45</Longitude>
<Gmtoffset>0</Gmtoffset>
<Dstoffset>0</Dstoffset>
<TimezoneName></TimezoneName>
<Isdst></Isdst>
<Ip>217.42.247.86</Ip>
</Response>
So far so good... Let's create a corresponding PHP class that will make the usage easy portable to different projects.


  1. I create a class and bunch of variables and add getter methods to the class, so I can return the variables when I need them:
    class geoIP {

    var $apiKey = "XXXXYOURKEYHEREXXXX";
    var $city;
    var $country;


    function getCity() {
    return $this -> city;
  2. Now I know that API key will be available when I initialise the object. Moving on to making a call...
    It's quite easy in this instance, because we don't need to set SOAP headers or anything. It's a simple API and all information we need to give IPInfoDB can be parsed into the request URL. Here is how it looks:
    http://api.ipinfodb.com/v2/ip_query.php?key=YOURKEY&ip=IPTOCHECK&timezone=false
    So I create a method, let's say, "makeCityCall" that I can then send the IP to check to:


    function makeCityCall($ip) {
    $urler = 'http://api.ipinfodb.com/v2/ip_query.php?key='. $this -> apiKey .'&ip='. $ip .'&timezone=false';
    The "$this -> apiKey" will return the API key that we declared and initialised as a global variable for this class. The "$ip" is what I send to the method.

  3. I know when I load this URL, I get an XML response. XML is best parsed via a DOM-parser. The DOM parser comes standard with most versions of PHP and is an object in it's own rights. We have to instantiate this and can then give it the URL we declared ($urler) to load:
    $parser = new DOMDocument();
    $parser  -> load($urler);
  4. As we saw by the result returned above, the interesting bit is wrapped in a XML node called Response. We only get one, of course, but I will still ask the DOM parser to repeat the process of getting the values from all nodes that it finds:
    $nodes = $parser -> getElementsByTagName("Response");
    foreach ($nodes as $node) {
    I now want to get the values of the nodes contained within the Response node:
    $cc  = $node -> getElementsByTagName('CountryCode');
    $cc =  $cc -> item(0)->nodeValue;
    $this -> countryCode = $cc;

    $cty = $node -> getElementsByTagName('City');
    $cty = $cty -> item(0)->nodeValue;
    $this -> city = $cty;

    $ctry = $node -> getElementsByTagName('CountryName');
    $ctry = $ctry -> item(0) -> nodeValue;
    $this -> country = $ctry;
    Thus setting the variables that I later want to retrieve via the getter methods.

  5. Lastly, if I now want to make a call from a PHP application, I simply need to instantiate the new class, get the IP address from the site visitor (or from wherever) and use the method to make a request. I can then retrieve the results from the getter-methods:
    $ip = $_SERVER['REMOTE_ADDR'];
    include ('PATHTOPHPFILE/geoIP.php');
    $gIP = new geoIP();
    $countCall = $gIP -> makeCityCall($ip);
    I can then write this out onto the page or re-use it as I wish:
    echo $gIP -> getCountry() . '<br />';
    echo $gIP -> getCity() . '<br />';
    echo $gIP -> getCountryCode() . '<br />';

I hope this gets you further...

Friday, 21 January 2011

Java Swing GUI builder for Eclipse

I often struggle to make Swing applications to look good, or even make them vaguely look like I intended. The different JFrame layout options and all the coordinates of where to place what and how long is that makes the creation of Swing interfaces difficult.

Since I don't like using different development environments and got very used to Eclipse for anything I need to do, I was looking for a good graphical GUI builder that works as a plugin for Eclipse. I came across this really nice one: Jigloo from CloudGarden.

It's pretty easy to install into Eclipse, via update site: http://cloudgarden1.com/update-site and then creates GUIs by drag and drop in a way that I thought wouldn't have been possible. The commercial use of this product is prohibited without license, but this shouldn't stop any hobby programmer, much like myself, from using this great product.

Here is a screenshot I leeched off their site (I might attach one or two myself):

Enjoy

Friday, 7 January 2011

Bear?

From: d3ngar
To: bear
Subject: Bear

Message:
Wow, Bear!

What a nick - what a movie...

You might not know this, Bear, but there is a movie with the same name, Bear, that came out last year. You might have guessed: it features a bear, named Bear...

You might wanna check out Bear, the movie, it's really great : http://www.imdb.com/title/tt1468703/

Best Regards,

d3ngar
d3ngar.blogspot.com

Wednesday, 5 January 2011

BadgerComp / Cart & Opilion

Anyhow, so I decided to start using the Java code from Opilion for crawling tasks for BadgerComp.com.
I probably will continue building on the image getter first. I'm thinking that you will want to upload them straight somewhere. Probably via FTP. Or you could download them to your local hard disk first.

I'll probably make the tool available via the BadgerCart Wiki, but it might be getting annoying to enter the user details all the time. Maybe I need to be able to load settings via XML?

where did all the social shopping go?

Maybe two years ago, when I was still working for an eTailer, "social shopping" became kind of the new buzz-word around town.

Social networking needed to be adapted into everything and, with women being the most active shoppers and gossipers, the connection of social shopping - a way of sharing your online shopping experience with friends - was an obvious one.

Many marketeers just assumed that women would happily sit in front of their computers at home, have a cup of tea and combine shopping with chatting to their best firend, whilst not having any worries at all.

I don't doubt that there are people like that, but it never took off and I doubt it will. The reason is that online shopping is simply fast, easy and anonymous. No standing in line, no filtering through piles of clothes, no need to have a coffee and stretch your legs. So why would you want to take a friend along?
Sure, the do-you-think-this-looks-good-on-me question is still something that you'd like to have answered, but that answer must come pretty much immediately and who can expect their friends to lurk on the social networking site ready to pounce on your "Can I wear this?" - question with a definite yes or no answer.

It won't even start working if you'd pay your visitors for such free PR and back-linking, because how much (net-revenue) have you got to give that you can incentevise links and make a margin?

Anyways, I think I will build and affiliate scheme onto BadgerComp, simply so that the Cart has everything :)