All posts by mehdihs

Getting Geolocation details and then using them to extract 1 Groupon Deal

Recently I’ve been trying out for a variety of roles and on a recent one they sent me a questionnaire with two PHP challenges. The first one, given here, asks us to use a web service to get a users Lat and long based on their IP and then use this to query groupon for 1 deal in their location. The format of the query will be in the fom of a GET variable called ip={THE USERS IP} for example

The result should be an XML file. I’ve solved the bulk of it below, but I still have to figure out how to respond when you have no deals found.


	$location = file_get_contents(''.$_GET['ip']);
	$lat = $ip_json&#91;"latitude"&#93;;
	$long = $ip_json&#91;"longitude"&#93;;
	if(strlen($lat)>1 && strlen($long)>1){		


		$gr_string = file_get_contents($groupon_url);

		$title = $gr_json["deals"][0]["title"];
		$desc = strip_tags($gr_json["deals"][0]["pitchHtml"]);
		$disp_url = $gr_json["deals"][0]["dealUrl"];
		$clk_url = $gr_json["deals"][0]["options"][0]["buyUrl"];

		//-----THIS GENERATES THE XML-----------//

		header('Content-type: text/xml');
		header('Pragma: public');
		header('Cache-control: private');
		header('Expires: -1');
		echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
		echo '<xml>';
		echo '<results>';
		echo '<title>'.$title.'</title>';
		echo '<desc>'.$desc.'</desc>';
		echo '<display_url>'.$disp_url.'</display_url>';
		echo '<click_url>'.$clk_url.'</click_url>';
		echo '</results>';
		echo '</xml>';
		echo "Could not resolve the ip into lat and long";
	header('Content-type: text/xml');
	header('Pragma: public');
	header('Cache-control: private');
	header('Expires: -1');
	echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
	echo '<xml>';
	echo '</xml>';

My Flash Animation

I used to be a huge fan of Flash and ActionScript. Infact I loved ActionScript, but even back then I knew that it was a dying technology. But I had a ton of fun doing animation with flash.

Here is a small animated clip I did in flash. Its stupid and its silly, but I’m kinda proud of it. I just wish I had better sound, i was just working on a cheap web-cam mic. Alas. I especially love the lip sync work I did. It was painful but I think the pay-off was worth it. Its not Pixar but its MINE. 

Continue reading My Flash Animation

How to create a Captcha with PHP GD library.

The “Captcha” idea is brilliant. While they are not totally foolproof (certain Universities have successfully been able to create software that are able to hack captchas), they provide a decent bit of protection from spam activity. The recaptha tool that many of us have seen on various sites on the web is a particular favourite of mine because apart from the added protection it also allows the crowd-sourcing of data via this small action. Currently I’ve seen two variations of this crowd sourcing. One to digitize books, so you’ll be shown a word that the Google OCR engine was probably not able to recognize and then you help them know what the word is, and the other one I’ve seen is the house numbers of Google Maps Streetview, which would probably give them more the ability to more accurately pinpoint addresses in their Maps. Below I’ve included two files that I’ve used to create a very basic captha module using PHP’s GD library. Continue reading How to create a Captcha with PHP GD library.

What is the difference between “Verification” and “Validation”?

Verification answers the question “Am I building the product correctly?” i.e. Does the product do what the requirements said that it should do. Verification is a low-level activity, done by testers and developers mostly, and performed during development on key artifacts, like walkthroughs, reviews and inspections, mentor feedback, training, checklists and standards. It is a Demonstration of consistency, completeness, and correctness of the software at each stage and between each stage of the development life cycle.

According to the Capability Maturity Model(CMMI-SW v1.1) we can also define verification as the process of evaluating software to determine whether the products of a given development phase satisfy the conditions imposed at the start of that phase. [IEEE-STD-610].

Validation answers the question “Ami I building the right product?” i.e. Does the product being built actually fulfill its intended purpose and meet the client’s needs? Validation is done at the end of the development process and takes place after verifications are completed. It is a High level activity, performed after a work product is produced against established criteria ensuring that the product integrates correctly into the environment.

According to the Capability Maturity Model(CMMI-SW v1.1) we can also define validation as The process of evaluating software during or at the end of the development process to determine whether it satisfies specified requirements. [IEEE-STD-610].

Kebsah with Lamb Shanks

Did I mention that I was a massive foodie? Well I don’t just like to eat great food buy love to cook too.

This was a dish I made called Kebsah with Lamb. The basic difference between Kebsah ( which is a middle eastern dish) and biryani is that Biryani has a yogurt base, while Kebsah has a tomato-base.

This was my first attempt at making this dish and it came out quite wonderful. I worked of a few recipes and figure out how to adjust the flavors myself.

Continue reading Kebsah with Lamb Shanks

My Drupal Site

February 2016 Update: I’ve taken this down and am hopefully going to do a full redesign.

I have been trying to learn Drupal on and off for a while, and now I finally have a decent project to work on. I have a small library of about 400+ books which I plan to catalog on this site so yes this is a very personal project. Its definitely a work in progress and I simply love the robustness of Drupal 7 as well as its new admin section. I am using the newly incorporated Fields module ( I think it used to be CCK before it got incorporated into Drupal core), I have custom taxonomy and a have integrated the WYSIWYG module for formatted text editing. Currently I am in the works of getting all my books listed in a spreadsheet and then I’ll upload them all (I have to see if batch upload is possible). I’ll then theme the site to my liking.

Technologies used: Drupal, Photoshop

In Selenium what is the difference between “Assert” and “Verify”

When you have a series of test cases in a script using an “assert” will halt the test run when it encounter a failure. On the other hand with a “verify” command it will continue to run and log the rest of the tests regardless of failures.

So the choice really dependent on the function you are testing. For example, if you have an email submission form and you want to test that the data verification module works for each input then you can test each input and just return the fail/pass results. Here you will use a verify statement.

But if on the same email submission form if you are testing the email submission functionality then if the first field, lets say, First name is not functioning properly then there is no point in testing the rest of the submission process, Here you will use an assert.

In practice however you use a combination of both. The Selenium documentation gives details of how this is done here.