Since recently setting up a forum for Three Devs and a Maybe, we have started to partake in a weekly code-kata.
What could be more fitting to start with than the common interview question, reversing a string in ‘X’ language.
In this case the language is PHP, and below are some of the many ways contrived to solve the problem.
Since exploring languages such as Scala and Python which provide the tuple data-structure, I have been keen to experiment with how to clearly map it into a PHP solution.
Tuples are simply a finite, ordered sequence of elements - usually with good language support to both pack (construction) and unpack (deconstruction) of the values.
I have found that many use-cases of the common place array structure in PHP could be better suited to n-tuple’s.
Familiar examples such as coordinate pairs (points) and records from a relational database (i.e. maybe the user id and name) could succinctly take advantage of the structure.
Yesterday I was looking through some application logs and noticed a significant bottleneck with I/O reads in the implemented file cache.
This cache is used to temporary store processed views and records for a set duration.
I looked into a couple of solutions to alleviate the intense spinning disk usage, ranging from Memcache to Redis.
These products are great for large-scale applications (spread over multiple systems), however, in my case simply required a single local configuration.
The Caesar cipher (shift cipher) is an extremely simple encryption technique.
Substitutions of this kind rely on the invariant - replace each plain-text letter by the letter some fixed number of positions across the alphabet.
The recipient is then able to successfully decode the encoded message if they are aware of the chosen position system.
Following on from my previous post on Self-signed SSL certificates, I would now like to address the second most common Web application vulnerability (Broken Authentication and Session Management).
When delving into the subject I was unable to find a definitive resource for an PHP implementation.
Due to this, I set out to combine all the best practice I could find into a single Session handler, to help protect against the common attack vectors.
Since PHP 5.4, you are able to set the Session handler based on a class instance that extends the default ‘SessionHandler’ class.