Starting Phoenix server in a different port than 4000


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


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


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:


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


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


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


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


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


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.


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:

(issues) lib/issues/github_issues.ex:14: Issues.GithubIssues.handle_response({:error, %HTTPoison.Error{id: nil, reason: :connect_timeout}})


Trying to follow the example in ‘Programming Elixir 1.2’ for fetching the issues from Github you are getting the following error:


You are quite likely behind a proxy and you get a timeout. Add the proxy details to the HTTPoison.get request as follows:

And you could make the following change to the github_issues.ex file to be able to work with the proxy:

So you can call it like the following from iex:

function for getting the bitmask integer value in PostgreSQL


You have set up some bitmask values and you would like to return the calculated value given a string with one or more of the codes used, to be able to used it in an SQL query.


You can use the following to create a function called bitmask. This one deals with any number of individual codes (2 and 3 digit codes in this case).
It also does not calculate duplicate values since they are removed.
So for this example the string ’02a’ is the same as ’02a,02a’ and should give 16 in both cases.

ActiveRecord::InvalidForeignKey: PG::ForeignKeyViolation: ERROR: …


You have a Ruby on Rails application/engine with some tests in Minitest and using postgresql as the db. In the original development environment all the tests that use fixtures and foreign key validations pass, but when you try to move to a different environment with new database some or all of you tests fail with a message that refers to the ForeignKeyViolation as in:


Since active record disables the foreign keys before loading the fixtures in the database, the user that you run the tests with needs to have superuser permissions in the test database. Otherwise the fixtures are not loaded. So add the superuser permissions to your user:

You may need to drop and create your test database.

unhandled &1 outside of a capture


Running something like the following in iex:

results in the following error:


Since the shortcut has been changed you will need to do the following: