Setting up git with Rescuetime highlights

Recently I’ve written on another site how I use Rescuetime to provide metrics on my overall productivity that I can review each week. One useful feature I noticed was Rescuetime highlights, which gives you a good overview of your accompishments throughout the day. The first thing I wanted to add to this (obviously) was git commits.

Luckily it turns out someone had already thought of this and implemented it. The script itself is here, I’m just going to reproduce it below.

Now, the annoying part for me is that this doesn’t work globally across all of my git repos, so to fix this you can leverage git’s templates directory. To create/initialise a git template folder simply run these commands.

Then put the above shell code into ~/.git-templates/hooks/post-commit

What this means is that from now on, any new git repos you initialise will contain this post-hook script. However, if you want to attach this to existing repos, just run a git init wherever the .git folder is.

Solving boot2docker’s fail to start error


I’m putting this obvious solution up as I couldn’t see it anywhere online.

If you try to start up boot2docker with boot2docker start and it returns.

Before destroying everything and wiping your ~/Virtualbox VMs folder, try starting up Virtualbox and seeing if the vm simply hasn’t been suspended due to an OSX suspend or shutdown.

1. Unpause the machine
2. Send a shutdown signal
3. Try boot2docker start again.

And that’s it, hope it works for you.

R – Cleaning/Merging Excel files

This is just a useful snippet of code I’ve been using a lot to tidy up messy exports I’ve been getting lately.

Takes in a bunch of excel files, rewrites some variable column names in column 3 then outputs them as a list of dataframes. These then get merged into a single csv file.

SugarCRM – Git Version Control Strategy

I’ve found SugarCRM an utter pain to work with in terms of version control for a number of reasons, but the most annoying is simply that certain critical elements of the SugarCRM configuration are stored on the database.

Over time I’ve worked out a system that circumvents this and I’ve managed to create a very useful gitflow based workflow.

I won’t go over what gitflow is or does, there’s a great explanation here and if you need a more visual explanation this cheatsheet is a terrific reference.

Example Problem

Say you’re in the middle of developing a new feature in SugarCRM. You’ve used something like.

Someone realises a new urgent fix is required to go live now, you’re not going to want to deploy your half implemented feature along with the new urgent fix. That’s okay, you’re using git flow. So you’d commit your half finished feature. Then create a hotfix, like

The problem is that you’ve made a bunch of changes to the sugarcrm database, specifically fields_meta_data. Even if you swap branches the fields_meta_data won’t update back to the master branch, which is where the new hotfix will create it’s branch from. What you need is a way to keep fields_meta_data in sync with the branch you’re currently working on.

The Solution – Git Hooks

Using git hooks you can automatically run commands when certain events occur. The two hooks of interest to us are pre-commit and post-checkout.

Tracking all database changes
What pre-commit does is run everytime you commit code. So, if you could dump your fields_meta_data everytime a commit is made, you can be sure your branch is tracking all database changes you’re making via the studio. So in .git/hooks/pre-commit add code that looks like so:

Note that I’m not compressing these database dumps, they should stay in plaintext with each line representing a database insert. The reason for that is when it comes time to merge two branches, say you’ve made changes to studio in a master branch and also to a feature branch you wish to release, you can merge the fields_meta_data in with branched changes very easily via any mergetool.

Keep Sugar up to date with your branch
Finally when you swap between branches you’ll want to automatically apply that branches fields_meta_data because your likely to forget to do this step. So say your swapping from a feature branch to master. You’ll want to revert your studio changes back to where master was. You can do this in the post checkout git hook. So in .git/hooks/post-checkout add something like this:

This will automatically execute your fields_meta_data database dump on your SugarCRM install.

In the end, whether a hotfix or a feature it’ll always get merged to master when I’m deploying. So what I tend to do is finish my release/hotfix, merge to master then apply a data sync to fields_meta_data on live so I can manually review the db changes before deploying. Navicat has a really nice tool to handle this.

Going further
As you can see all I’ve written is two simple bash scripts and they’ve made my Sugar workflow much cleaner. You could go far further than this, a few examples I can think of would be to track db changes on the saved_reports table or have the scripts automatically run a command line variant of the Quick Repair/Rebuild. The other thing could be to track the entire structure of the SugarCRM database if you felt like it, but since all db fields are tracked via fields_meta_data I thought this wasn’t necessary but I’m sure there’s ton of other things you could add to make your development life easier.

Let me know if you think of anything!

Better PHP Debugging with Emacs

Recently I came across an app called CodeBug, a really nice PHP debugger for Mac. I find debugging PHP really painful within editors such as Vim or Emacs, so up until now I’d been stuck using the incredibly bloated PHPStorm.

On Emacs you can currently use Geben for debugging but I find it’s install really painful and it’s usage even more so. I figured it was worth knocking up an Emacs plugin that allows you to set breakpoints in Codebug.

You can find the repo here and it’s been accepted to Mepla, so it can be installed via the package manager. MELPA

Update: Codebug have very nicely featured this plugin on their homepage. Awesome!