This post is a follow-up to Safari on iOS 5 randomly switches images. In our case almost all of the images on the front page has unique height * width combinations. Since our CMS sets the image size with height/width attributes in the element and rescales the image file to fit those dimensions, we can compare that the height/width and naturalHeight/naturalWidth matches up. (more…)
VGTech is a blog where the developers and devops of Norways most visited website share code and tricks of the trade… Read more
Safari on iOS 5 Randomly Switches Images, Part 2
Safari on iOS 5 Randomly Switches Images
Since the release of iOS 5 we’ve received several bug reports about images randomly displaying the wrong image(s) on our front page for smartphones. It seems to be completely random and could affect any of the images, anywhere and anyhow. During one week we would receive anywhere between two and ten reports about this error. In the same time period we would do about 4.5 million page impressions(2.9 million of them from iPhone) on the front alone. (more…)
Running multiple versions of PHPUnit
The latest version of PHPUnit (3.6.4 at the time of this writing) does not play well with the Zend Framework extensions (Zend_Test_PHPUnit). After asking Matthew Weier O’Phinney about this he answered that they had standardized on PHPUnit-3.4 for ZF1.
Having just upgraded to the latest version of PHPUnit on our servers we were no longer able to test our Zend Framework applications. One option was to downgrade PHPUnit, but since we were already using some of the new features this was not going to happen.
One solution to this problem is to run multiple versions of PHPUnit and use specific versions for specific test suites. Not optimal, but at least it gets the job done. (more…)
Speeding up fonts for the web
Custom fonts for the web are a bit of a pain. Browsers support different kinds of font formats, they can be relatively heavy and the rendering can vary between operating systems.
Luckily, Google Web Fonts have come along and helped out, providing free and open-source fonts that is easy to implement on any website and should work across browsers. Typekit also provides fonts for the web, although not free.
We were having trouble getting the touch-version of VG’s front page to render correctly on Android – the reason behind this is the use of the “Times New Roman”-font. While Android does have a serif-font (Droid Serif), its metrics are not equal to that of Times New Roman, which results in text breaking at different points compared to the original font we use.
(more…)
Fat Models, Chubby Routes, Super-Skinny Controllers
Some of you have probably heard the “Fat models, skinny controllers” mantra with regards to developing MVC applications. Recently we figured out that the routes (not part of MVC, but a crucial part to the application nonetheless) could take some weight off the controllers. Since we use Zend Framework (ZF) at VG I will use ZF when describing this solution.
You need to be familiar with some ZF basics to follow along with all the code presented in this post, but fear not, the idea itself can easily be transferred to other frameworks/languages.
(more…)
Building Tree Structures in PHP Using References
Using a recursive function or joining in SQL usually are the most common ways for creating tree structures. Both these solutions are of exponential time complexity 2O(n) and therefore very expensive in computational time. For every element you add to the dataset the computational time theoretically doubles.
While researching in best practices for building tree structures I found this method using references. Using references, the tree is built with only one pass. This gives a time complexity of O(n), which is completely linear. For every element you add to the dataset you get only a small and constant increase in computational time. (more…)
Unit testing with streams in PHP
Using the memory/temporary stream provided by php:// stream wrapper you can create a stream with read and write access directly to RAM or to a temporary file.
This gives you the possibilty to write unit tests that does not rely on a specific file, resource or stream, but rather on data provided by the test itself.
Creating a memory stream is easy; $fp = fopen('php://memory', 'r+');. Now you have a resource that can be used and manipulated just like any other stream or file.
Speeding up SQLite insert operations
I’ve been working on an Android application recently which uses an SQLite database to store and search about 6000 rows of data, and the data is updated from a webservice periodically. It would seem like a fair assumption to think the retrieval of data from the webservice would be the slowest part of the operation, however – this turned out not to be the case. (more…)
Mocking the file system using PHPUnit and vfsStream
This article is about how to mock the file system when writing unit tests, and it will be rather code-heavy. If you are not familiar with the concept of unit testing this article might not be the best place to start. There will be other articles regarding unit testing on this blog, so keep coming back for more. (more…)