YamdaBlam!

Technology

PHP matching url to a domain using parse_url

by Jay on Sep.02, 2010, under Technology

Purpose:
My purpose is for a URL forwarding system whereby I need to ensure that
the target of the URL forward doesn’t match the domain the forward is being applied to.

// Take in the domain and the target url
$target=trim($_REQUEST['target']);
$domain=trim($_REQUEST['domain']); // always in the format domain.tld

// Use parse_url() to get an array of the various parts of the target url
$arTargetUrl = parse_url($target);

// Since were only interested in the host part of the url
$host = $arTargetUrl['host'];

// Break the target up into an array based on the “.” dot
// www.url.ie becomes array(‘www’,'url’,'ie’)
$arTargetHost=explode(‘.’,$host);

// Now get the size of this array
$sizeOfArray = sizeof($arTargetHost);

// Since we’re only interested in the url.ie part of the host
$newHost = $arTargetHost[$sizeOfArray-2] . ‘.’ . $arTargetHost[$sizeOfArray-1];

// Now compare the the newHost to the domain.
// If they’re different carry on applying the url forward
// otherwise, stop.

if($newHost != $domain) {
echo ‘yay! all good’;
}
else {
echo ‘boo.. old man shouts at cloud!’;
}

Leave a Comment more...

Augmented Reality Layar Submitted

by Jay on Aug.23, 2010, under Augemented Reality, Technology

Further to my previous post about augmented reality and Layar, I have developed a small Layar for the Donabate and Portrane area. It basically will list all the business and tourist spots in the area. Pending approval I will be putting the remaining number of businesses and highlights of the area on to the layar with a view to having a Google map submission tool on a subpage of yamdablam.com in the very near future. So for those residents of the peninsula who have a GPS enabled smart phone, you’ll be able to view Donabate and Portrane area like never before.

So, fingers crossed the good people of Layar in Amsterdam approve the new layar for the area!

Leave a Comment :, , , , , , , more...

PHP – first day of the current month

by Jay on Aug.20, 2010, under PHP

A really quick post mainly for myself, because I will need to remember this at some stage in the future

$startDate=date(“Y-m-d”, strtotime(date(‘m’).’/01/’.date(‘Y’).’ 00:00:00′));

Enjoy!

Leave a Comment :, , more...

Augmented Reality and Layar = Exciting times.

by Jay on Aug.17, 2010, under Augemented Reality, Technology

I’m very excited for a number of reasons.

I recently got myself a shiny iPhone 4 and since I upgraded from the 3G I have a whole host of new features to play with. The one that got my attention most was the possibility of using some of its great GPS and navigational functionality. Enter, Layar, the augemented reality browser, downloaded from the Apple App Store.

To put it simply, I was blown away by this application. My mind was racing with ideas and to be frank, any excuse to get a layer of my own onto this service. The first thing that I noticed that there was a startling lack of augmented reality layars for my local area. The layers that do exist for Dublin are great for example, the daft.ie property search layer, but none the less they are few and far between.

After reviewing the API documentation and putting together a test layer, I developed a layer for Donabate & Portrane and submitted this for publication on the Layar platform. I hope to hear back from them within 5 working days. (Watch this space) In the meantime, I will be continuing to add places of interest (POI’s) to the DonabatePortrane layer in the coming days and weeks. Dump a comment and let me know if you want any thing in particular on the layer and I’ll be happy to accommodate!

I am 100% sure  I will be posting about this in the very near future – and you never know, I might even be helping you get a layer in place for your business or area!

1 Comment :, , , , more...

Getting GPS Data out of your images

by Jay on Jul.21, 2010, under PHP, jQuery

Privacy is important

Your privacy is a big deal. Be it in the physical world or in the virtual world. The unfortunate thing is that because browsing the web can be done in solitude, personal privacy tends to be an after thought. Not too mention that nearly everybody in the western world has access to an internet connected device.

When you take a photo on one of the latest digital cameras, or from a smart phone and if the device has GPS functionality, it can be assumed that the photo has been tagged with the location of where it was taken. This information is stored in a data format call EXIF. You can read all about it here and here.

It is not a huge leap of the imagination that if your photos are published on the internet ( which is public and not private ) that you are enabling others to track your movements without your expressed informed consent. This information can be used against you aswell as for you. The question should arise of how to manage your online profile. I will cover this topic in a later post.

GPS Data

Photo location is encoded using the Global Positioning System. This is a network of satellites orbiting the globe which return positions of devices which request it.  If you would like to know more about this see here.

Do your uploaded photos hold GPS data?

