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
Follow

Get every new post delivered to your Inbox.

Join 44 other followers