BASH Prompt Pr0n

So I've been asked a couple of times for this post and I keep not getting around to it so thought I would take some time and get this out. My bash prompt is very informative, long, and functional and that is they way I like it. One prompt actually results in 2 lines in my terminal being used. This is my current Bash Prompt in terminal:


  1. First thing to notice is my command prompt is actually on the second line, below all the information. This is by design.
  2. The first part of the prompt in the typical username and computer name. Nothing special. A lot of people remove this but I keep it. When all the voices in my head start shouting at each other I can always look at my command prompt and remember who I am.
  3. Next is my location on the computer. Again, a lot of people will just have this piece represent only the current folder but I like to see the entire path. Main reason is I might have several Project folders on my system and this helps me to see which Project folder I am in.
  4. Then comes this little piece of magic that I love, my Git Branch. This section only displays when I am in a directory structure related to a Git checkout and shows me which branch of that git checkout I am working on. This section, depending on your system, may require different set ups. Since I am on my OSX system what I am using is git-completion.bash (or One of the better post on how to install this correctly can be found on a thread. Keep in mind, if I am not on a Git branch none of this section displays, not even the []- which makes it is very clean.
  5. Finally I like to add a time stamp to the end of my prompt. This allows me to return to a console and figure out when I last ran something from that window. It's very helpful. The time doesn't stay current, meaning it won't continue to keep time, it will only show you the time when that prompt was created and that is it.

The prompt does include the different colors for the different sections if your system supports it and most Unix type console do support it. Here is the magic that makes this happen.

There are a couple of ways to play around with this, tweak it until you find what you like, without impacting your system permanently until you want to. At the command prompt simply copy and past the entire line including the word "export", you should be able to see the new prompt immediately. Once you've tweaked it to exactly what you want you can add it to either you .profile or .bash_profile files however you can remove the word export when you do that and just start the line at PS1

If you would like a version without the Git Branch indicator this version should work for you

Here is a link to some other helpful and fun Bash Prompts

Enjoy and Happy Bash'ing
Update: My buddy @johncongdon on twitter pointed out by adding export GIT_PS1_SHOWDIRTYSTATE=1 to your .profile or .bash_profile then you will also get the status of the Git branch.


15 Minutes with CakePHP

I recently gave a quick, and I mean quick, presentation on CakePHP to our San Diego PHP User Group. The presentation consisted of 5 slides of which only 2 were actually about CakePHP. The rest of my presentation was me building a quick blog which I might add I successfully did in about 15 minutes.

SDPHP CakePHP Presentation 1 SDPHP CakePHP Presentation

So the presentation went something like this:

But it probably goes without saying that 2 slides and a quick 15 minute demo really doesn't do a framework like CakePHP justice. CakePHP is an awesome framework with a ton features and of course you can always read the documentation yourself. However, there did seem to be a lot of interest in the command line interface I was using to build my demo code with.

I showed a lot of the functionality of the 'Console/cake bake' command. To recap a little.

> Console/cake bake
App : app
Path: /path-to/project/app
Interactive Bake Shell
[D]atabase Configuration
[T]est case
What would you like to Bake? (D/M/V/C/P/F/T/Q)

I also demonstrated you can run

> Console/cake bake all

and we saw all sorts of auto code generation magic happen.

But there are also other options I didn't touch one.

> Console/cake bake db_config
> Console/cake bake model
> Console/cake bake view
> Console/cake bake controller
> Console/cake bake project
> Console/cake bake fixture
> Console/cake bake test
> Console/cake bake plugin plugin_name

One of my complaints was that CakePHP didn't have built-in migrations. Cake does have a couple commands to make moving database around a little easier.

Now we take a look at Console/cake schema.

We start with

> Console/cake schema generate

This will generate a schema.php of the data in your projects database.

To then use this data on another project or database you run

> Console/cake create create

which uses that schema.php to import the schema.

You can also use the schema command to create a database dump file

> Console/cake schema dump --write filename.sql

Cake Shell also comes with a ACL Shell interface for managing and inspecting Acl databases. We spoke a lot about the need to run PHPUnit test and touched on how cake bake had the option to generate test files. As such the command line interface also includes

> Console/cake test

One of the more interesting commands, and one I have not tried using myself is the Upgrade command.

> Console/cake upgrade all

According to the Cake documentation "The upgrade shell will do most of the work to upgrade your CakePHP application from 1.3 to 2.0." which, if worked as advertised, would make updating projects to the latest version of the framework a lot easier.

The full list of shells available look like this

Available Shells:

[CORE] acl, api, bake, command_list, console, i18n, schema, test, testsuite, upgrade

Hope this perks the interest of some of you to give CakePHP a try.

Why aren’t you using git flow?

Attended another great presentation put on by the San Diego PHP User Group (which I am now a co-organizer of) around a workflow built off Git called Gitflow, presented by John Congdon (@johncongdon). Unfortunately the slides, as good as they are, don't capture all the great discussion and examples that were sparked up from the presentation but its a good start.

As I mentioned, I've taken a more active role is the SDPHP Group so if you have any question feel free to ping me. You can also keep tabs on the groups in the normal spots:
Twitter: @sdphp
Facebook: San Diego PHP
Meetup: SanDiegoPHP


A local PHP User Group is starting to get some traction here in San Diego again which makes me very happy. Last night we attend a pretty good presentation on MySQL help at the Oracle building here in San Diego. It was given by Dave Stokes who is the MySQL Community Manager there at Oracle and he was nice enough to share his presentation online. via @slideshare

Powerful Validation from Respect

All developers have had to, and one time or another, write a validation class. Over the years, I've personally tweaked my own validation class and it has become a pretty standard part of all my coding project; However that may all change now.

Respect is not the first PHP validation class to hit the tubes of the Net but it does appear to be one of the better implemented and flexible ones out there.

More powerful Validation from Respect -

Posted via email from shocm

Getting Git to work in Textmate, Resolving "sh: git: command not found" error

I've been doing a lot of work with Git lately and its great. I downloaded and installed the Git Bundle for Textmate but it didn't  seem to work, always returning the error message "sh: git: command not found". Since I did most of my Git work from the command line I just ignored it but for some reason tonight I decided I needed to fix.

Since I knew Git worked on my system, it must have been something with the way Textmate was configured. I couldn't figure out how to confiugre Textmate to point to my Git install so I guess I cheated and I created a symbolic link on my system to point to my Git install. It seems to have corrected my issue with Textmate.

The command I ran was pretty simple

sudo ln -s /usr/local/git/bin/git /usr/bin/git

That's it, Textmate is now happy with my Git install.

Posted via email from shocm

‘report_activate_error’: RubyGem version error

So from time to time I will post small things to my blog that I just want to keep track of or remember how I did something. This is one of those post. I should prefix this post to anyone who happens to come across it and read it, I am by no means a "Rails Developer" and as a matter of fact, I ran into this problem working through a "How to" books.

The issue

I am running OSX 10.6.2 and although I had Ruby on Rails working on it at one time, some how, some where it broke. Now there is nothing more frustrating to a n00b who is trying to work through a tutorial on how to learn a new programming language and not being able to get past the first chapter because something about the base install of the programming language that you don't know anything about and you're trying to learn, wont work.

The Actual Error

When I try to create my first controller this is what happens

  1. ruby script/generate controller main welcome

And this is what the system kicked out to me
  1. /Library/Ruby/Gems/1.8/gems/rails-2.3.5/lib/initializer.rb:271:in `require_frameworks': RubyGem version error: rack(1.0.0 not ~> 1.0.1) (RuntimeError)</p>
  2. <p>from /Library/Ruby/Gems/1.8/gems/rails-2.3.5/lib/initializer.rb:134:in `process'<br />
  3. from /Library/Ruby/Gems/1.8/gems/rails-2.3.5/lib/initializer.rb:113:in `send'<br />
  4. from /Library/Ruby/Gems/1.8/gems/rails-2.3.5/lib/initializer.rb:113:in `run'<br />
  5. from /Users/eric/Dropbox/Code/Rails/r4music1/config/environment.rb:9<br />
  6. from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require'<br />
  7. from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require'<br />
  8. from /Library/Ruby/Gems/1.8/gems/rails-2.3.5/lib/commands/generate.rb:1<br />
  9. from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require'<br />
  10. from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require'<br />
  11. from script/generate:3

Naturally, the first thing I do is start hitting Google and start clicking on links. A lot of similar issues with a wide variety of solutions. From just doing a simple 'sudo gem update', to making sure rake is installed, to making sure you have the correct rake version installed. None of which worked for me. Finally, I stumbled onto Wojno' Site and following the steps in his post I manage to resolve my problem.

The Fix
If you didn't want to click on Wonjno's link here are the steps that fixed my problem. Had to change a couple of things because my install paths were a little different since I was running a different OS.
We begin by uninstalling the problem package

  1. sudo gem uninstall rack

When prompted, make sure you remove all versions of the rack packages. Now this is one place where my experience differed a little. I ended up getting prompted to uninstall rails itself. I'm a brave soul, that didn't scare me, so yeah I uninstalled it.
Here is what that looked like
  1. <br />
  2. sudo gem uninstall rack<br />
  3. Remove executables: rackup in addition to the gem? [Yn] &nbsp;Y<br />
  4. Removing rackup<br />
  5. You have requested to uninstall the gem: rack-1.0.0<br />
  6. actionpack-2.3.3 depends on [rack (~> 1.0.0)]<br />
  7. actionpack-2.3.5 depends on [rack (~> 1.0.0)]<br />
  8. If you remove this gems, one or more dependencies will not be met.<br />
  9. Continue with Uninstall? [Yn] &nbsp;Y<br />

OK, that was a little scary but we will fix it.
I did manually remove the directory for the older version of rack
  1. <br />
  2. sudo rm -rf /Library/Ruby/Gems/1.8/gems/rack-1.0.1/<br />
  3. </bash><br />
  4. Now we reinstall things. Don't forget we need to reinstall the rails itself<br />
  5. <code lang="rails"><br />
  6. sudo gem install -v=2.3.5 rails<br />
  7. sudo gem install rack<br />

After that, life was good, at least for me. If you found this article and actually read it in hopes that it helped fix your issue, well then I hope you had some success as well.

Posted via web from shocm

Microsoft and Zend

More for my geek friends. This is old news but if you haven't heard.

Microsoft and Zend Technologies Announce Technical Collaboration to Improve Interoperability of PHP on the Windows Server Platform / 10 / 2006 / Announcements / Zend News / Company /

REDMOND, Wash., and CUPERTINO, Calif. — Oct. 31, 2006 — Microsoft Corp. and Zend Technologies Inc. today announced a technical collaboration to enhance the experience of running the PHP scripting language on Windows Server® 2003. The parties expect to extend the collaboration to the next version of Windows Server, code-named “Longhorn.” The resulting technology enhancements and ongoing interaction with the PHP community is expected to enable customers to take advantage of the Windows Server platform. The cooperative effort seeks to provide customers with richer functionality and better integration, resulting in improved performance and increased reliability.

Continue reading Microsoft and Zend

Vi for programmers

This is a great article that shows you how to really harness some of the power of VIM. I snagged it from

It was a multiple part article so this is going to be kind of long but really filled with a lot of great information.

If you're a developer working on a UNIX/Linux platform, you've already encountered vi. Vi users fall into one of two categories: those who hate it and continually curse its finger-twisting key combinations and hard-to-remember commands, and those who love the flexibility and power it offers. For a long time, I was in the former category. However, continuous usage has led to a gradual appreciation for the speed and power under the cryptic interface, and I've since learnt a bunch of shortcuts and key combinations that ease the task of writing code in the editor. This article discusses my personal top ten features. Before proceeding, ensure that you have a copy of ViM (that's Vi iMproved) installed and working on your system. You can download both binaries and sources from

