Home »
Blog
Debugging with audio
Andreas Jansson | 08 September 2011
echo "here";
Sometimes you just want to know that you took the right branch in an if statement, or that the value of a variable is what you expect it to be. Sometimes you don't have the need, time or incentive to fire up the debugger, you just want to dump a few variables to stdout. That works really well if you're writing a CLI script and it's okay if you work on old-fashioned HTML, but when it comes to debugging AJAX requests, it's pretty useless. When the response comes back to the browser you have to open up the web inspector and look at the network activity to find that particular requested document, click to look at the contents and dig out that debug message from the raw source. Not fun.
PDF DOC XLS ODF from PHP?
Zdenek Machek | 01 September 2011
Every PHP developer will sooner or later face a request to output a document as a PDF, XLS, DOC or ODF. Exporting each format by hand is as time consuming as it is dull - especially things like point-by-point positioning of elements in a PDF. So how can we get around this tedious chore using PHP?
Writing MySQL functions in C
Andreas Jansson | 15 December 2010
In the previous post Zdenek explained how to use MySQL stored functions to calculate the distance between two points on the lat/lng plane. Here I take his function as a starting point to describe how to implement user defined functions written in C, and import them into MySQL.
User defined functions (UDF) are compiled C functions that you can use as normal functions within MySQL. UDFs have a number of advantages over stored functions written using SQL, the most important being improved performance and the fact that you can use them as aggregate functions (like you can with SUM(), AVG(), etc.).
Writing UDFs is easy. So is compiling and importing UDFs into MySQL. First you need to do a little bit of setting up. This is how you do it (in Ubuntu and Red Hat).
Automatic geolocation and SQL
Zdenek Machek | 16 November 2010
Recently we launched a website and platform for iGo Gift Vouchers. One of the screens shows an interactive list of the shops where vouchers can be used. The classic interface design pattern for this is to ask users to provide a postcode, or the name of a city or town, and then display the shops in that area on a map.
As usual, we decided to try something new and improve a little on the traditional functionality. We wanted to automatically detect where the user is right now, so we can display shops in their area as soon as they arrive on the page, without them having to enter any information. You can see how it works at www.igogiftvouchers.co.uk/myigo - when your browser asks if you would like to share your location with the page, just click the option to accept.
So why Geolocation and SQL? The first part of this task, identifying where the user is, is handled on the client side usining JavaScript. But SQL comes in as the best and fastest tool for the second part of the task: identifying which shops are nearest and should be displayed on the map.
Our brand new tech blog
Nick Nettleton | 24 April 2009
Welcome to our brand new tech blog, which I hope will in time be full of fabulous, magical and shiny clever things.
For those that don't already know, I'm Nick Nettleton, and Loft Digital is my company. We're a digital agency in London and by day we create geekily smart websites and apps for ecommerce, publishers and are various others. By night, well, we try to put our computers down, but sometimes things just get too exciting!
To keep life simple, I've ported a lot of content over from my old blog nicknettleton.com, warts and all. There's been some great discussion there that I'd like to keep alive - especially on PHP / UTF8 and, bizarrely the simplest of all things - trimming a string in Javascript.
Over the coming months I'll be sharing and open-sourcing lots of code from the various problems we've solved over the years, as well offering up some general banter on the tech scene and the political bits and bobs that go with this.
Anyways, thanks for listening up. Do drop me any questions if you have them, via my email at the top of the page. Look forward to chatting!
Nick
Validate a credit card number in JavaScript
Nick Nettleton | 12 August 2007
When you're writing web apps, it's good to do validation both in the browser and on the server side. Do it in the browser to provide your user with instant feedback, and on the server for real security, as all client-side validation can be tricked or circumvented by those who know how.
Validating credit card numbers is a little tricky. They all follow a special algorithm, whose name I forget. But here are the mechanics of it...
Intro to microformats
Nick Nettleton | 08 July 2006
Microformats are an important - no, very important - new idea on the web. In fact, I think they are so important, they could precipitate a leap of evolution more important than AJAX and as important as XML web services. But first, an introduction.
The focal site for microformats, microformats.org, is not clear at all on what microformats are, but here is my understanding:
Microformats build on the semantic capabilities of the web, using existing standards.
Unless you're fairly technical, that's probably meaningless. So, to explain. <h1>, <h2>, <p>, <ul> - all of these and other HTML tags are designed to tell human readers, web browsers and other HTML readers what sort of information they contain. Not what it looks like - that's what CSS is for - but how that bit of information relates to other bits on the page. Is it a heading, a paragraph or a list of things?
CMYK, RGB and PHP
Nick Nettleton | 04 July 2006
A month or so ago, we were putting the finishing touches to the Lena White website, which sells OPI nail lacquer, among other things.
Lacquer is all about colour, so we wanted to give shoppers a way to quickly and visually browse all the available colours with colour swatches, rather than the more traditional product shot route. This makes particular sense because all lacquer bottles look pretty much the same, photos of them give a poor impression of the actual colour, and they take up way more screen estate than is helpful to anyone.
PHP UTF-8 cheatsheet
Nick Nettleton | 03 July 2006
When we started building DropSend, we decided to support all languages worldwide from the start. The interface is currently in English only, but the application can send, store, sort and process your data whatever language you want. As a result, we have a good number of customers out east.
To support worldwide languages, you need to use UTF-8 encoding for your web pages, emails and application, rather than ISO 8859-1 or another common western encoding, since these don't support characters used in languages such as Japanese and Chinese.
Happily, UTF-8 is transparent to the core Latin characterset, so you won't need to convert all your data to start using UTF-8. But there are a number of other issues to deal with. In particular, because UTF-8 is a multibyte encoding, meaning one character can be represented by more one or more bytes. This causes trouble for PHP, because the language parses and processes strings based on bytes, not characters, and makes mincemeat multibyte strings - for example, by splitting characters 'in half', bodging up regular expressions, and rendering email unreadable.
There are a number of great articles online about UTF-8 and how it works - Joel Spolski's comes to mind - but very few about how to actually get it working with PHP and iron out all the bugs. So, here to save you the time we put in, is a quick cheatsheet and info about a few common issues.
Optimising while() loops in PHP
Nick Nettleton | 02 July 2006
Following the for() tests, I performed the same tests for while() loops. The speeds were very similar to the for() tests across the board, with just one syntax standing out: the one that doesn't use a comparison operator. It was about 50% faster than all the others:
$i = 1000000 ;
while($i){ $i-- ; }
As with the for() test, this is a count-down loop, which checks the boolean value of $i without a comparison operator for each iteration.