Understanding Tracking Branches in Git

Here’s a topic that took me a while to understand in git, and now (I think!) I do, I thought I’d write it all down while I can remember!

Some branches in git (such as your origin/master branch) will usually track the remote branch that they are related to. But what if you want to create a relationship between local and remote branches? Or stop them from tracking? Here’s some pointers Continue reading

Running Pull Request Builds with Jenkins

The joind.in projects are set up so that the build process runs on pull requests when they are opened, which is great! It means that contributors don’t have to wait for one of the maintainers to look at it, only to reject the contribution on something that could be picked up automatically. I’ve had a few questions about the setup so I thought I’d share how it works. Continue reading

What Got You Involved in Open Source?

I did a very unscientific twtpoll recently regarding what brought each of us into open source. Plenty of people took the time to vote or retweet, so I thought I’d loop back around and let you know how it looked overall when the poll closed. Continue reading

Logging to Stdout with Monolog

My worker scripts have really basic logging (as in, they echo when something happens, and I can see those in the supervisord logs). Which is kind of okay, but I wanted to at least add timestamps in to them, and maybe send emails when something REALLY bad happened.

I’m a huge fan of Monolog so I grabbed that, but it wasn’t immediately obvious which of the many and varied options I would need for this fairly simple addition. It turns out that the right thing to use is the ErrorLogHandler, so now my code looks like this:

<?php

require "vendor/autoload.php";

$logger = new \Monolog\Logger("log");
$logger->pushHandler(new \Monolog\Handler\ErrorLogHandler());

$logger->addInfo("Something happened");

And the output is neatly in lines like this:

[2014-06-05 17:00:47] log.INFO: Something happened [] []

You can do a lot of different things with Monolog, but since I had to look up this simplest of all options, I thought I’d share.

Colourless Git Output

I teach git and often have issues with bad projectors where you can’t see the colours. Recently I had a setup where even white on black was more or less invisible, but using black text on a white background worked okay. There’s lots of documentation on how to turn on colours in git but not so much about how to turn them off.

Try putting the following into .git/config:

[color]
    branch = false
    diff = false
    interactive = false
    status = false

I had expected to be able to set color.ui to false but that didn’t seem to make much difference, so I now use the settings above. I thought I’d drop it here in case anyone else is looking for the same thing.

Easy Lint Check for JavaScript

I’m introducing lint checking on one of my projects, because it didn’t have a build process yet and I love this as a great place to start. Oh, and because we managed to commit broken syntax! So I set up a php lint job (I will share my travis config in another post) and tried to work out doing the same thing for JavaScript. Continue reading

Beanstalk, Pheanstalk and Priorities

I’ve got an application that uses Beanstalkd to queue up messages, and some PHP worker scripts that grab messages from the queue and process them. Messages get added by the web application, but can also be added by cron – and when I add a bunch of messages via cron, I don’t want to swamp what the web application is doing! Those cron-added jobs are mostly pretty low priority, generating reports, sending weekly update emails, that kind of thing. Beanstalkd has a concept of priority, so I can create lower priority jobs by using code like this:

<?php

define("LOW_PRIORITY", 2048);  // default is 1024 

$queue =  new Pheanstalk_Pheanstalk($config&#91;'beanstalkd'&#93;&#91;'host'&#93; . ":" . $config&#91;'beanstalkd'&#93;&#91;'port'&#93;);

$queue->useTube("scorem")->put(json_encode(array("action" => "my_important_task")), LOW_PRIORITY);

This will add the job to the queue, but anything with a higher priority value (where 1 is the highest priority!) will take precendence. This way I can add as many non-urgent jobs as I want to to the queue without impacting my website performance. My setup has multiple workers and also I tend to write a script that puts loads of tiny jobs on the queue rather than putting one monster task on there. I find this approach a bit more fault-tolerant and also means that incoming tasks can get a chance to get serviced rather than waiting for some crazy huge thing to finish.

I had real issues finding information about the priority settings for beanstalkd and PHP, so hopefully if anyone is looking for it, they will find this post :)

Copy/Pasting and Vim

I’m a vim user and I somehow completely missed this excellent feature until much more recently than I care to admit! Usually vim has its own clipboard, but it doesn’t share with the operating system. You will need a vim-gtk install, this isn’t available in really basic vim (I’m a little unclear exactly on the dependencies).

To paste between vim and something else, use the + (plus) buffer in vim. It contains the contents of your system clipboard, and you can also write to it. If you’re not already using buffers in vim, then you should probably read the excellent documentation but for a very quick start:

  • To copy something into the buffer, select it in visual mode and type "+y
  • To paste from the buffer, type "+P

I had no idea how I’d missed this really fundamental trick, so I thought I’d share!

Quick Switch Between Git Branches

Today’s little-known git feature (or maybe everyone knows but me? I only found this a few months ago) is for quickly switching between branches. Usually I would switch branches with:

git checkout [branchname]

However if you switch from one branch to another and want to switch back again (this happens when I’m reviewing changes and wondering if a bug is present on master as well), then you can do so by just doing:

git checkout -

Just a little timesaver in case it’s useful to anyone else – I know I’ve been using it quite a bit!