Continue reading Vi for programmers

Backing Up and Restoring Your MySQL Database

Do you need to change your web host or switch your database server? This is probably the only time when you really think of backing up your MySQL data. If you've got a website with a database or your custom database running for your applications, it is imperative that you make regular backups of the database. In this article, I will outline two easy ways of backing up and restoring databases in MySQL.
The easiest way to backup your database would be to telnet to the your database server machine and use the mysqldump command to dump your whole database to a backup file. If you do not have telnet or shell access to your server, don't worry about it; I shall outline a method of doing so using the PHPMyAdmin web interface, which you can setup on any web server which executes PHP scripts.

Playing with mysqldump

If you have either a shell or telnet access to your database server, you can backup the database using mysqldump. By default, the output of the command will dump the contents of the database in SQL statements to your console. This output can then be piped or redirected to any location you want. If you plan to backup your database, you can pipe the output to a sql file, which will contain the SQL statements to recreate and populate the database tables when you wish to restore your database. There are more adventurous ways to use the output of mysqldump.

A Simple Database Backup:

You can use mysqldump to create a simple backup of your database using the following syntax.

mysqldump -u [username] -p [password] [databasename]> [backupfile.sql]

[username] - this is your database username
[password] - this is the password for your database
[databasename] - the name of your database
[backupfile.sql] - the file to which the backup should be written.

