What Is Git

Git is a distributed revision control system (RCS). Git is open-source and focuses on speed. It was originally developed by Linus Torvalds for the Linux Kernel Project.

Revision control systems allow developers to keep track of the changes they make to their code. Before such systems existed, developers would keep backups of their files in case their changes would break something. In case it happened, they could easily revert to the previously working version.

Such systems are an essential part of any technology business. Without them, it would be very hard to release early and often, quickly revert buggy releases of software, etc.

What Is A Distributed Revision Control System

Decentralized revision control systems (like Git) allow developers to :

  1. Track changes to their code;
  2. Work in teams without having to fear overwriting someone else’s code;
  3. Work on a given project without needing a central server for hosting the code.

Other systems like CVS or Subversion (SVN) are centralized. This means that they require a main repository to exist. Each developer then checkouts a working version from this main repository, and commits back changes when they are complete. In a decentralized system, there is no main repository. Each developer has it’s own complete repository and changes are exchanged across developers.

How It Works

Conceptually, there are many ways to work with Git. This is what is beautiful with decentralized systems, they allow the team to choose what best suits their needs. Let’s explore two common methodologies :

  1. Every team member has a private and a public repository.
    In this case, each developer has it’s own private repository where he can freely change code, revert modifications, etc. When changes are ready to be shared with other developers (code is tested, compiles or parses and is believed to be bug-free) it is pushed to the developer’s public repository. The public repository is remotely accessible by other developers. The rest of the team can then pull the newly committed changes in their own private repositories. This way of working allows team members to easily add only the changes they want in their working versions.
  2. Every team member has a private and share one master repository.
    Again, each developer has it’s own environment for working, but instead of having one public repository for each, there is only one master repository which is remotely accessible. It makes it easier for changes to propagate to everyone (each team member has only one repository to pull changes from).

Making your repository available to your team

It is up to the team to decide where is the right place for hosting the remote repositories. Git can be remotely accessed from anywhere (HTTP, NFS, etc.). You can even share your repositories on Dropbox (something that was not possible with Subversion). There is also the famous GitHub.

What revision control tool do you use? Where and how do you share changes to your code? Feel free to add your methodology in the comments.

Support for OpenGraph Protocol META tags with Zend Framework’s HeadMeta

This is good news for all Zend Framework developers. Next release of 1.11 will allow us to set OpenGraph Protocol META tags right away from the HeadMeta view helper.

You can now do:

$this->headMeta()->setProperty('og:title', 'Title of this page');

Thanks to Marc Hodgins for this patch!

Note: To ensure your documents will validate, you need to use the XHTML1_RDFA document type. Read the HTML+RDFa 1.1 specification. Thanks to Roy Toledo who points out that this can be done with : $view->doctype(‘XHTML1_RDFA’);

View resolved issue ZF-9743.

Subversion Best Practices: Tags, Branches and Merging

Matt Wood shared on SlideShare a short presentation of what would be Subversion Best Practices. Here are a few of them:

  1. Repositories need to be kept as simple as possible. Projects should be separated from each other.
  2. Use tags. Tags meant to give symbolic names to a group of files like snapshots.
  3. Use branches. Branches provide space to experiment (easily contain parallel changes without breaking production code). They are a good way to generate releases.
  4. Each release is a branch.

Happy merging.

Here is the presentation:

Friendly URLs and User Generated Content (UGC)

If your website allows users to create content, you will likely want to equip the content’s URL with the name or title of that content. The classic example, a blog post, would have an URL like this one: http://example.com/blog/1234/title-of-the-post

As the SEO experts will explain you, having good keywords or content titles in the URL should increase the odds that your page is displayed to search engine users first. Also, friendly-URLs are more easy to remember, to type and they look great.

The most common problem with UGC is data filtering and normalization. You will want all of your URLs to have URL-friendly characters only so you do not generate broken links. This block of PHP code strips all unwanted characters and builds a clean content “name” that can be used in your URLs.

// Strip accents
$name = str_replace(
    array('à', 'á', 'â', 'ã', 'ä', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î',
          'ï', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', 'ù', 'ú', 'û', 'ü', 'ý', 'ÿ',
          'À', 'Á', 'Â', 'Ã', 'Ä', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î',
          'Ï', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ù', 'Ú', 'Û', 'Ü', 'Ý'),
    array('a', 'a', 'a', 'a', 'a', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i',
          'i', 'n', 'o', 'o', 'o', 'o', 'o', 'u', 'u', 'u', 'u', 'y', 'y',
          'A', 'A', 'A', 'A', 'A', 'C', 'E', 'E', 'E', 'E', 'I', 'I', 'I',
          'I', 'N', 'O', 'O', 'O', 'O', 'O', 'U', 'U', 'U', 'U', 'Y'),
    $name
);

// Replaces all but alphanumeric characters, underscores and dashes.
$name = preg_replace('/[^\w\d\s_-]+/', '', $name);

// Trim the white space at the start and at the end of the string.
$name = trim($name);

// Replace whitespace with dashes.
$name = str_replace(' ', '-', $name);

// Repleace double dashes with single dashes.
while(strpos($name, '--') !== false)
{
    $name = str_replace('--', '-', $name);
}

// Lowercase all characters.
$name = strtolower($name);

// URL Encode the string.
$name = urlencode($name);

You think this could have been done in a better way? Feel free to add your idea in the comments.