Archive for April, 2016

Generating a random string

April 30, 2016 Leave a comment

Problem: You want to generate some random strings.


$ dd if=/dev/urandom count=1 bs=32|base64
1+0 records in
1+0 records out
32 bytes (32 B) copied, 5.7006e-05 s, 561 kB/s

$ dd if=/dev/urandom count=1 bs=32|base64
1+0 records in
1+0 records out
32 bytes (32 B) copied, 5.444e-05 s, 588 kB/s

$ dd if=/dev/urandom count=1 bs=32|base64
1+0 records in
1+0 records out
32 bytes (32 B) copied, 0.000972518 s, 32.9 kB/s
Categories: bash Tags: , ,

Adding and deleting users in Ubuntu

April 30, 2016 Leave a comment

Well I keep on forgetting how to do this.

$ sudo adduser 2>/dev/null –system –group rodnee
Adding system user `rodnee’ (UID 109) …
Adding new group `rodnee’ (GID 115) …
Adding new user `rodnee’ (UID 109) with group `rodnee’ …
Creating home directory `/home/rodnee’ …

$ sudo deluser –remove-home rodnee
Looking for files to backup/remove …
Removing files …
Removing user `rodnee’ …
Warning: group `rodnee’ has no more members.

Categories: bash Tags:

xterm colors

April 30, 2016 Leave a comment

Editing a file using vim looks like this:
Screen Shot 2016-04-30 at 12.29.40

instead of this (ie note the colors):
Screen Shot 2016-04-30 at 12.30.06

This happens to me on freshly set up vagrant boxes. I am yet to find a permanent solution.

Run the following command and try again.

$ export TERM=xterm-256color

Allow remote hosts to connect to PostgreSQL database server on vagrant box

April 26, 2016 Leave a comment

Problem: How to connect to PostgreSQL database server on a vagrant box.
Getting the following error when trying to connect using pgAdmin3.

could not connect to server: 
Connection refused Is the server running on host "" 
and accepting TCP/IP connections on port 5432? 


1. Ensure you have forwarded the ports on the vagrant box.

$less Vagrantfile
  # Create a forwarded port mapping which allows access to a specific port
  # within the machine from a port on the host machine. In the example below,
  # accessing "localhost:8080" will access port 80 on the guest machine. "forwarded_port", guest: 5432, host: 5431

  # Create a private network, which allows host-only access to the machine
  # using a specific IP. "private_network", ip: ""

2. Install postgresql database. As per instructions here.

3. Create a user and a database. As per examples here.

4. Change listen_addresses

$ sudo vim /etc/postgresql/9.4/main/postgresql.conf

# - Connection Settings -

listen_addresses = '*'         # what IP address(es) to listen on;
                                        # comma-separated list of addresses;
                                        # defaults to 'localhost'; use '*' for all
                                        # (change requires restart)
port = 5432                             # (change requires restart)

5. Add the ip of the vagrant box to pg_hba.conf

$ sudo vim /etc/postgresql/9.4/main/pg_hba.conf
# IPv4 local connections:
host    all             all               md5
host    all             all           md5

6. Restart PostgreSQL database server.

$ sudo service postgresql restart
 * Restarting PostgreSQL 9.4 database server                                      [ OK ]

You should now be able to connect.

Python frameworks and books

April 25, 2016 Leave a comment
Categories: Interesting, python

Installing Graphite

April 19, 2016 Leave a comment

I needed to install graphite on a Ubuntu box on vagrant. The instructions on were not for the faint-hearted. But after 5mins on google I got the following guide from


The Real Reason to Not Use SIGKILL

April 18, 2016 Leave a comment
Categories: funny

Using Ansible to install vim-airline

April 16, 2016 Leave a comment

Problem: Automate the installation of vim-airline on a vagrant box.

Solution: Ansible.

- name: Configure VM with vim-airline and other plugins.
  hosts: testserver
  become: yes
  become_method: sudo
  become_user: vagrant

        - name: "Run apt-get update"
          become_user: root
          apt: update_cache=yes

        - name: "Install git"
          become_user: root
          apt: name=git state=present

        - name: "Creates vim autoload directory"
          file: path=/home/vagrant/.vim/autoload state=directory

        - name: "Creates vim bundle directory"
          file: path=/home/vagrant/.vim/bundle state=directory

        - name: "Download pathogen"
          get_url: url= dest=/home/vagrant/.vim/autoload/pathogen.vim mode=0677

        - name: "Install vim-virtualenv"
          git: repo=

        - name: "Install vim-airline"
          git: repo=

        - name: "Run helptags vim-airline"
          command: vim -u NONE --cmd "helptags /home/vagrant/.vim/bundle/vim-airline/doc" --cmd q

        - name: "Install vim-airline-themes"
          git: repo=

        - name: "Install vim-fugitive"
          git: repo=

        - name: "Run helptags vim-fugitive"
          command: vim -u NONE --cmd "helptags ~/.vim/bundle/vim-fugitive/doc" --cmd q

        - name: " Copy vimrc config"

Categories: vagrant, vim

Installing vim-airline

April 14, 2016 Leave a comment

Decided to try out vim-airline. So I had to find out how to install it and ended up installing some other plugins as well, as they looked like nice features to have.

1. Install Pathogen. This is a popular vim plugin manager.

mkdir -p ~/.vim/autoload ~/.vim/bundle && curl -LSso ~/.vim/autoload/pathogen.vim

2. Install vim-airline

git clone ~/.vim/bundle/vim-airline

3. Install vim-airline-themes
For different vim-airline themes.

git clone ~/.vim/bundle/vim-airline-themes

3. Update your ~/.vimrc with the following settings.

$ less vimrc
" To update the status line, so that you have the colourful status bar. If it is not set you will not see any change when you start up vim.
" Set a status line
set laststatus=2

" Set encoding so that your fonts look okay.
set encoding=utf-8

execute pathogen#infect()
filetype plugin indent on

" Enable powerline fonts
let g:airline_powerline_fonts = 1

Here is how it looks when your encoding is wrong.

And when you set the encoding.

4. Install vim-fugitive
If you want to be able to see the git branch that you are working in

git clone git:// ~/.vim/bundle/vim-fugitive

5. Install powerline fonts

cd ~/.vim
git clone
cd fonts/

Thats it.

Everything is going into ~/.vim/bundle which is created in the first step.

If the arrows or symbols look misaligned (either too big or too small), try to increase or decrease the size of the font you are using on the terminal window. You can do that in the terminal settings.

Changing fonts

I have the 12pt Monaco font as well as the 12pt Non ASCII Sauce Code Powerline font. Have something similar to avoid any headaches.