Troubleshooting gitolite SSH connection issues

We’re all agree that GitHub it’s pretty much the next best thing since sliced bread, but there will be times that we’ll need to host some repositories on our own server, and for that cases Gitolite it’s probably the best tool.

There are, however, several issues that you might find when trying to connect or creating an access for some user, and most likely they’ll be related to the SSH connection instead of gitolite itself, so here are a few tips to help you get around those issues.

Continue reading

Using anonymous functions and closures for user-defined array sorting

Anonymous functions and closures are relatively new in PHP, but they’re extremely welcome.

Whenever you need to sort an array with a custom order (that is, with a user-defined comparison function such as usort, uasort or uksort) you can use anonymous functions and closures in an easy and very straight-forward way.

For instance:

// assuming you have your un-sorted elements on $elements
// and the customized order on $order

usort( $elements, function($a, $b) use ($order){
    $a_index = array_search($a->ID, $order);
    $b_index = array_search($b->ID, $order);
    if ( $a_index > $b_index ) return 1;
    if ( $a_index < $b_index ) return -1;
    return 0;
});

Sharing a single WordPress codebase for multiple multisite installations

Ok; the title seems a tonge-twister, but the situation it’s:

  • One of our clients, a rather large university, needed to create independent sites for each of its faculties aaaand we love WordPress, so it was clear that we were going to use it as their CMS
  • Each of these faculties had to be able to create and manage sites for their pregrad careers, postgrads and research centers, so instead of  separate installations for every site or just one huge multisite setup, we chose to set a multisite network for each of the faculties, where they could add and manage their sub-sites as needed
  • The codebase for all the sites it’s the same; they’re all part of the same project and all features are shared. Each faculty has a default theme (which it’s a child theme from a shared parent) and they all use the same plugins
  • Every faculty lives on a different subdomain, which we could use as a unique identifier for every site, so all sites had URLs like:
    • http://subdomain.somesite.com
    • http://othersubdomain.somesite.com
    • http://anothersubdomain.somesite.com

At one moment we had separate WordPress installs for each faculty, but sharing a single installation (multi tenancy) has some benefits, such as:

  • On the previous setup, we needed to update various directories from an SVN repo; if something went wrong updating one of these (because someone f*cked up the permissions or something like that) we would end up with different versions on the different sites
  • Keeping a single set of WordPress files should improve performance for an opcode cache such as APC or the built-in Zend Optimizer in PHP 5.5
  • Well… it just makes sense, doesn’t it?

So, how to do it?

First, you’ll need to tweak your wp-config.php file just a little bit. What’s important here it’s:

  • Getting the subdomain for the site that the user it’s viewing, which we’ll use as a unique identifier for connecting to the database and configuring the uploads directory
  • Set wp-config to use wp-content/sunrise.php, where we can identify the blog (sub-site) that the visitor requested, and map that to the correct uploads directory
  • Define the database connection constants used by WordPress for the requested site. Since all of us in the development team had local copies and slightly different setups, we did this on a local config called local-config.php

Of course, this assumes that you need to follow some sort of convention for the names of the databases and the uploads directories, and all canonical URLs for the sites are set to the subdomain that you’ll use as your id.

Both the wp-config.php and wp-content/sunrise.php were included on the project repository, along with a local-config-sample.php that should be used to define everything that was specific to the local enviroment.

The local-config.php that’s included defines:

  • DB_NAME, DB_USER, DB_PASSWORD, DB_HOST
  • DOMAIN_CURRENT_SITE which it’s needed by WordPress on Multisite setup
  • Also, it could be used to define other constants such as WP_DEBUG and related

The wp-content/sunrise.php we used was very similar to the one used by the WordPress MU Domain Mapping plugin, but with one important difference: we needed to define BLOGUPLOADDIR for getting the uploads from the correct site and subsite.

You can check these snippets on GitHub for a working example:

Continue reading

Saving MySQL access credentials for your Linux User

To keep entering your access credentials everytime you need to connect to your MySQL database, you can store them on your user folder. Just create a .my.cnf file such as:

[client]
 user=your_username_here
 password=your_user_password_here
 socket=/var/run/mysqld/mysqld.sock

You can chmod 0600 that file to keep other users from reading it.

Why Are People Resigning Before The Copyright Industries’ Will? | TorrentFreak

But no matter what, don’t ever accept the resigned position that the copyright industries determine law. They don’t. They’ve gotten away with wishlists because politicians haven’t cared. They do care when tens of thousands of people make noise, and we can do that. We know absolutely well that we’re capable of that and much more.

Why Are People Resigning Before The Copyright Industries’ Will? | TorrentFreak

A Simple Device Diagram for Responsive Design Planning | Metal Toad Media

There are an ever-increasing number of devices with different screen resolutions to take into account with a responsive design, so we put together a simple but handy diagram that lists the most common device widths as of the present, along with overlays for potential device width ranges. A big shout out to creative partner Sisu for the inspiration to put this together.

Originally posted on April 11, 2012 at 06:05PM at A Simple Device Diagram for Responsive Design Planning | Metal Toad Media

Sam’s ultimate web performance tool and resource list

While preparing for my talk at Codemania I started filling my slides with links, clearly not something that scales. So, instead, here is a big list of interesting tools and resources that can help you journey through the murky waters of web performance.

Originally posted on March 28, 2012 at 06:36PM at Sam’s ultimate web performance tool and resource list

The Case Against Google

It’s not surprising that the tracking debate had people up in arms. A Pew Internet study, conducted just before Google combined its privacy policies (and after it rolled out personalized search results in Search Plus Your World) found that three quarters of people don’t want their search results tracked, and two thirds don’t even want them personalized based on prior history.

Originally posted on March 23, 2012 at 08:36AM at The Case Against Google

Install Dropbox On Ubuntu Server (10 & 11)

This post will help you install the Linux Dropbox client on your headless Ubuntu Server and link it up to your Dropbox account. Unlike the process of mounting an S3 bucket we looked at before the Dropbox approach is a much better solution for sharing files. If you’re a daily Dropbox user you’ll quickly get hooked on the convenience of having your servers in the same file sharing loop as all your other Dropbox connected devices!

Originally posted on March 21, 2012 at 11:50AM at Install Dropbox On Ubuntu Server (10 & 11)