From the deep

Categories

Jul 11

An introduction to PDO: The basics and benefits

MySQL is/was deeply integrated within PHP. No doubt you have seen and used the mysql_*() functions at some stage, but there is an alternative that makes your database interactions much more reliable. It’s called PDO (PHP Data Object) and here’s a quick guide that should get you up to speed in no time at all. [...]

 

Jun 29

Update: Reversi board game in PHP and Javascript

I like playing the occasional game of Reversi, and thought it would prove to be an interesting project (creating something like RedHotPawn for chess). Several hours programming later I had a simple working prototype. A couple more hours later I added in some missing features and smartened everything up. Demonstration and Download To view a [...]

 

Jun 20

StackOverflow challenge: Replicate (almost) HTML text-align justify

Quite an interesting little test, I thought. Has zero practical world application, but it does require the person to have a somewhat analytical mind and problem solving skills. Also a reasonable knowledge of PHP. So I thought I would have a go (without looking at others’ solutions). 10 minutes later a working script which does exactly what was requested.

 

Feb 10

PHP Unit Testing: Test your code like a pro

Running through a website checking for errors is time consuming. It’s also boring and prone to human error. Unit testing has been around for years and is a much faster and reliable way to test for errors.

 

Sep 5

Amazon S3 batch uploading + upload stream

It was hard to track down if these two features were possible with the latest Amazon S3 SDK, but they are and have documented them for you below.

 

May 25

Simple PHP Encryption and Decryption

The need for encryption and decryption in general day-to-day Web programming is quite rare. But it can crop up from every now and again. I use a class that handles both encryption and decryption using mcrypt and the Rijndael algorithm (AES) and a 256 bit key size.

 

Mar 13

PHP autoload: The Good, the Bad and the Ugly

The autoload function is one of my favourite aspects of PHP. I’ve even blogged about it before. It makes writing code quicker and more reliable (no more typos or worrying about whether you forgot to include a class file) giving you more time to actually program.

 

Dec 5

CSS Variables and why you’re doing it wrong

I can’t browse the Internets these days without stumbling into some new fang-dangled state-of-the-art CSS-parsing-framework Web 2.0 (beta). And every time I see them I cringe. And to be honest they’re normally written in Ruby. Which answers a hell’uva lot of questions.

 

Sep 26

Design Pattern II: Factory

As you might have grasped from the name of the pattern its role is to produce and dispatch a product. In this case a classes. We use the Factory pattern as it is a standard way to create a class which is very similar to other classes by containing the same functions, but implemented in a different way. I always like to use non-technical terms when explaining, and this example will be no different.

 

Aug 24

Cookie replay attack protection

So let’s jump straight in, what is a replay attack? Essentially a security breach whereby someone poses as someone else using some unique piece of data the user supplied/was issued to/from the Web server. It’s kind of similar to a man-in-the-middle attack. We’re going to be looking at the attack using specifically cookie authorisation, a very common means of implementing a “remember me” function.

 

Aug 2

Defensive programming

Earlier in the week, whilst implementing a domain registration API into another client project (and pulling my hair out), I thought back to a seminar from university. The module was Component Based Design and it was all about writing code in a standard way, helping to aid both the supplier (API creator) and the client (the person using the API). Although I didn’t realise it until now it actually played a large role…

 

Jul 12

PHP __auoload

PHP5 reared it’s head mid 2004, 5 long years ago and all PHP developers rejoiced. Especially me. It gave us lots of new shiny tools to play with, including the obvious improved OO support and my particular favourite: the __autoload function. For all you Java developers out there you know that you never have to include or require files, the Java language instinctively knows where to find them thanks to the…

 

Apr 2

PHP class: SimpleXML

One thing I have found is the lack of really simple XML classes—that’s not to say there aren’t any good ones out there, I have used several really cracking ones. For my new version of my personal site (yes, this site is planned for a revamp) I wanted to integrate my Twitter feed somewhere. I looked and looked for a really simple XML class but was unable to find one. So I made one. And here is the result:

 

Jun 28

PHP class: Text to anything

I recently had a client who sent me a 300+ list of items they wanted placing into a drop down select menu. Beside the obvious accessibility issues they were quite set in their ways about what they wanted—per usual.

 

Jun 26

Design Pattern I: Singleton

In this first episode of PHP design patterns, we will be looking at the Singleton. The Singleton is available in most, if not all, OO languages. The purpose of the Singleton is to only ever have 1 instance of a class available which supplies the rest of the application with consistent data. I would like to point out that my version of a Singleton may differ slightly from other peoples; design patterns are not exact nor are they set in stone.

 