There are loads of web apps out there that will answer this question for you. In the spirit of DIY and because I like to program, I decided to put together my own image information parsing system. You can see it in action here. This basically reads the EXIF data from an image supplied via a URL to the image in question.

Next steps…

As you see from the lab, the system generates a link to the search page on http://maps.google.com/ When time permits, I will add a Google Mapping feature which will display the position from the image on a Google map. Watch this space.

Demo

This little web app is built using the ExifReader.php class from quiteless.com. You can get it here. It is an elegant PHP class which is now part of my library. Thank you Steve! (quiteless.com)

As always, feedback and comments are more than welcome!

Enjoy!

Leave a Comment :, , , , , , more...

Cannot use object of type stdClass as array

by Jay on Jul.19, 2010, under PHP, Technology

Problem

I was getting this particular error when decoding JSON data block from a web service.

It basically is trying to assert that the data block is a different type to the variable which it is being assigned to.

Meet solution

Explore the data dump by using something like

echo ‘<pre>’;  print_r($dataDump); echo ‘</pre>’;

and you will see the different data types for example:

stdClass Object ( [acc] => Array ….

Drill down through the structure to the data you want and check the data type of it. To prevent this error, simply apply some Type casting during the variable assignment. Bada-bing… problem, meet solution.

1 Comment :, , , , , , more...

URL Shortening on your site

by Jay on Jul.15, 2010, under API, PHP, Technology, jQuery

A nice feature to have on a site would be that of a URL shortener. I’ve looked at some of the more popular ones and decided to play with the API of the most popular, http://bit.ly.

I selected bit.ly as it is the most widely used, your account can be integrated with your Twitter client (Twitter for iPhone for example) and most impressively, you can get real time statistics on the shortened URL’s you create. This would be very useful for those companies who wish to track their marketing campaigns running on their website/twitter/Facebook accounts.

In the spirit of exploration, I’ve created a simple PHP bit.ly class, called bitlyApi.class.php.

To get up and running with this, I first created a new bit.ly account and copied out the API key they provide. Once you create an account, you will have access to the realtime statistics feature, otherwise you’ll just get the bog standard URL shortener service.

The bit.ly API is really straight forward. Have a look at the previous link to see what you can do.

Taking the most obvious function, URL shortening, the class simply takes in a valid URL, puts together the API request and sends it along with my username and API key and in return a JSON encoded string.

Download the sample code and have a look here at the live demo.

Note, that the code supplied is not production ready. I would need to have your usual input validation etc..

Feel free to comment!

Leave a Comment :, , , more...

Recall on the cards for iPhone 4

by Jay on Jul.13, 2010, under Technology

It doesn’t surprise me. Apple has not been performing well for me  or some friends lately.

Shortly after its release, punters started reporting the problem. Apple denied it.

Then a memo was release informing employees how to handle complaints about it. A.k.a damage control.

Now Consumer Reports has done a u-turn and is not recommending the phone until Apple put a permanent and free fix in place.

Ouch.

How does Apple respond? Why, it deletes discussion reports on the contentious issue. Job well done. (Excuse the pun!)

So, is a recall on the cards? Some say it is ‘inevitable’.

I’m not impressed with Apple of late. I own a iPhone 3G and had recently updated the OS to iOS4 and have had nothing but problems since doing so. The same problems have been reported by my wife and she is due to downgrade the OS like I did yesterday. By the way, if you want to do this too for similar reasons, here is a great tutorial from the folks over at Lifehacker.com

Since downgrading, the problems (network connection loss, unresponsiveness) have ceased to be an issue. I am now running OS3.1.2 and all is good!! Looks like 3G does not have the hardware spec to handle the new features which iOS4 has to offer. Or, on the other hand, maybe some lazy coding is the reason. I would say both.

Since buying a Macbook last year, I’ve bought a number of other Apple products and this is the first time having serious problems with their stuff. Get the act together Apple!

- Update: 15th july

Looks like Apple will be holding a press conference on the matter on the 16th to address the issue.

Leave a Comment :, , more...

When ‘mv’ fails you

by Jay on Jun.02, 2010, under Technology

Very handy linux command I keep forgetting so here it is:

Scenario:

You need to move a few thousand files from one directory to another on a linux server. The mv command gives the following complaint:

“Argument list too long…”

You can use this bad boy (assuming you are in the directory containing the files you want move):

find . -type f -name ‘*’ -exec mv {} $newdir/. \;

Wait a few seconds and list the contents of the directory to see that its now empty. Check the contents of your $newdir to see if the files have moved.

Leave a Comment :, , , , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

 

Archives

All entries, chronologically...