Creating Pull Requests quickly from Emacs

A lot of code I work on lives in GitHub, both work and personal project normally make their way there quickly so maintaining it means I work with the GitHub interface quite a lot as well. To make my live a little easier I decided to create a quick Emacs function to drop me in the matching interface and create or visit the pull request I’m currently working on. Luckily most of the pieces where already out there. All that was needed was grabbing the correct URL and branch from the current repository.

Switching git users in Emacs based on repository

Using Github internally for work is really nice, but especially when working on multiple projects, some on public and some on internal Github it can also be quite hard to always remember to use the correct username and email for the commits. Because I tend to forget such things I decided to create a little elisp function to make sure the correct user is set when I start magit. Right now I only have to switch between 2 users so it is managable, but I think this is easily extended to more if the need arises (god I hope not).

Learning some emacs

I have been a very faithful Vim user for the last couple years, but recently I ran into more and more things which made me want to know more OS like shortcuts. On Mac OS that means that using Emacs is pretty close, most of the basic text navigation just works in most other text windows, and Emacs is a powerful editor in itself as well. The advantage is that I can more or less have my whole setup inside emacs, it can act as my terminal, my editor, as well as my interface to other servers via SSH and the emacs built in trampmode. When editing some ruby I realized that I’ve been relying on CTags quite a lot, and I need to have a quick way to generate and update them in emacs as well, which let me to write my first few lines in ELisp in years.

(defun create-tags ()
  "Create tags file for current project defined by the textmate-project-root"
  (let ((root (textmate-project-root))
        (tags-file (concat (textmate-project-root) "TAGS")))
    (shell-command (concat "ctags -e -R -f " tags-file " " root))
    (visit-tags-table tags-file)))

This small function allows me to run a simple

M-x create-tags

to update the CTags for the current project, aka the closest folder with containing .git directory, a Makefile, Rakefile etc.. So far the experience has been really nice, but I’m still catching up speed wise to my Vim days.

Setting the process name in Ruby

When running a ruby application by default the process is shown like 1234 ruby ruby test.rb when running ps -o pid,comm,args on a linux box. The command, comm, is the process name according to the application, and args are the arguments passed to the process on startup. Since the arguments are passed as a string this means that a programm can theoretically modify them to change what is displayed. In ruby this means that one can change the value of the $0 variable to change what is displayed by programms like top for example, this does however not change the actuall process name but just changes what is stored in the process agruments. A problem with this arises when the process is forked via a tool like upstart, which means that its arguments like any other process memory is copy-on-write, and therefor a modification of the arguments will cause a copy and modification, instead of changing the underlying string, this in turn means that overwriting $0 will not change the output in top or other tools.
With ruby 2.1 a new API appears in ruby setproctitle which is available to change this, unfortunatly this does not work everywhere and is also not available pre 2.1. Luckily linux offers an API to set the process title via prctl which can easily be leveraged via FFI to change the process title to whatever is needed (as long as it is below 15 characters).
Now 1234 mytitle ruby test.rb can be seen when running ps -o pid,comm,args when calling ProcessCtrl.set_process_name "mytitle" from the test.rb script.

Detect long paths incompatible with OneDrive for Mac

Screen Shot 2015-09-01 at 21.35.28

As a user of OneDrive on MacOS I ran into an issue that OneDrive would hang at the processing files or scanning files stage. After some searching I found that this can be related to having paths with more than 255 characters in the name but how to find those? Well some small bash magic did the trick for me.

cd ~/OneDrive && find `pwd` -name '*' | grep '^.{255}'

This will list all the paths longer than 255 characters for the OneDrive directory located in home.

Canned v0.3.3

It has been some time since I wrote about canned and a lot has happend since then. With the current release canned now supports all features on Windows as well as Unix, which has been limited before due to the Windows limitation of certain characters in the filename, which caused complex get parameters to create filenames that are not valid on Windows.
With the new version canned now fully supports multiple response bodies in a single file, allowing you to match on headers, parameters, and body of the request, as well es return different status codes for each of them. This allows now to have a single file bundling up all the post responses for a certain resource, emulating the rejection of certain parameters, or headers while returning the correct status code for the operation.

For more details see the changelog thanks to everybody who contributed to the recent releases, reporting and fixing bugs as well as adding features like proper SOAP XML support to emulate ever more complex APIs.

Moving from Tumblr to WordPress

