Create custom named events in Backbone.js

In Backbone, Events is a module that can be mixed in to any object, giving the object the ability to bind and trigger custom named events. Events do not have to be declared before they are bound, and may take passed arguments. For example:

Show hidden files on Lion

To enable hidden files/folders in finder windows:

  1. Open Finder
  2. Open the Utilities folder
  3. Open a terminal window
  4. Copy and paste the following line in
  5. Press return
  6. Now hold ‘alt’ on the keyboard and right click on the Finder icon
  7. Click on Relaunch

You should find you will now be able to see any hidden files or folders. To revert:

Clear the terminal’s command history

Sometimes you just need to clear your history in Terminal. It’s actually pretty easy to do.

If you’d rather not have your history saved to a file at all, add the following line to your ~/.bash_profile:

This way, your command history is limited to only those commands you used during the current session. More information and options can be found on the bash man page

Ubuntu Package Management

Chances are good that you’re already familiar with apt-get, a command which uses the “advanced package tool” to interact with the operating system’s underlying package system. The most relevant and useful commands are, (to be run as root):

This command installs the package(s) specified, along with any dependencies.

This command removes the package(s) specified, but does not remove dependencies.

This command removes any “orphaned” dependencies which remain installed but are not used by any applications.

Removes downloaded package files (.deb) for software that are already installed.

Combines the functions of remove and clean for a specific package. Also removes configuration files for the given package.

Reads the /etc/apt/sources.list file and updates the system’s database of packages available for installation. Run this after changing sources.list.

Upgrades all packages if there are updates available. Run this after running apt-get update.
While apt-get likely provides the most often used functionality of the package management, apt provides additional information that you may find useful in the apt-cache command.

If you know the name of a piece of software but apt-get install fails or points to the wrong software, use search to look for other possible names, if you need to find out the name of a package that you know is in the system.

The search interface only provides package names. If you need to learn more about a package, including dependency information, version numbers and a basic description, run this.

Lists the packages that the specified packages depends upon in a tree. These are the packages that will be installed with the apt-get install command.

Generates and outputs a list of packages that that depend upon the specified package. This list can often be rather long.

Generates a list of the currently installed packages on your system. This list is often rather long, so it is best to pipe its output through a command like less.

Get your Twitter follower count with jQuery

A PHP function for the Fibonacci sequence

I was recently asked as a test to write a function that outputs the Fibonacci sequence in PHP. Here it is:

Getting MySQL and PHP running on Terminal with XAMPP

I have XAMPP setup on my Mac. Getting MySQL and PHP to run in terminal didn’t work after installation. To be able to run mysql and php you have to add the xampp application to the .bash_profile file in your users home directory.

To check that it has worked, open a new terminal session and type in:

Both should point to /Applications/xampp/xamppfiles

Recursively remove .svn folders on Windows

I’m not an SVN guy; I love my GIT but, sometimes you inherit projects where SVN was the choice used for version control. There are many ways to do this of course but my preferred method is creating a Batch (.bat) file in the root of the target folder, add this line and run it.

Drupal – How to install Drush

What is Drush?

It’s a command line shell and scripting interface for Drupal. The Drush Package Manager allows you to download, enable, disable, uninstall, update modules/themes/profiles/translations from the command line in a very simple way (apt-get style) – just type,

and

in a Drupal directory to install the Views project! Additionally, the Drush Package Manager also allows you to update all your modules and even Drupal core with just one command,

How to install Drush

  1. Download the current version of the Drush Package from the Drupal website.
  2. Upload the folder to the root directory of your server. I did this on a shared environment.
  3. Login to your server via shell.
  4. Make the ‘drush’ command executable:
  5. create an alias to drush:
  6. Now, you must log out and then log back in again or re-load your bash configuration file to apply your changes to your current session:
  7. Start using drush by running “drush” from your Drupal root directory.