A quick PHP example; how to implement an Enum. PHP lacks this useful feature so this is a bit of a hack to emulate an Enum.
Example below with an example of usage;
A quick PHP example; how to implement an Enum. PHP lacks this useful feature so this is a bit of a hack to emulate an Enum.
Example below with an example of usage;
A useful, perhaps, class for database connections using the PHP PDO library: PDOConnection.php
Singleton implementation with the class method getConnection() returning a \PDO connection with connection details;
Recently uploaded some more photos from the latest holiday in Borneo; I have used some of the effects in Picasa in an attempt to enhance some of the photos! The full gallery is here.
My photos from Borneo holiday have been sorted out and uploaded so check them out or on Google+.
I have to say that it was one of my favourite holidays; this being down to a few things such as this area of Malaysian Borneo being a wonderful country, lovely and friendly people and the activities and experiences had there were fantastic. The country was beautiful (mostly; see below) and it has everything from coral reefs around the coast, through dense jungle rainforests to high mountains – every type of terrain and I had the pleasure to see examples of them all. As I travelled through their country I was welcomed everywhere, not because of money but just because I was there – this is rare thing these days, enjoy and cherish it where you can. We were given help and advice in many situations for no reason other than the generosity of the people there – many countries, UK included can learn a lot from this positive, friendly atmosphere.
In our time in Borneo we managed to fit a lot of varying experiences in, through good planning and a lot of travelling these all came off without a problem. Not the most relaxing of holidays but worth when you consider we climbed a mountain, trekked through proper jungle and crammed in 13 dives, some of them often voted in the top 5 dives in the world. Proud and pleased to complete everything and survive!
<Rant>
OK, if the holiday was as perfect as it sounds then something would be wrong with the world – the downside I saw in Borneo was that the rest of the world has and still is taking advantage of Borneo and destroying it.
Rainforests are being cut down to make way for Palm Oil plantations; vast areas of rainforest is cut down every year and millions of palm trees go up in its place. You may think that these are vegetation too and what’s the problem? Well, its very well documented elsewhere what the problems are with this; wildlife is displaced by chopping down the rainforest, they cant live in palm trees, lots of chemicals are used on the plantations both on the crop and in processing the seeds into oil. Anyone who thinks palm oil and biofuels (produced from palm oil) are OK is wrong, they are destroying parts of the world while other parts of the world just keep using more and more – i’m looking at you USA and China.
The seas and fishing; wildlife in the seas isn’t faring any better than that on land, large scale, corporate, unsustainable fishing is sweeping the oceans clean and at the same time small scale local fishermen are doing whatever they can to make a living. This is often catching endangered species because they sell for a lot of money or fishing with dynamite or chemicals in order to catch more because they are forced to sell at low prices due to the large scale fishing. Fishing, and any other type of farming is OK if it is sustainable – it rarely is though.
</Rant>
PS. Visit Borneo!
When I first went travelling an Internet connection was not too common, a working Internet connection even less so but here I am in a (reasonably) remote part of borneo typing this in a cafe on an iPad! How times have changed! I used to frown upon backpackers with over exuberant technology, it was a target for thieves, unnecessary luggage and I never took anything that couldn’t be replaced half way round. But I have swayed ands and the pad has become an important backpacking essential now!
So, I am in Borneo and the challenge has not been Internet connections, these have popped up everywhere, often in the most unexpected shops, cafes and hostels. The challenge has been fitting everything in that we planned and the rain! We are halfway through the holiday and it has been hectic but worked out OK so far having started with a day of luxury in Singapore – I broke the law here by bringing in chewing gum but luckily was not caught. We have now made it almost to the the final place in Borneo; Palau Mabul – an island off Semporna on the north east Malaysian district of Sabah.
We have travelled from the west coast city of Kota Kinabalu to here and crammed in a lot in the week; have climbed 4095 metres of Mount Kinabalu, visited Orang utan sanctuary, been on river safaris in the jungle and got wet. It seems the wet season lasted a bit longer and it rains at random inconvenient intervals but at least it’s warm rain, and not snow.
Next up is a few days diving in one of the worlds top scuba diving spots with turtles, rays and sharks common before a trip back to Singapore and then home. Will have to get rid of that illegal chewing gum first.
A preliminary article here about a current project I have resurrected recently; IPAC – IP Addressing and Connectivity management application.
It is a web based application backed by a database to manage an organisation’s network focussing on Host connectivity and IP addressing. The reason this application exists is the lack of an existing equivalent; a while ago during my time working in a Network Operations team I spent a some time searching for decent applications to manage our IT infrastructure including everything from switches, routers, servers to management equipment. There were several almost suitable applications but nothing that concentrated on how your host was connected and it’s interface’s IP addresses were managed and that which also fitted our workflow, allowing a host to be created and allocated an IP address.
We needed something that managed the host / IP address / network switch relationship, in the IPAC model a Host entity has many Interfaces, these are physical or virtual interfaces such as a NIC on a server. These Interfaces then have IP Addresses which are part of a Subnet which in turn is allocated to a VLAN. All these entities then sit under one site, therefore allowing you to manage multiple sites of distinct or connected networks.
IPAC; the application is still immature and in the early stages of development but it is truly open source and I welcome contributions – this, I believe will allow the application to grow and improve. I have released the project on github.com and under the GNU General Public License, anyone can take my code and use it, improve on it, etc but just don’t try and make some money without recognising my work.
Here are some of the features available
To use this software you need to build and run it – more details coming up but basically just a few things:
You can use, view or contribute to the IPAC.
The IPAC is currently in early development, it does build and work just with limited functionality but I will be working on the IPAC over the next few months and hope to get a working demo available soon.
Do not use the Xcode automatically generated Prefix headers (.pch) file and the preprocessor for constants, configuration, environment settings, etc – The name gives away its purpose, it is not called Prefix headers and configuration settings. Best practice; if you have to share constants between classes then create something like a Constants class by subclassing NSObject and store any constants or settings there and then use the Prefix header file to import that class – stay in Objective C or C.
I have recently seen an iOS project with a Prefix headers file containing 400 lines of code, 10 preprocessor if statements with a maximum depth of if statements of 3.
A better idea would be to go back to Objective C land and use static const to define your constants – here the static part sets or limits the scope of the variable to that compilation unit, think class, method. The const tells the compiler not to let anything change it.
If the constant is only used in one class then why not keep the constant in that class? Make it easy for someone coming in to work on your code by keeping related items together, its likely they will be jumping about around over class files anyway so help them out a little by reducing one switch to the .pch file.
BTW; Don’t forget to follow Apple’s coding guidelines for naming conventions!
If you need something across the project then create a class to define them, subclass NSObject and implement the constants. Then use the prefix header for what it is meant for by adding the import statement to every class.
The BBC have released results of a survey undertaken in 2012 involving 166 clubs in 10 divisions across British football, including the Conference Premier and Women’s Super League gathering the prices for the most expensive, and cheapest, season tickets and adult matchday tickets along with a programme and some say, most importantly a pie and tea. The results have been published on the BBC website but I notice two problems;
I have grabbed their results and geolocated all 166 clubs, this then enables you to plot the data on a map (in this case via Ordnance Survey OpenSpace) as I have done in my app.
So what do the results show? There has always been talk of a north/south divide in football, and indeed GB in general but the results show that this is not the case, yes the most expensive tickets are in the South but the North has its share too. I think basically the ‘big’ clubs charge big money no matter where they are, now if you could also quantify and display value for money then that would be a useful graphic.
For football fans, I suppose one use of this map could be to decide where you will watch your football, you could find the cheapest clubs around you and then decide where you part with your cash. Just because ‘big’ clubs charge so much for match tickets and related items doesn’t mean you have to pay it in order to view live football.
@datasource: via Google Docs
The Twitter hashtag #OpFortress refers to Operation Fortress, a Hampshire Police operation to reduce crime in Southampton. The police force have been Tweeting about it, reporting updates, arrests, raids or crimes – with road names in the Tweets. Road name = location data… Location data = mapping visualisation. An ideal method to visualise where the police are working in Southampton would be to plot these tweets on a map, all you need is location data.
13 arrested in 5 #OpFortress raids in #Southampton yesterday on Northbrook Road, Atherley Road x2, Kern Close and Nelson Road
— Hampshire Police (@HantsPolice) July 12, 2012
View the map
In order to visualise this unstructured data as the map above, there were a few operations of my own I had to step through so that I could plot the tweets correctly.
Code:
Here is a SQL script to load OS Locator data into MySQL MyISAM table with Full Text index.
As an update to a previous post about Mr Correcter, the Twitter spelling bot here is a post about how I managed to find and geolocate so many offenders. Quick update; Mr Correcter was a script that searched Twitter for 2x common spelling mistakes (beleive and acommodate) and replied back to the tweeter reminding them of the spelling mistake.
Stats:
I wanted to geolocate the offenders to generalise which part of the world was the worst at spelling, at least on social media anyway. I previously guessed America due to the number of replies back to Mr Correcter (see previous post for some amusing ones) and as you can see from the map, this turned out to be true.
How I gathered this information
I used three methods in this algorithm to identify where (lat, lng) these Tweets (or accounts) orginated;
if( the tweet has geolocation data available ){
then use this
} elseif ( the user has geolocation data available on their account ){
then use this data
} elseif ( the user has a location string set and this can be geolocated ){
then use the geolocation of this
} else {
unable to geotag the tweet
}
The obstacles were the Twitter API, getting some of this data is restricted to hourly limits so I had to use a cronjob to schedule the script and aggregate the data after completion.
The script I used is openly available.