Removing Docker containers that have exited

Problem

You would like to clear Docker containers that have been exited and not cleared properly.

Solution

Run the following to find out the containers that have exited and remove them.

Error response from daemon: conflict: unable to delete xxx (must be forced) – image is referenced in one or more repositories

Problem

Trying to remove some unused docker images that you no longer use with docker rmi image_id you get the following error message:

Solution

Use the following to delete multiple images (ie ubuntu):

Mentioned here

Starting Phoenix server in a different port than 4000

Problem

You would like start a phoenix application in a port different from the default 4000, by using something similar to the rails:

Solutin

You will need to change the config/dev.exs file to include the following:

and then start the server with:

Taken from the answer here

Routing rspec with nested routes

Problem

You would like to add a routing rspec test in your rails application that tests for a nested route.
So while you have something like the following in your config/routes.rb file:

you want to add the following test for your route:

but you are getting an error like the following:

Solution

You will need to change your rspec to the following using any number for the user_id:

Solution adapted from here

Removing git branches from local repository

Problem

You would like to remove your local branches that were used to track remote branches that no longer exists (deleted after merge).

Solution

To delete your local branch you could use the following:

And to to delete the remote tracking branching you could use the following:

Resetting sequence number in PostgreSQL

Problem

While issuing the query TRUNCATE table TABLE_NAME works for MySQL for restarting the id of the table, this does not work with PostgreSQL.

Solution

In order to restart the sequence of the table in PostgreSQL you will have to issue the following:

from here

Stopping a blocking query in postgresql

Problem

You run a query in PostgreSQL that takes a lot of time to finish (maybe because of an error) and you want to stop/kill it as it is blocking other queries in db.

Solution

You will need to find the pid for the query, either by using a GUI program like Pgadmin or by issuing the following to an SQL prompt:

make a note of the pid of the query that you want to stop/kill and issue the following: