Running XFCE 4.10 on Debian 7.4

The Debian 7 series (a.k.a. Wheezy or stable) repositories are currently serving the xfce4 package at version 4.8 and the upgrade to XFCE 4.10 series is not slated to occur until the next major version relase, known as Jessie or testing currently. But I want to use XFCE 4.10 now...

Luckly, there is a way for me to pick and choose certain packages from different Debian repositories, while still maintaining proper dependencies. So, here's how I installed it on Debian 7:

  1. First I installed the latest Debian stable with a default XFCE desktop. This is version 7.4 at the time of this writing. I got it here.
  2. I installed it with the Desktop, SSH, and Base System options checked.
  3. Next I booted the new Debian 7 system and logged in. I had a default Debian install with XFCE 4.8 desktop.
  4. Next I edited my sources.list file like so:

    sudo <editor-of-choice> /etc/apt/sources.list
    
  5. And inserted the following repository at the bottom of the sources.list file:

    deb http://ftp.us.debian.org/debian/ testing main
    
  6. I also had to ensure that the default release in the Apt system remained configured to use wheezy. I created a file like so:

    sudo <editor-of-choice> /etc/apt/apt.conf.d/30default-release
    
  7. In that file I inserted the following directive:

    APT::Default-Release "wheezy";
    
  8. I saved and closed the files above and then ran the following:

    sudo apt-get update
    
  9. Then I was able to install XFCE 4.10 by issuing the following command:

    sudo apt-get -t testing install xfce4 xfce4-terminal
    

Recap

This is what I have done so far: I installed Debian 7 with the default XFCE 4.8 desktop. I edited the sources.list file to add a reference to the Debian testing repository. I made sure that the default Apt repository remained the stable one. Then I updated the Apt system and installed XFCE 4.10 from testing. Note that with the -t option, apt will track the package in the given release until the package version or newer is available in default release.

Let's Make it Look Better

At this point, I logged out and then back in and I had the new XFCE 4.10 desktop available. But that's not quite enough. I wanted to make it look better by installing a good looking theme. My personal favorite theme for XFCE is Greybird.

Let's dispense with the fluff and get down to just the stuff:

sudo apt-get install gtk-engine-murrine
mkdir ~/.themes
cd ~/Downloads/
git clone https://github.com/shimmerproject/Greybird
cp -R Greybird ~/.themes

Then I used XFCE Settings Manager to set the Appearance and the Window Manager settings to use the new Greybird theme.

I also installed the Faenza icon theme:

mkdir ~/Downloads/faenza
cd ~/Downloads/faenza
wget http://faenza-icon-theme.googlecode.com/files/faenza-icon-theme_1.3.zip
unzip faenza-icon-theme_1.3.zip
sudo ./INSTALL

Running as sudo will install the theme globally in /usr/share/icons. Also ensure that the permissions on the Faenza folders under /usr/share/icons is properly set to drwxr-xr-x.

That's it... Enjoy!

Pro Tip: Set Emacs 24 smex-history-length to a sane value

A few days ago I was tweaking my Emacs configuration and I decided to bump the smex-history-length variable really high to 4096. Everything was fine for about a week, and then in the last couple of days I noticed that the M-x chord was taking a really long time to respond. So I was really scratching my head for a few hours, trying to figure out why it wouldn't respond promptly and also why I would sometimes get this really weird error from smex itself (wrong-type-argument number-or-marker-p nil).

Eventually, it occurred to me that the reason for the slowness and the error is that I had set that history variable to a really insane value. The problem was not apparent immediately because it took a little while to build that smex history list. But once it was big enough, smex spent a ton of time ranking the list every time I hit the M-x chord on the keyboard. I bumped it back down to 16 now and the problems immediately went away. Beware!

Connecting to a Cisco VPN from Linux

The folks at the new job are running a Cisco VPN. While it's very straight forward to connect using the AnyConnect client from Windows, the steps to do it in Linux are not so clear cut, because the AnyConnect client for Linux constantly drops the connection for me and won't hold it for more than 30 seconds. So, this is how you do it from a Debian-based Linux:

  1. Install the "network-manager-openconnect-gnome" package

    sudo apt-get install network-manager-openconnect-gnome
    
  2. Open the Network Manager applet from the task bar

  3. Click on VPN Connections
  4. Click Configure VPN...

    Connection Manager

  5. Click the Add button

  6. VPN Connection Type should be Cisco AnyConnect Compatible VPN

    Edit VPN

  7. Enter a name for your connection

  8. Enter a value for the Gateway (IP or Host Name)
  9. Click Save

    VPN Connection Type

  10. Then go back to the Network Manager applet on the task bar

  11. Select VPN Connections and then select the one you just created
  12. On the Connect to VPN dialog, choose the VPN host and
  13. Click the Conect button
  14. Enter your Username and Password
  15. Lastly, click Login