The resultant dump file will contain all the SQL statements needed to create the table and populate the table in a new database server. To backup your database 'Customers' with the username 'sadmin' and password 'pass21' to a file custback.sql, you would issue the command:

mysqldump -u sadmin -p pass21 Customers> custback.sql

Continue reading Backing Up and Restoring Your MySQL Database

Configuring Apache to use a .htaccess file

Just a good step by step on how to configure Apache to use a .htaccess file. I rarely ever use this method except in testing so I always forget.

First, get your web administrator to enable your use of .htaccess files. This requires a stanza in ServerRoot/conf/access.conf like this:

AllowOverride AuthConfig

where /home/webber is replaced by your home directory. Without this, the usual default is AllowOverride None, which means that .htaccess files are ignored. The above stanza allows .htaccess control in all subdirectories of the specified Directory.

Set up a reasonably secure directory for the password (and optionally the group) files. This directory should not be in the web document tree! If it is, someone who can learn or guess the URL of the password file can fetch it and try to crack the passwords. (This refers to visitors from elsewhere on the Internet. There is no simple way to prevent users with accounts on the web server host itself from snooping in the password file, so we will have to settle for security by obscurity and trust them not to try too hard.)
Let us name this directory http-etc by analogy to the Unix /etc directory where the system passwd and group files reside. Place it in your home directory (not in public_html) so that it is outside URL space. Give it permission 701 = rwx-----x meaning you the owner can do anything, and the web server, running as the ordinary user apache, can access the directory but cannot list it (so it must know the file names in advance).1

