Mika Tuupola

Blog Projects

HTTP Basic Authentication From Database for Slim

HTTP Basic Authentication middleware comes with simple PDO authenticator. It can be used to authenticate users from database. Authenticator assumes username and hashed password are stored in database. Default name for table is users. Default column names for username and has are user and hash. Column and table names can also be set in options. Hash must be created with password_hash() function. Simplest possible table to store user data looks something like this.

    user VARCHAR(32) NOT NULL,
    hash VARCHAR(255) NOT NULL

Continue reading >>

Witchcraft for PHP

There are two kinds of people. Those who like their accessors and mutators to start with get and set. This is also what PHP-FIG seems to suggest.

$unicorn = new Unicorn();
print $unicorn->getAge();

It works well with IDE autocompletion. It is also easy to write API documentation using PHPDoc. Then there are those like me who prefer to leave get and set out.

$unicorn = new Unicorn();
print $unicorn->age();

Or sometimes even access them as properties.

$unicorn = new Unicorn();
$unicorn->birthday = "1930-24-12";
$unicorn->color = "rainbow";
print $unicorn->age;

Continue reading >>

Chained Selects Stable Release

Chained is now stable and in feature freeze. In 2.x.x version class support will be removed. Next major version will use data attributes will be used instead. After all, it is 2014 already!

Legacy syntax removed

Stable version removes legacy syntax. It is not 100% compatible with 0.9.x branch. You must pass all options to remote version as JavaScript object. Example of all possible options below.

    parents : "#mark",
    url : "/api/series.json",
    depends : "#series",
    loading : "Loading.",
    bootstrap : {
        "" : "--",
        "series-3" : "3 series",
        "series-5" : "5 series",
        "series-6" : "6 series",
        "series-7" : "7 series",
        "selected" : "series-3"

Class based version does not have any configuration. You only need to pass parent selector.

$("#engine").chained("#series, #model");

Continue reading >>

Flat UI Theme for Developers

Wanna be like all the cool guys? Grab a Flat UI theme for TextMate 2 and Sublime Text. It is based on colors of the amazing Flat UI Pro framework made by Designmodo. Theme is for oldschool hackers who prefer their terminal windows to be green or yellow on black. It offers just enough highlighting without looking like a rainbow.

NOTE! Designmodo link above contains my referral code. If you buy something from them I will get a reward and be a happy puppy.

Textmate 2

To install download the zipped bundle. Unzip it and doubleclick on the resulting file. It will ask if you want to install the bundle.

Continue reading >>

Chained Selects for Zepto

New version of Chained mostly updates the remote version. Plugin now supports both Zepto and jQuery. You can avoid initial AJAX requests by bootstrapping select values. You can configure extra values to be sent to server. Since plugin now accepts more configuration options new prettier syntax was implemented. Lastly support for Bower was added.

Zepto support

Since plugin uses :selected you must also include Zepto selector extension. It is not included by default.

<script src="zepto.js"></script>
<script src="zepto.selector.js"></script>
<script src="jquery.chained.js"></script>

After this you can use the plugin as you normally would.

Continue reading >>