Friday, May 10, 2019

Error starting Rabbitmq on MacOS

After having problems with my Homebrew I had to reinstall a few things. A month or so later I found I had forgotten to reinstall RabbitMq so I did the usual:

brew install rabbitmq

I went to:

cd /usr/local/sbin

Then I started rabbitmq:


which resulted in an error:

JMBP:sbin johnroberts$ ./rabbitmq-server 

  ##  ##
  ##  ##      RabbitMQ 3.7.14. Copyright (C) 2007-2019 Pivotal Software, Inc.
  ##########  Licensed under the MPL.  See
  ######  ##
  ##########  Logs: /usr/local/var/log/rabbitmq/rabbit@localhost.log

              Starting broker...
{"Kernel pid terminated",application_controller,"{application_start_failure,rabbit,{{schema_integrity_check_failed,[{table_attributes_mismatch,rabbit_exchange,[name,type,durable,auto_delete,internal,arguments,scratches,policy,operator_policy,decorators,options],[name,type,durable,auto_delete,internal,arguments]}]},{rabbit,start,[normal,[]]}}}"}
Kernel pid terminated (application_controller) ({application_start_failure,rabbit,{{schema_integrity_check_failed,[{table_attributes_mismatch,rabbit_exchange,[name,type,durable,auto_delete,internal,ar

Crash dump is being written to: /usr/local/var/log/rabbitmq/erl_crash.dump...done

Looking at $PATH

echo $PATH

I noticed rabbitmq was not in there so I added it.

Still no good!

I then noticed that the error referred to a table and that the error log file referred to a database directory:

 database dir   : /usr/local/var/lib/rabbitmq/mnesia/rabbit@localhost

I had a hunch that removing rabbitmq the first time probably didn't remove the database directory and the new install was probably incompatible with what was in there.

So I uninstalled rabbitmq using
 brew uninstall rabbitmq

and noticed the db directory was still there.
So I removed the directory.

Reinstalled rabbitmq.
Started it.
And jolly good news.

  ##  ##
  ##  ##      RabbitMQ 3.7.14. Copyright (C) 2007-2019 Pivotal Software, Inc.
  ##########  Licensed under the MPL.  See
  ######  ##
  ##########  Logs: /usr/local/var/log/rabbitmq/rabbit@localhost.log

              Starting broker...

 completed with 7 plugins.


Comprehending Monads by Philp Wadler. Probably the first time Monads could be used to structure programs

If you're interested in the origins and why's of the Functional Programming idea then this is an interesting read.  In the 1960's monads were invented by Category theorists. In the 1970's Functional programmers invented list comprehensions. This paper shows how the two come together.

Why Functional Programming Matters, John Hughes The University, Glasgow

A really interesting paper by John Hughes though really quite old now.

As software becomes more and more complex, it is more and more important to structure it well. Well-structured software is easy to write and to debug, and provides a collection of modules that can be reused to reduce future programming costs. In this paper we show that two fea- tures of functional languages in particular, higher-order functions and lazy evaluation, can contribute significantly to modularity. As examples, we manipulate lists and trees, program several numerical algorithms, and implement the alpha-beta heuristic (an algorithm from Artificial Intelligence used in game-playing programs). We conclude that since modularity is the key to successful programming, functional programming offers important advantages for software development.

Sunday, March 18, 2018

Matplotlib.pyplot not working on Mac in virtualenv

I had a very curious problem where python would not find pyplot in matplotlib.

I was using:

  • python3
  • virtualenv
  • matplotlib

To create the virtual environment I used: 
virtualenv -p python3 <myproject name>

However, when I used:
python3 -m venv <myproject name>

It worked ok.

An explanation was found here:

Sunday, January 15, 2017

How to update a console line without writing a new line in python3

import time
import sys
print('Update the same line in console output')

sys.stdout.write('Doing task a\r')
sys.stdout.write('Doing task b\r')
sys.stdout.write('Doing task c\n')

Saturday, December 24, 2016

Python how to swap two values in one line of code - tuple unpacking

 A common problem we need to solve is how to swap two values
 For example if we have to variables x and y, 
 we might want to swap the
 the values.  

 x = 123
 y = 456
 print('Start values:  a = {} b = {} '.format(x, y))

 temp = x
 x = y
 y = temp
 print('Finish values: a = {} b = {} '.format(x, y))

 A better, more succinct method is to use the cool 'tuple unpacking'

 x = 123
 y = 456
 print('Start values:  a = {} b = {} '.format(x, y))

 x, y = y, x
 print('Finish values: a = {} b = {} '.format(x, y))

Sunday, November 27, 2016

Best way to transfer files to and from Raspberry Pi using Mac

I've been messing about with scp and ftp and now have stumped across a really happy solution for my Mac.

As I use Pycharm to develop my python files it is handy to have a method that uses finder to manage the files. Hard-core folks might be happiest with emacs and scp etc.

So, on the Raspberry Pi. run:
apt-get install netatalk

Then on the Mac in a terminal:

open afp:// 
replace the above ip address with that of your Raspberry Pi.

This will install Apple talk protocol onto the Pi which means that the Pi can appear in the Finder.

Sunday, October 2, 2016

If n people are tested positive for an illness with x probability of accuracy, how confident are we that you are sick?

Yet another way of explaining Bayes's conditional probability.

I found this from Hilary Mason, who in turn heard it from Jake Hofman and Chris Wiggins.

If there are 10,000 people.
1% are sick.
The test has a 99% confidence of accuracy
Given a positive result, what is the probability that you are sick?

10% of 10,000 is 100 - 100 people test positive. 99% accuracy means that we expect 99 people to be sick and not the whole 100.

But also, of the remaining 10,000 - 100 people, 99% will have tested incorrectly so 1% of that group will be ill. 1% of 9900 = 99.

So in total, we have 99 sick people testing positive
And 99 healthy people being positive.

So, if you test positive you have a 50% chance of being sick.

Sunday, September 11, 2016

How to use my own text in NLTK?

The best explanation I have found of this is in the 3 hour presentation by Benjamin Bengfort.

Click on the link above and it should take you to 53:40 in the video where he talks about how this.

Friday, September 9, 2016

Resources for learning NLTK

Some great resources:

The incredible video series from Harrison.
This take you through the theory of NLP with NLTK.

And from the same nice chap,

Another very good lecture:

District Data Labs exercises from a workshop.

A talk on product categorisation