Saturday, October 27, 2012

Creating a new git repo on a remote server

Let's say you have some source code and you want to create a new git repo on a remote server, and check it in there. Here's the simple steps to create a new repo and push the code you have written. I assume you have git installed in both places and have done the basics to properly initialize things, e.g., add git users and so on.

First, ssh onto the remote machine (for this example, call it myhost) and then:
  • cd to location you want the repo (in my case, on Mac OS X this is /Volumes/SRV-EXT2)
  • mkdir mynewrepo
  • cd mynewrepo
  • git init --bare
back on the machine where the code exists:
  • cd into source dir
  • git init
  • git add your files (I like to add them individually, "git add ," may pick up unwanted files)
  • git commit
  • git remote add origin gituser@myhost:/Volumes/SRV-EXT2/mynewrepo
  • git push origin master
 That's it.

Tuesday, October 23, 2012

C++ STL for Arduino

It may not be obvious, but Arduino is programmed in C++.

However, the core libraries do not support the Standard Template Library, which has (in my opinion) indispensable support for generic containers like vector, list, map, and so on.

Well, some kind person did a straight port of the uClibC implementation of STL, and it is available here:

The instructions are pretty clear, but I will summarize:
  • Open up your Arduino IDE, go to preferences, and locate your sketchbook (details here: On my Ubuntu 12.04 machine, it is /home/slogan/sketchbook. Chdir to that location and then type:
$ mkdir -p libraries
  • Download the StandardCplusplus tarball into the libraries directory you just created, and unpack it with
$ tar -zxvf file (where file is the name of the tarball)
  • Exit arduino IDE if running, then restart.
  • Go to File->Examples/StandardCplusplus and select one of the examples, and compile it.
I haven't done any testing but given it is a straight port from uClibC I'm not expecting surprises. This is a huge plus for me, because other than occasionally using Boost (most recently for regex), the STL containers are essential for my style of C++ programming.


Sunday, October 21, 2012

Django-like URL handling in C++

I wrote some code tonight (and checked it into github @ that aims to provide URL handling that is similar to how Django handles URLs.  From the readme file:


Simple C++ classes that wrap boost regex, and invoke a callback on matches, 
similar to django

To use this code, simply copy djangourls.cpp and djangourls.h into your

On Linux, you will need the boost regex dev package, on debian/Ubuntu, you
can get it like this:

$ sudo apt-get install libboost-regex-dev

See the test directory for an example. The regular expressions in that
example are pulled from django docs, and explained there. See the URL for more details.
The example is roughly analogous to the following

from django.conf.urls import patterns, url, include

urlpatterns = patterns('',
    (r'^articles/2003/$', 'news.views.special_case_2003'),
    (r'^articles/(\d{4})/$', 'news.views.year_archive'),
    (r'^articles/(\d{4})/(\d{2})/$', 'news.views.month_archive'),
    (r'^articles/(\d{4})/(\d{2})/(\d+)/$', 'news.views.article_detail'),

with the exception that in the sample, a single callback function is being
used. Of course, you can declare as many classes/objects that you like to
act as handlers when a match comes in.

Friday, October 19, 2012

Git server on Mac OS X

Some decent looking instructions for setting up GIT server on Mac OS X:

Mostly correct. Setup non-ssh for local use only, which means I can only push origin master only while inside my firewall (and that I must always supply a password for the gituser account). Cloning is done with git clone gituser@host:/path (note the missing http or git prefix on the URL).

Thursday, October 18, 2012


I know that this may seem trivial, but I need some webby place to store the core vimrc I use, so many times I am spinning up a VM or am on some new machine where I want this.

Surprisingly, it doesn't take much of a vimrc to make me happy. This one is derived from one that was used at VMware to adhere to the coding standard.

set hidden                      " Allow sane buffer switching
set shiftwidth=4                " for coding standard
set backspace=2                 " allow backspacing over in insert mode
set textwidth=78                " always limit the width of text to 78
set expandtab                   " expand tabs to spaces
set smarttab                    " tabs -> shiftwidth
set showmatch                   " show matching brackets
set tabstop=8                   " set tabstop (coding standard)
set cinkeys-=0#                 " don't indent # comments
set history=100         " Number of lines of command line history.
set undolevels=100      " Number of undo levels.