Recently I moved this blog from Tumblr to WordPress, as I wanted more control over the environment. My setup now is a hosted WordPress instance on heroku, with really nothing special, using the current PHP stack with Apache2 as my server, and ClearDB to provide me a MySQL instance to store data in. Since this basic setup will provide rather dreadful performance, especially on a single free Dyno, I use Amazons CloudFront as my CDN. All this gets me to a quite fast experience. The setup was quick and painless, but migration of the content proved harder than expected. All there is to do to make this work on heroku is using environment variables to get the database setup in PHP.

Importing Tumblr into WordPress

WordPress offers an importer for Tumblr, sadly this importer seems to strip HTML from Tumblr posts which meant that all my carefully embedded content was not imported. Looking around there are multiple ways to solve this, the quickest being Tumblr2Wordpress which allows to create a WordPress compatible XML file from all the Tumblr posts, with the content being HTML. Importing is as simple as hitting import on the new WordPress blog.  

One thing which constantly annoys me on the more “casual” web is that people break links all the time, and since I didn’t want to be one of those people I wanted to make sure that all links to my content still work after the migration. Also since I use Disqus for my commenting, and Disqus uses the URL to determine the correct comment stream (afaik) I wanted to make sure this works correctly. Tumblr uses a somewhat weird way to reference posts its URL format is something like: what is funny about this is that the last part of the URL does not matter at all, it is just the ID Tumblr cares about, and this ID is also carried over by the import and stored in the post_name attribute for the post. So to faking the first part of the Tumblr URL in WordPress is easy, just make the permalink structure: /post/%postname%. Now if everybody would just link to the ID this would work great, but sadly most of the time the title is going to be included, even though nobody cares about it. The solution to this is simple, just don’t make WordPress care about it either, but display it if needed.

Added to function.php of the theme that is in use, this little snippet will provide a new tag for the permalinks to attach and strip of the slugified title to the to the permalinks, depending on if the imported post used the Tumblr way of URL or if it is a new WordPress post, just don’t name your posts 1234… /post/%postname%/%tumblrslug% will now give you the structure you need.

Easy management with Rake

For the longest time I have been a ruby guy and I just like to use rake to automate almost everything and do the needed command remembering for me. So to make sure I can keep managing my blog I ended up creating a Rakefile with some function to manage my remote instance, and I use dotenv to manage my local variables in the same way as heroku does remotely, through environment variables. For anybody interested, this is what this looks like

And that’s it, the blog is migrated, all the links should still work and I can easily manage the needed tasks, like backup, getting into the database, running a local server all through Rake.

Using Couchbase Lite from RubyMotion

CouchbaseLite has been released for sometime now, so I thought it is time to
give an update for using CouchbaseLite from RubyMotion.

When I ported ToDoLite-iOS to
RubyMotion originally there where some bumps in the road, but it worked over
all. There were for example some problems with RubyMotion not handling lambdas
the way CouchbaseLite needs them, but this has been resolved since then. If you
don’t know what I mean by that, you can be happy and forget all about it, or
read up on

So what do I need now to get going with CouchbaseLite and iOS?

By now it is possible to go 100% ruby for a RubyMotion project using
CouchbaseLite, which is great. CouchbaseLite has been publicly released, is out
of beta and has already received much love in terms of patches to make it work
even more reliably cross all platforms. In case of RubyMotion this made things
much easier, and the process is by now:

  • Add couchbase-lite via cocoapods
  • Tell rubymotion where to find the header files
  • Use it!

Installing CouchbaseLite via Cocoapods

Cocoapods is an awesome package manager for iOS and
MacOS projects, and it integrates really well with RubyMotion. All there is todo
is add cocoapods and motion-cocoapods to your gemfile

Now you can install any cocoapods by adding them to the Rakefile and running
“bundle exec rake pod:install”

Important side not, make sure to include

as the headers are not going to be found otherwise.

Using Couchbase Lite from RubyMotion

You can now use CouchbaseLite like you would any other Obj-C library from
rubymotion, for example to define a view which grabs all the “lists” in the
database you can write this

For more details checkout the RubyMotion Sample project on

Plain text to-do list and Textmate

For my personal to-do list I’m a big fan of todo.txt and have been using it for quite a while, recently I returned to Textmate to manage the list so I decided to revamp my todo.txt bundle a little to now include syntax highlighting for todos with a date, as well as a command to include the date in a task.
It’s also downloadable as a bundle now, if you are one of the 3 people still using Textmate 1.5 and todo.txt check it out ;).