Jun 19

phpSimpleAuthent

I was browsing a couple of PHP forums the other day, and it seems people require a simple authentication script for their website. So, I thought I would make just that.

 

Jun 11

Magically dynamic PHP

There are several functions in the PHP language which were made to make classes more accessible and dynamic. I am going to be talking about two of these so called “magic functions” which allow you to set and get information dynamically, whilst also providing a simple log to show you what is really going on behind the scenes. These two functions are of course __set() and __get().

 

Jun 8

PHP exception handling

Arguably one of the best things to come out of PHP5 was its improved OO support. With OO comes easier separation of presentation, data, and business logic layers which leads to reusable code and better code management, amongst a host of others.

 

From the journal

From the deep

Obligatory links

jQuery plugin: JustGage

JustGage is a handy JavaScript plugin for generating and animating nice & clean gauges. It is based on Raphaël library for vector drawing, so it’s completely resolution independant and self-adjusting.

Javascript: URI.js

URI.js is a javascript library for working with URLs. It offers a “jQuery-style” API (Fluent Interface, Method Chaining) to read and write all regular components and a number of convenience methods like .directory() and .authority().

HTML5 mockup site: Moqups

There are many alternatives (Balsamiq and Go Mockingbird, to name a few) and haven’t delved too deeply, but looks like a solid (free, for now) alternative.

jQuery plugin: Handsontable

Handsontable is a minimalistic approach to Excel-like table editor in HTML & jQuery. Now with column and row headers!

jQuery plugin: Morris.js

Making good-looking graphs shouldn’t be hard. Morris.js is a lightweight library that uses jQuery and Raphaël to make drawing time-series graphs easy.

jQuery plugin: Turn.js

Turn.js is a JavaScript library that will make your content look like a real book or magazine using all the advantages of HTML5. The web is getting beautiful with new user interfaces based in HTML5; turn.js is the best fit for a magazine, book or catalog based in HTML5.

Try Git in your browser

Git allows groups of people to work on the same documents (often code) at the same time, and without stepping on each other’s toes. It’s a distributed version control system.

Brackets: The Open Source Code Editor for the Web

Brackets is a new open source project founded by Adobe to push tooling on the web forward. Based on the principle that the best developers to build tools for web developers are in fact web developers, Brackets is built in JavaScript, HTML and CSS.

jQuery version 1.9 and beyond

Seems as though the jQuery team are planning on dropping support for IE 6/7/8 in jQuery 2.0, expected to be released in early 2013. Now, although I don’t particularly like IE, I think that might be a little too aggressive a development path. Unfortunately few people still use IE 6, a little more 7, and quite a chunk 8.

Node 0.8.0 released

I am thrilled to announce the arrival of a new stable version of Node.js. Compared with the v0.6 releases of Node, this release brings significant improvements in many key performance metrics, as well as cleanup in several core APIs,

‘Twisted light’ carries 2.5 terabits of data per second

Researchers have clocked light beams made of “twisted” waves carrying 2.5 terabits of data – the capacity of more than 66 DVDs – per second.

PHP sockets with Ratchet

Ratchet is a component library for PHP that provides developers with the tools to create real time, bi-directional applications between clients and servers. This is not your Grandfather’s Internet.

reFiddle: Helping to debug regular expressions

Test your regular expressions with live matching and custom string matching.

Google Maps adds UK waterways to travel routes

Google Maps users may soon find it easier to plan a trip on some of England and Wales’s waterways. The search engine has teamed up with the Canal and River Trust, a charity that will be in charge of the two countries’ water network from July.

jQuery plugin: Joyride

We have been meaning to add this kind of functionality to Signable for a while. Will have to add it to the ever-growing todo list.

Responsive design illustration

Resize your browser to reveal just a handful of the kind of devices you should expect web pages to be viewed on.

Microsoft announces Surface Table

Still no real “hands on” with the newly announced Microsoft Surface, but it looks as though it will integrate well into their product line since it runs Windows 8 (whether that will be a full or stripped version is as yet unknown).

A new way to CAPTCHA

PlayThru is the next generation of online human verification. It is designed to be more simple, more intuitive, and more fun than the current CAPTCHA options. We use game mechanics to create an experience that is more enjoyable than solving that awful squiggly text.

jQuery plugin: Nestable lists

I have actually created this exact plugin for our internal CMS – I might look into releasing it into the public after this.

Skype 4.0 released for Linux

Not sure how manu years Linux users have waited for an update, but it seems to finally be here!