Creating a simple rails docker image for testing in cloud deployment

Trying to deploy a rails application in a cloud provider ie dreamhost, that uses OpenStack these are the steps needed:

  1. Install docker in your development machine and your cloud provider by following the installation instructions from here
  2. Create an account in Docker Hub, that will be needed later on to push your docker image with the application
  3. Pull the official rails docker image to your development environment:
    sudo docker pull rails:latest
    
  4. Create a new simple rails application:
    rails new docker_test
  5. Change to the application directory and add a Dockerfile in the root directory containing the following:
    FROM rails:onbuild
  6. Build your new image by using:
    sudo docker build -t rails_docker_test .
  7. Check that your image was build by using:
    sudo docker images
  8. Start the container with:
    sudo docker run --name rails_test -p 0.0.0.0:3000:3000 -d rails_docker_test
  9. Make sure that you can see the initial rails page by using your browser to go to http://127.0.0.1:3000
  10. Push your image to your Docker Hub account by first logging in to it from the command line:
    sudo docker login --username=yourhubusername --email=youremail@company.com

    , and then when you get ‘Login Succeeded’, push your image to your account:

    sudo docker push yourhubusername/rails_docker_test
  11. TBC

Replacing spaces with underscores in linux busybox

Problem

You want to replace the spaces in filenames (ie in Brennan’s B2 system), that uses busybox and you do not have all the linux commands available.

Solution

Use the following in the directory with the files (ie flac files). At the moment this command only works in the directory that is being run.

# find . -type f -name "*.flac" -exec ash -c 'mv "$0" "${0// /_}"' '{}' ';'

Terminate/Kill unused guest sessions in linux

Problem

You have started a couple of guest linux sessions on your pc, that you do not need anymore (ie giving access to your children while on holiday 🙂 ), and you want to close them from your own session.

Solution

Find out about the guest users by using who:

who
...
guest-kk9tnS :2           2015-08-09 17:39 (:2)
guest-kk9tnS pts/21       2015-08-09 17:40 (:2)

and then kill the sessions using pkill:

sudo pkill -9 -u guest-kk9tnS

Combine .img OpenStreetMap files to use in a Garmin GPS

Problem

You would like to create your own map that includes different tiles and upload it into your Garmin’s SD card.

Solution

  • Make sure that your SD card is formatted with the FAT32 file system and not with the default exFAT that comes as standard in some > 32GB SD cards. There is no limit in the size that your Garmin can read provided is FAT32.
  • In your SD card create a directory called Garmin if it does not exist.
  • Download the latest version of the program mkgmap from here
  • Put all your .img tile files in a directory called my_tiles for example.
  • Go to the directory that you downloaded the mkgmap zip file and extract the files
  • Run the following to combine them all toghether:
    ./mkgmap.jar --gmapsupp  $( ls my_tiles/*.img )
  • Rename the resulting image file and upload it to your Garmin SD card inside the Garmin folder

Password protect a pdf file in linux using pdftk

Problem

You have a pdf file with sensitive information and you want to protect it with a password.

Solution

Install the pdftk if you haven’t already in your system:

sudo apt-get install pdftk

And then run the following to prompt for a password before opening the file:

pdftk original.pdf output pswd_protected.pdf user_pw PROMPT

ERROR: could not open extension control file “/usr/share/postgresql/9.3/extension/plr.control”: No such file or directory

Problem

You are trying to install the PL/R extension to PostgreSQL, after install R in your linux ubuntu development environment, but when trying to install the extension inside your PostgresSQL with:

create extension plr;

you are getting the following error:

ERROR:  could not open extension control file "/usr/share/postgresql/9.3/extension/plr.control": No such file or directory

Solution

Install the necessary package for your PostgreSQL version with the following, and install the extension in your psql:

sudo apt-get install postgresql-9.x-plr