This approach has been working really well and reliably for me and I hope it will for you too.

Manage your PostgreSQL Database from a Remote Machine

At home I have my main development workstation and then I spin up VMs that mimic my production environment to run different types of integration tests. One of these VMs is running a relatively recent version of PostgreSQL. By default, PostgreSQL is setup to allow connections coming from the local host only. In this article I will walk through the steps of setting up PostgreSQL so that it allows connections from other machines also.

Setup Remote Connections

There are, essentially, two lines in two different PostgreSQL configuration files that need to be changed to allow remote connections to work. The first file is postgresql.conf and this is usually found at /etc/postgresql/9.1/main/ on Debian-based systems. Open that file and find the line that starts with listen_addresses. By default the value assigned to it should be 'localhost'. Change that so the line reads like this:

listen_addresses = '*'

The second file is called pg_hba.conf. In this file you need to look for a IPv4 local connections line that starts with host. By default, the line reads the following:

host    all             all             127.0.0.1/32            md5

You need to change this line to read like this:

host    all             all             10.0.0.0/24             trust

For all intents and purposes, the default is telling PostgreSQL to accept connections only from the localhost (that's what the /32 is for), while we are changing the value to allow any host with an IP starting with 10.0.0.* to connect. The above will only work after you restart PostgreSQL with the following command:

sudo /etc/init.d/postgresql restart

Again, YMMV if you are using anything other than Debian.

Allowing Connections Through a Firewall

The above is really all you have to do with PostgreSQL proper to allow remote connections. But if you are like me, you are probably running a firewall on your systems also and you will need to punch a whole for PostgreSQL to talk through. You can find out more about how I setup my IPTables firewall by reading this. In my case, I need to allow only one system (my workstation) to connect to the VM hosting PostgreSQL. I created the following lines in my IPTables configuration file:

# Allow connections to Postgres DB Server from hurricane
-A INPUT -p tcp -s 10.0.0.90 --sport 1024:65535 -d 10.0.0.60 --dport 5432 \
         -m state --state NEW,ESTABLISHED -j ACCEPT
-A OUTPUT -p tcp -s 10.0.0.60 --sport 5432 -d 10.0.0.90 --dport 1024:65535 \
         -m state --state ESTABLISHED -j ACCEPT

In the above, the first line allows traffic on port 5432 into the local system from the 10.0.0.90 IP address, which is my development workstation. The second line allows the local system to send traffic out via port 5432, which is the default port used by PostgreSQL.

Conclusion

To allow remote connections to your PostgreSQL instance, all you have to do is edit postgresql.conf and pg_hba.conf. Also remember to address firewall configuration issues that may arise.

Read on my Twitter Stream

Read this on my Twitter stream:

Wealth is our organised capability to cope effectively with the environment to sustain our healthy regeneration and decreasing both the physical and metaphysical restrictions of the forward days of our lives.

from Operating Manual for Spaceship Earth by Buckminster Fuller

What are the genuinely useful ideas in programming?

There is a really interesting article here about "What are the genuinely useful ideas in programming".

The comments are closed for that post, so here are the two things I would add to the list:

  1. Index = Data(Algorithm + Data Structure): Google made this concept relevant, again.
  2. Sensors, and networks of them (not to be confused with scanners (e.g. barcode, QR)): The Arduino and the Raspberry Pi made these important.

Resume interrupted downloads with cURL in Linux

I have recently been trying to download an ISO of a certain Linux distro, but I find myself at the wrong end of a crappy connection. I tried downloading it with both Firefox and Chrome but both choked very early in the process and current speed would go down to 0 and after a while the connection would just cutoff with no way to resume the download from where I left off.

Fear not because [cURL][curl] comes to the rescue. After typing Up-Arrow and Enter more time than I care to admit, I decided to let the computer do the hard work and automate this thing. So I created a small Bash script called acurl.sh (for Automated cURL) that looks like this:

export ec=1;

while [ $ec -gt 0 ]; do
    /usr/bin/curl -O -C - $1;
    export ec=$?;
done

if [ $ec -eq 0 ]; then
    echo "Downloaded $1";
fi

What's going on above is that I have a while loop that is checking the exit code of curl. This exit code is captured by assigning the value of $? to the variable $ec. If curl exit code is larger than 0 then continue trying to download the file, which is represented by parameter $1, from where we left off, which is accomplished by passing the parameter -C to curl.

Assuming that the script above is located somewhere in the $PATH, then using it is as simple as this:

acurl.sh http://distrodomain.org/downloads/linux-distro-version-platform.iso

This is definitely a brute force approach, but it does the work.

[curl]: http://curl.haxx.se/ "cURL"

How to Change the Default Browser in Xubuntu

I am using Xubuntu 12.04 on my main workstation at home and for the longest time I have been trying to make Google Chrome my default browser on that machine. I've tried several things that didn't work or worked but would not persist when I rebooted the machine. Well, that changed just recently...

Recently I found out that there is a configuration file at ~/.local/share/applications/mimeapps.list that you can change and make it stick. Just replace all references to firefox.desktop with google-chrome.desktop.

Here are the relevant current values:

[Added Associations]
x-scheme-handler/http=exo-web-browser.desktop;google-chrome.desktop;
x-scheme-handler/https=exo-web-browser.desktop;google-chrome.desktop;
...
x-scheme-handler/ftp=google-chrome.desktop;
x-scheme-handler/chrome=google-chrome.desktop;
text/html=google-chrome.desktop;
application/x-extension-htm=google-chrome.desktop;
application/x-extension-html=google-chrome.desktop;
application/x-extension-shtml=google-chrome.desktop;
application/xhtml+xml=google-chrome.desktop;
application/x-extension-xhtml=google-chrome.desktop;
application/x-extension-xht=google-chrome.desktop;

[Default Applications]
...
application/x-mimearchive=google-chrome.desktop
...
x-scheme-handler/http=google-chrome.desktop
x-scheme-handler/https=google-chrome.desktop
x-scheme-handler/ftp=google-chrome.desktop
x-scheme-handler/chrome=google-chrome.desktop
text/html=google-chrome.desktop
application/x-extension-htm=google-chrome.desktop
application/x-extension-html=google-chrome.desktop
application/x-extension-shtml=google-chrome.desktop
application/xhtml+xml=google-chrome.desktop
application/x-extension-xhtml=google-chrome.desktop
application/x-extension-xht=google-chrome.desktop

The ... above means that I omitted 1 or more lines for brevity. Hope this works for you too.

Burn an ISO to a USB stick

Several of the Debian CD and Debian Live images are created using isohybrid technology, which means that they may be used in two different ways:

  • They may be written to CD/DVD and used as normal for CD/DVD booting.
  • They may be written to USB flash drives, bootable directly from the BIOS of most PCs.

The most common way to copy an image to a USB flash drive is to use the dd command on a Linux machine:

dd if=file.iso of=/dev/device bs=4M; sync

where:

  • file.iso is the name of the input image, e.g. netinst.iso
  • /dev/device is the device matching the USB flash drive, e.g. /dev/sda, /dev/sdb. Be careful to make sure you have the right device name, as this command is capable of writing over your hard disk just as easily if you get the wrong one!
  • bs=4M tells dd to read/write in 4 megabyte chunks for better performance; the default is 512 bytes, which will be much slower
  • The sync is to make sure that all the writes are flushed out before the command returns.

How to migrate a git repository from GitHub to Gitorious

The other day I had to move a git repository from GitHub to Gitorious and after cracking my head against the wall about this problem for a little while, I think I came up with a pretty elegant solution.

Here are some of the assumptions we are making in this turtorial:

  1. You already have a GitHub and a Gitorious account
  2. You have an existing GitHub repo that you want to move
  3. We will use this repo as the example

Now follow these steps:

  1. Login to Gitorious and create a new Project with a Repo
  2. Find a location on your local system and create a new folder called XmlTidy. I usually do this at ~/Projects
  3. Drop into your new folder and initialize a new git repo in it
  4. Add a remote reference to your GitHub repository called origin
  5. Pull all code from the master branch in origin
  6. Add a remote reference to your Gitorious repository called destination
  7. Push your local master branch to the destination remote repo

Here's the complete code listing for the above narrative:

mkdir ~/Projects/XmlTidy
cd ~/Projects/XmlTidy
git init .
git remote add origin git@github.com:gorauskas/XmlTidy.git
git pull origin master
git remote add destination git@gitorious.org:xmltidy/xmltidy.git
git push destination master

That's it... You're done!