Author Archive
Capturing echo output and storing it in a variable
by Jay on Jul.06, 2011, under PHP
Working with legacy code somethings throws up little eggs that need to be cracked.
For instance, I need to use a function which is generally called via the browser and instead of using return statements, it uses echo.
This post shows you how to deal assign echo statements into a local variable by using output control.
ob_start();
helloWorld(param1, param2);
$capturedVar = ob_get_contents();
ob_end_clean();
The echo from the function helloWorld() is now stored in $capturedVar for use!
MySQL – Removing duplicate rows from a table
by Jay on May.19, 2011, under MySQL
This save me loads of hassle this morning as I ran my script which populated an important table with duplicate entries which should not be there.
This is a must share for those who fall into the same problem.
Open up a mysql editor and paste in the following (don’t forget to edit for your table names)
CREATE TABLE new_table as SELECT * FROM old_table WHERE 1 GROUP BY [column to remove duplicates by];
Drop the old table and rename the new one – job done!
Quick, easy and slightly painless.
Getting Rid of Distractions
by Jay on Mar.22, 2011, under Human
Here are some of my tips for dealing with distractions when trying to get work done. I hope you find them useful!
Shut off the outside world
Close down all rss apps, twitter, facebook , email etc.. these are not your friends when trying to get work done. They’re designed to keep you on the site with little popups saying there are new updates or messages to be read. Once they’re open, you will find yourself checking the page often, very often. So kill those when you need to get stuck in.
Plan your attack
Turn your back on the screen and take out some pen and paper and actually write down or draw what you want to achieve. This will have the effect of forcing you to think about what you need to accomplish.
Create Mini Tasks
Break down the task into mini tasks and put these into a todo list. Put this on paper as a physical list is way better than a virtual one. You’ll be able to track your progress by this. This will act as a positive feedback loop which will help with momentum.
Impose a deadline
Apply a strict deadline and stick to it. This will give you a sense of urgency to the tasks at hand.
Carrot and Stick
If you meet the deadlines, give yourself a reward!
Say ‘No’
If others approach you requesting some of your time, just say no.
Do you have any tips for getting rid of distractions in order to get work completed?
PHP Looping through a range of dates
by Jay on Sep.10, 2010, under PHP
Problem:
You need to get the individual dates in a date range and store them in an arbitary data structure such as an array
Solution:
$endDate = date(“Y-m-d”, strtotime(‘yesterday’));
$startDate = ’2010-08-01′;$newDate = $startDate;
$arRangeOfDates = array();
while($newDate != $endDate) {
$newDate = date(‘Y-m-d’,strtotime(date(“Y-m-d”, strtotime($newDate)) . ” +1 day”));
$arRangeOfDates[]=$newDate;
}
The Surprising Truth About What Motivates Us
by Jay on Sep.09, 2010, under Human, Technology
Google’s Eric Schmidt posted this on his twitter account and I liked it so much, I decided to post it on yamdablam too.
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!’;
}
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!
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!
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!
Getting GPS Data out of your images using PHP
by Jay on Jul.21, 2010, under jQuery, PHP
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.
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!