Category Archives: Uncategorized

print statement for C++

print-stmt is a Python-like print statement for C++. It’s damn easy to add it to the project:

The easiest way to use this is to clone this repo and copy the file print.h into your project. Then simply

#include "print.h"

at the top of the file, but after the system #includes.

This is pretty handy. Some example features:

  • bool prints ‘true’ or ‘false’
  • A type that defines a member function called c_str() is converted to a string by calling this function.
  • A type that has a begin() member function that returns in iterator but does not have a c_str() member function is printed like a list, e.g. [“one”, “two”].

Connecting to mobile broadband from a terminal

In Linux, connecting to internet using a mobile broadband connection (i.e., a dongle) is fairly easy. If your distro has nm-applet installed (like most modern distros do) all you need is to create a new network connection and choose your country and network provider.

But how do you connect with a dongle when you don’t have a GUI? azeemigi’s blog has the solution. I’m reproducing it here just for the sake of my own future reference.

First determine the name of your broadband connection using the command nmcli -p con You will get the list of network interfaces in your computer and among them might be a row corresponding to your dongle. It’s easily distinguishable. In my case it was,

~ » nmcli -p con
 =============================================================================
                                                   Connection list
==============================================================================
NAME                      UUID                                   TYPE         
------------------------------------------------------------------------------
Wired connection 1        cbd369e1-b2fa-46a6-83b1-fbfdc9d28e0f   802-3-ethernet
Dialog GSM Postpaid       bb06d9f7-772c-4b4b-851a-4564503c3798   gsm       

Obviously it’s the last row.

Now download the following gist and copy/paste the name and the UUID of the connection in the relevant lines.

It goes without saying that you need to make the script executable with chmod +x mbb and add to a location in your $PATH.

Now you can connect to the internet with mbb start, disconnect with mbb stop and check the status with mbb status.

4b825dc642cb6eb9a060e54bf8d69288fbee4904

4b825dc642cb6eb9a060e54bf8d69288fbee4904 is a special hash value in git which denotes an empty tree. And it does not change from repo to repo. This opens way to some neat tricks, but how the hell would one remember this value? You don’t need to.

Colin Schimmelfing:

In both of the links that mentioned the special hash, it looks like there is another way to find the magic value, a little faster:

> git hash-object -t tree –stdin < /dev/null
4b825dc642cb6eb9a060e54bf8d69288fbee4904

Thus you get the hash of the ‘null’ tree.

The author of the post mentions about changing/diff-ing the first commit using this, but remember that since git 1.7.12 or so you have this awesome –root flag for git-rebase which does wonders in this particularly intimidating situation.

So, if you want to amend the initial commit or add one after some commits (humans forget), you can just:

git rebase -i –root

Now just do whatever you want in the editor window that pops up. Anything’s possible with git-rebase.

Installing Sinhala Unicode in Crunchbang Linux

Being debian-based, the usual commands can be used to install Sinhala Unicode in Crunchbang Linux. Tested with #! Waldorf.

  1. sudo apt-get install ttf-sinhala-lklug ibus im-switch ibus-m17n m17n-db m17n-contrib
  2. rm -f ~/.xinput.d/* ; im-switch -z all_ALL -s ibus
  3. Logout and login again.
  4. ibus-setup
  5. Choose the Wijesekare layout from the Input Method tab and close

Now you can switch between English and Sinhala using the key combination Ctrl + Space.

Upgrading to thunar 1.6.2 in crunchbang

I switched to CrunchBang (#!) today. The debian-based distro is fast and everything installed effortlessly. Except I didn’t like thunar, the default file manager. Some googling revealed that despite #! comes with thunar 1.2.3, the 1.6 version is available with lots of new features including tab support. After some messing around, here’s how I installed thunar 1.6.2.

Setup siduction keyring:

wget http://packages.siduction.org/base/pool/main/s/siduction-archive-keyring/siduction-archive-keyring_2013.03.29_all.deb
dpkg -i siduction-archive-keyring_2013.03.29_all.deb
rm siduction-archive-keyring_2013.03.29_all.deb

Add this line to /etc/apt/sources.list:

deb http://ftp.spline.de/pub/siduction/xfcenext unstable main

Add the following to /etc/apt/preferences:

Package: thunar libthunarx-2-0 thunar-data
Pin: origin ftp.spline.de
Pin-Priority: 1200

And finally,

sudo apt-get update
sudo apt-get install thunar

The new thunar looks much better. I might try this for a few days and consider moving to nautilus only as a last resort.

On comparing languages, C++ and Go

Implementing the business card-sized raytracer in your favorite language and benchmarking it against other languages is the trend these days. It all started with Fabien Sanglard beautiful breakdown of the ray tracer written in C++.

Whilst the raytracer has been written in many languages since then, the major heat seems to be between C++ and Go. Henrik writes:

Because when you actually do code for performance, in those small bits of code in inner loops where it’s warranted to do so, your priorities change. The language you code in ends up being… less relevant, abstractions fade away and you try to divine communication directly with the hardware that will be running your code.

All these benchmarking might be a fanboy-thing, but they have certainly paved way to lots of insights.

Global Git ignore

I feel stupid for not being aware of a global git ignore earlier. It’s a good approach to globally ignore those editor-specific swap files, OS-specific crap (like .DS_Store in OS X) etc. From usevim:

A better approach is to use a global option. Run git config –global core.excludesfile ~/.gitignore. Then you can add *.sw?, and perhaps *~ as well. I like to add .DS_Store because Windows developers don’t need to worry about that nonsense, and they should probably add Thumbs.db.

The trick is to add globally-ignored files into some place like ~/.gitignore and specifying this in core.excludesfile.

Unknown search terms

From the wordpress.com Stats support page:

UPDATE: In September 2013 Google started to rapidly expand the number of searches that it encrypts, which results in a higher proportion of “Unknown search terms” in your stats. According to some sources, this expansion will eventually result in encryption of all Google searches. This is being done for privacy reasons by Google when someone searches at Google.com, before a visitor arrives at your WordPress.com site. Therefore we don’t have any way to unhide the search terms. We recognize this means a loss of stats information for you and we will look for other ways to show you how users arrived at your site.

Any blog owner would love to see the search terms leading to his blog, but I damn respect Google’s decision. Been using Google’s encrypted version for some time, but 99% of the people don’t know of its existence. And it seems now you don’t need to anymore.

sudo make me a sandwich

There’s nothing to write these goddamned days. Here’s a snippet I came across in HN:

curl https://put.honkgong.info/ed8e3df8691ec7944a878cea595e00c363079504 > Makefile
sudo make me a sandwich

In case you’re scared to curl the goddamned link, just fucking visit it.

Killing W3Schools

Though it ranks number one in most web development-related google searches, w3schools is a horrible place to learn from. Someone is trying to create a site called “The HTML and CSS Tutorial” simply to kill w3school’s search engine rank and stop the kittens from dying.

Somone points out an interesting view in the HN discussion:

W3Schools is like an old dictionary. A dictionary isn’t particularly helpful when you’re trying to learn a foreign language properly, but it’s quite handy when you’re face to face with a foreigner and you need to think up a word for “toilet paper” quickly.

But that does not justify the highest search engine ranks.