Category Archives: Tumble

I just discovered a gem called etckeeper, which I’m sure will change the way we’re used to work with server configurations.

The official website describes it pretty well:

etckeeper is a collection of tools to let /etc be stored in a git, mercurial, darcs, or bzr repository. It hooks into apt (and other package managers including yum and pacman-g2) to automatically commit changes made to /etc during package upgrades.

All it took me to set it up on my Debian Lenny slice was:

$ aptitude install etckeeper
# aptitude will install Git as the version control system, which is pretty neat!
$ cd /etc/
$ sudo etckeeper init -m "initial commit"
Initialized empty Git repository in /etc/.git/

The best part is that it’ll detect changes made by apt, commit whatever changes you had made previously, and even enable you to make your own commits, after your manual modifications. Do try it out!

If you upgraded to PHP 5.3, chances are high you’re going to run into a few warnings or deprecated function messages.
An example is the ereg family of functions, which are gone for good, as they were slower and felt less familiar than the alternative Perl-compatible preg family.

To migrate ereg():

ereg('\.([^\.]*$)', $this->file_src_name, $extension);

becomes

preg_match('/\.([^\.]*$)/', $this->file_src_name, $extension);

Notice that I wrapped the pattern (\.([^\.]*$)) around / /, which are RegExp delimiters. If you find yourself escaping / too much (for an URL for example), you might want to use the # delimiter instead.

To migrate ereg_replace():

$this->file_dst_name_body = ereg_replace('[^A-Za-z0-9_]', '', $this->file_dst_name_body);

becomes

$this->file_dst_name_body = preg_replace('/[^A-Za-z0-9_]/', '', $this->file_dst_name_body);

Again, I just added delimiters to the pattern.
If you are using eregi functions (which are the case-insensitive version of ereg), you’ll notice there’re no equivalent pregi functions. This is because this functionality is handled by RegExp modifiers.

Basically, to make the pattern match characters in a case-insensitive way, append i after the delimiter:

eregi('\.([^\.]*$)', $this->file_src_name, $extension);

becomes

preg_match('/\.([^\.]*$)/i', $this->file_src_name, $extension);
  1. Install the Smilies Themer plugin
  2. Activate it.
  3. Go to Settings > Smilies Themer and pick a theme pack. If you want to create a custom one, keep reading
  4. Create a folder with the name of your theme pack in wp-content/themes/smilies-themer/. In my case I called it devthought
  5. Place your emoticons in that folder and a file called package-config.php

    art

  6. Place a code like this in package-config.php

    :o'      => 'angryface.png',
    	'>:-O'   => 'angryface.png',
    	':-['       => 'blush.png',
    	':['         => 'blush.png',
    );
    // add as many as you want respecting the same format:
    // 'emoticon' => 'file.jpg',
    
  7. Go to Settings and choose your package!

Now you’re done! :) :[ >:o :o :X :-/ ;) :D o:)

This is a quick idea I came up with. We extend the Event native like this:

Event.implement({

   hasCapsLock: function(){
      return ((this.code > 64 && this.code < 91 && !this.shift)
           || (this.code > 96 && this.code < 123 && this.shift));
   }

});

And then access the method from a keypress event:

$('test').addEvent('keypress', function(event){
   if (event.hasCapsLock()){
      // do something
   }
});

The only drawback is that it relies on sniffing alphabet characters and whether the shift key was pressed. This means that if the user presses the caps lock key, you won't know it until another character is inserted.