Monthly Archives: May 2007

Enabling folding in Vim, especially for Ruby

I was originally going to release my .vimrc on the blog, but I’m in the process of repairing it up right now–so it might just confuse people. I will release it at a later time when it is stable(I cleaned it up to get rid of a problem I was having after creaing the ShowMeDo videos, in which i inadvertently destroyed the folding setup). Meanwhile, most of my file is derived from Amir Salihafendic’s vimrc file, available here.

A couple of things I changed from his suggestions:

  1. (Mac OS X only) I put the helper directory contents directly in the package contents
  2. (possibly Mac OS X only)I turned off lazy redraw

Meanwhile, I was able to recover most of my folding stuff with the following commands. here is how folding should work(put this in your .vimrc–without the numbers of course):

  1. set foldenable
  2. set foldmethod=indent
  3. set foldlevel=1

That last line depends on your shiftwidth, which you can set by set shiftwidth=2, for example. For a shiftwidth of 2, set foldlevel=1 seems to work fine. Also, for some reason, even though I enabled folding with the first command above, I still have to type in zC in command mode to see the folding.

Hope this helps.


Standing on the Shoulders of Giants

“If I have seen further it is by standing upon the shoulders of giants.”

–Isaac Newton

Well, it is that time of year again–university summer classes. I won’t update this blog as frequently as before, but I will try to post from time to time, depending on how much time I can free up.

I made two small Cocoa projects on Google Code which leverage existing code and tools(hence the quote above)



I have uploaded the code and binaries from a different machine instead of my Mac, so let me know if something is broken.


  1. Andreas Mayer for AMShellWrapper
  2. Greg Miller for gcalc

Major RubyCocoa update

Very nice update and a new wiki based site for RubyCocoa. Check out the new version. The documentation seems to be better, etc. I’ll be updating my little Regular Expression utility so that potential users don’t have to download RubyCocoa to actually run it. I’ll keep you posted.

It looks like other RubyCocoa programmers can register and contribute to the community through the Wiki on the website.

In other news, BridgeSupport offers a framework for helping create new bridges between language “X” and Cocoa. A nod from Apple to the bridge developers.

(news from Daring Fireball and MacResearch)

Adding a project to CVS(version control)

CVS comes preinstalled in Mac OS X.

Here is what I did to setup and use a local cvs repository:

  1. Make a directory called cvsroot on Desktop
  2. Edit ~./bash_login and add the command export CVSROOT=~/Desktop/cvsroot
  3. Run the command cvsinit in the Terminal
  4. cd to the project directory you want to place under version control
  5. Suppose your project directory is called project, type in cvs import -m "Program" project sample start
  6. You should get bunch of output followed by the message No conflicts created by this import
  7. Let us say you want to checkout the code you have just placed. Simply navigate to a directory where you want to store the checked-out project and type in cvs checkout project
  8. If you made changes and want to commit your changes to the repository–say you added a variable called int x; C file called foo.c, simply type in cvs commit -m "Added a variable" foo.c after navigating to the directory where your modified file is

There is much more to CVS, here is an Apple tutorial on the subject.

this seems to be a good, if somewhat dated, tutorial.

GraphViz for Mac OS X

It is straightforward installing GraphViz for Mac OS X. The easiest way might be using the Mac port of the same name, GraphViz. However, I think this has not been updated in a couple of years.

You can install the commandline version of the latest GraphViz tools, dot, neato, etc by using MacPorts. Assuming you have MacPorts properly installed and configured, I think the following command is used(I have to check to be 100% sure):

sudo port install graphviz

Once the installation is done, do a simple sanity check by typing in dot and neato in the Terminal.

Boost Smart Pointers or: How I learned to Stop Worrying and Love C++

Boost smart pointers fix many of the things wrong with auto_ptr. The smart pointer library consists of

scoped_ptr <boost/scoped_ptr.hpp> Simple sole ownership of single objects. Noncopyable.
scoped_array <boost/scoped_array.hpp> Simple sole ownership of arrays. Noncopyable.
shared_ptr <boost/shared_ptr.hpp> Object ownership shared among multiple pointers
shared_array <boost/shared_array.hpp> Array ownership shared among multiple pointers.
weak_ptr <boost/weak_ptr.hpp> Non-owning observers of an object owned by shared_ptr.
intrusive_ptr <boost/intrusive_ptr.hpp> Shared ownership of objects with an embedded reference count.

The table is courtesy of the link here.

I will just go through a simple example here. For a slightly more detailed look, you can take a look at this article.

Installing Boost on Mac OS X

Compiling and installing Boost is straightforward even if it takes some time and is processor intensive–it kept both cores of my Intel Core Duo pretty busy. What you really should do is follow the more authoritative guide from the Boost folks here. Here is my summary. Disclaimer: This is not a comprehensive guide. I am not liable for any failures you might have. See the link above for a more detailed guide.

  1. Install bjam (it is a tool like make, but supposedly better). Put bjam in your PATH
  2. Invoke bjam. Step 3 shows what an invocation might look like(you can customize this to your preferences): The following command works if you have the boost_1_34_0 directory in ~/ and bjam built and set up correctly.
  3. $ cd ~/boost_1_34_0
  4. $ bjam --build-dir=/tmp/build-boost --toolset=darwin stage
  5. After a while, type in
    echo $?

    to make sure everything proceeded correctly.

  6. Try the example given on the Boost page(see here).

A smart pointer example.

I’ll be using the IT++ library for this example. Of course, you can make your own examples without the library. The concepts are what matter.

typedef boost::scoped_ptr<PAM> pam;

int main()
pam p(new PAM(2));

vec output;

bvec demodded_out;

bvec input = “0100100001100101011011000110110001101111001000000101011101101111011


//The following line of code simulates the transmitter end.

//The following simulates the receiver end.
if(demodded_out == input)
else {
return 0;

This is basically my previous code, with some smart pointer stuff added in. Notice that I didn’t deallocate any memory(I didn’t have to).

Navigating Wikipedia with style

From MacResearch,

If you use wikipedia as one of your favourite sources of information then you should definitely take a look at Pathway. It will allow you to navigate wikipedia in a graphical way, creating a pathway as you move from page to page. Its creator, Dennis Lorson, is an electrical engineering/CS student at the Catholic University of Leuven, Belgium. If this is his first program he made, I can only look forward to what we can expect from him in the future!

Innovative little apps like this one are one of the reasons I like Mac OS X. Here is a sample screenshot. Click on the thumbnail to get the full view.