How to install SublimeClang on Archlinux

SublimeClang is a cool and useful extension for SublimeText which enables IDE features for C++ programmers.
Here are the installation instructions for Linux from their github page.

There are two problems with the installation on Archlinux.

Problem A

SublimeText looks for Python 2.6. Archlinux has Python 3 and Python 2.7,

Solution

Step 1

Install python26 from AUR.

Step 2

Create a symlink to the new Python 2.6 installation in the right place for SublimeText to find, as root (sorry, I don’t know how to solve it without creating a symlink as root).

ln -s /lib/python2.6/ /opt/sublime-text/lib/python2.6

Problem B

When trying to build libcache the build environment won’t find libclang.so and will try to build it and fail.

Solution

Copy the file to a place where it will be found.

cp /usr/lib/llvm/libclang.so ~/.config/sublime-text-2/Packages/SublimeClang

Now clean the build environment if needed and run the cmake and make commands as written in the instructions.

It should work now. Tested on Archlinux 64 bit.

How to tell ruby (rails) which version of rake to use?

I am playing a bit with Rails on Archlinux. and the first command I ran errored on me:

% rails new Site
...
...
...
run bundle install
Fetching gem metadata from https://rubygems.org/...........
Fetching gem metadata from https://rubygems.org/..

Errno::EACCES: Permission denied - /usr/lib/ruby/gems/1.9.1/cache
An error occurred while installing rake (10.0.2), and Bundler cannot continue.
Make sure that `gem install rake -v '10.0.2'` succeeds before bundling.

I do have ‘rake 10.0.2’ installed but I also have ‘rake 0.9.2.2’ because Archlinux bundles it with the Ruby package. I struggled to find a way to tell Rails to use the newer package.

The solution turned to be quite easy. Just set the GEM_HOME environment variable to where your gems are installed. For example:

export GEM_HOME=/home/username/.gem/

If you want it to be persistent add it to a file which is sourced every time you log in, like for zsh you can add to the file /home/username/.zshenv :

GEM_HOME=/home/username/.gem/

Now it will work:

% rails new Site
...
...
...
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.

How to run Starcraft Brood War and Diablo II on Windows 7? (Color correction)

Old games and new versions of windows not alwasy go well together, but sometimes there are games which stay with us for a very long time and require some fiddling in order to work.

Most of the problems with old games can be solved by simply running them in compatibility mode or as administrator. Starcraft does not need it, and Diablo does. These two games have another problem. Although they run, their colors are messed up. Luckily, once you know the solution it is very simple. Close explorer.exe and viola! the colors are good again.

Closing explorer.exe has a price though. You can’t change volume, and it is harder to start up your games. In order to help with these two tasks, I wrote a little C# application which allows you to close explorer, run your games and open the sound mixer in order to control the sound. Extremely simple but useful.

It can be downloaded from here: 32-bit, 64-bit, and the source code.
Make sure to use the right architecture because manipulating explorer with the wrong version won’t work.

How to remove selected items from a Gtk::TreeView using gtkmm? The painless way.

I am building an application using C++/gtkmm-3.0. The development process is sometimes nice and sometimes too complicated in my opinion. The worst part until now was when I wanted to remove the selected items from a tree view.

This is a tree view:


Behind a tree view there is a “store” which holds the information for the view, like a model in MVC. Sometimes you need to enable the user to choose multiple items from the view and delete them. Should be simple, right?

I was expecting something like

treeview.removeSelected();

or

store.remove(treeview.getSelected());

but no, it won’t be that simple.
According to the official documentation you have to reviece a “selection” object from the treeview and keep it. Then you have to create a (wasn’t so easy for me to find it’s structure) callback function that deletes an item, and when the user presses delete you tell the “selection” something like

selection.selected_foreach_iter(pointer to the callback function);

And that’s supposed to do it. I was surprised to see the steps needed, and even after it did somewhat work, Gtk wrote on the command line that this way of iterating over a selection is for reading only and for manipulating the store I have to use another way. Well, I wasn’t the one who came up with that method, I saw it in a few examples and tutorials and it was used to delete items.

I became tired of the over complication and found a simple little way to do it. I don’t know if it “right”, but it is simple and it works.

We have our class, with the view, store, and selection as private members.

Gtk::TreeView treeview;
Glib::RefPtr<Gtk::ListStore> store;
Glib::RefPtr<Gtk::TreeSelection> selection;

In the constructor we initialize the selection

selection = treeview.get_selection();
selection->set_mode(Gtk::SELECTION_MULTIPLE); // enable multiple selection

And then, all we have to do in order to remove the selecte items is:

void MainWindow::_remove_selected()
{
    vector<Gtk::TreeModel::Path> paths = selection->get_selected_rows();
    for(int i = paths.size()-1; i>=0; i--)
        store->erase(store->get_iter(paths));
}

That’s all. 3 lines of code. Why not do it like that? Why the over complication? Who knows.