Archive

Archive for April, 2016

Generating a random string

April 30, 2016 Leave a comment

Problem: You want to generate some random strings.

Solution:

$ 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
Da86DdCu/fyqdZasjzMA3sn0Psq+v5nogGKXtZTLgWE=

$ 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
ovuUVjbLD4QG3ZkyzFjUJ7ntbdmXpI81VoZsg/42Png=

$ dd if=/dev/urandom count=1 bs=32|base64
1+0 records in
1+0 records out
jHNLGhNI9bgxfXNMgA423dD1MDBNf4JUgO0LFnMOjMQ=
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.
Done.

Categories: bash Tags:

xterm colors

April 30, 2016 Leave a comment

Problem:
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.

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 "192.168.33.10" 
and accepting TCP/IP connections on port 5432? 

Solution:

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.
   config.vm.network "forwarded_port", guest: 5432, host: 5431

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

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
#------------------------------------------------------------------------------
# CONNECTIONS AND AUTHENTICATION
#------------------------------------------------------------------------------

# - 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             127.0.0.1/32            md5
host    all             all             192.168.33.10/24        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

Problem:
I needed to install graphite on a Ubuntu box on vagrant. The instructions on http://graphite.readthedocs.org/en/latest/index.html were not for the faint-hearted. But after 5mins on google I got the following guide from digitalocean.com.

Solution:
https://www.digitalocean.com/community/tutorials/how-to-install-and-use-graphite-on-an-ubuntu-14-04-server

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

tasks:
        - 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=https://tpo.pe/pathogen.vim dest=/home/vagrant/.vim/autoload/pathogen.vim mode=0677

        - name: "Install vim-virtualenv"
          git: repo=https://github.com/jmcantrell/vim-virtualenv.git
               dest=/home/vagrant/.vim/bundle/vim-virtualenv

        - name: "Install vim-airline"
          git: repo=https://github.com/vim-airline/vim-airline
               dest=/home/vagrant/.vim/bundle/vim-airline

        - 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=https://github.com/vim-airline/vim-airline-themes
               dest=/home/vagrant/.vim/bundle/vim-airline-themes

        - name: "Install vim-fugitive"
          git: repo=https://github.com/tpope/vim-fugitive.git
               dest=/home/vagrant/.vim/bundle/vim-fugitive

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

        - name: " Copy vimrc config"
          copy:
                src=/home/rodnee/files/vimrc
                dest=/home/vagrant/.vimrc
                group=vagrant

Categories: vagrant, vim

Installing vim-airline

April 14, 2016 Leave a comment

Problem:
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.

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

mkdir -p ~/.vim/autoload ~/.vim/bundle && curl -LSso ~/.vim/autoload/pathogen.vim https://tpo.pe/pathogen.vim

2. Install vim-airline

git clone https://github.com/vim-airline/vim-airline ~/.vim/bundle/vim-airline

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

git clone https://github.com/vim-airline/vim-airline-themes ~/.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.
Without_encoding

And when you set the encoding.
With_encoding

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

git clone git://github.com/tpope/vim-fugitive.git ~/.vim/bundle/vim-fugitive

5. Install powerline fonts

cd ~/.vim
git clone https://github.com/powerline/fonts.git
cd fonts/
./install.sh

Thats it.

Note:
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.

Source:
https://github.com/vim-airline/vim-airline
https://github.com/vim-airline/vim-airline-themes
https://github.com/tpope/vim-fugitive
https://github.com/powerline/fonts