Continue reading Configuring Apache to use a .htaccess file

Backup files with tar

I don't remember where I got this article from but it is full of some good information

TAR is the Unix Tape ARchive utility. It can be used to either store data on a streaming tape device like a DAT drive, or store files in what is commonly called a tarball file- somewhat like a pkzip file, only compression is optional.

[The basics]

In these examples, I will use the following file structure: a top level directory called DIR1 containing the files picture.jpg, document.doc and database.db.


[Creating a tarball]

If we were in the directory DIR1 and wanted to backup all the files to a tarball called backup.tar, we could issue this command:

$ tar cvf backup.tar .
tar: backup.tar is the archive; not dumped

c=create (an archive)
v=verbose (just because)
f=filename (the name of our tarball)
.=current directory (what's going to be backed up)

Also worth mentioning is that by default tar is recursive- meaning it will back up all files and subdirectories recursively unless you otherwise specify with the n flag (non-recursive)

[Displaying the Contents of a Tarball]

The current directory will now contain a file called backup.tar. To display the contents of the tarball file, we could issue this command:

$ tar tvf backup.tar
drwxr-xr-x root/gci 0 Jun 29 10:10 ./
-rw-r--r-- root/gci 1 Jun 29 10:10 picture.jpg
-rw-r--r-- root/gci 1 Jun 29 10:10 document.doc
-rw-r--r-- root/gci 1 Jun 29 10:10 databse.db
Continue reading Backup files with tar

Learning to Use Regular Expressions by Example

Dario F. Gomes

This site I'm working on relies heavily on user input through forms, and all that data needs to be checked before being sent a database. I knew PHP3's regular expression functions should solve my problem, but I didn't know how to form the regular expressions in the first place. What I needed were some sample strings--obviously the first places I looked were the PHP3 manual and the POSIX 1002.3 specification, but they don't help much in the way of exemplifying.
Adding to that, I had a really hard time finding good literature on the Web about the subject. I eventually got to know how to do it, mostly through experimenting, and seeing there wasn't much to it, I decided to write down this straight-out introduction to the syntax and a step-by-step on building regular expressions to validate money and e-mail address strings. I just hope it manages to clear the fog around the subject for all you fellow programmers.

Continue reading Learning to Use Regular Expressions by Example