https://www.youtube.com/watch?v=UR_Fp09NC_0
And imagine what Tony would think. Standing there on his brand new feet, on brink of the beginnings of mankind as we know it. If he could look forward, just a few, short, hundreds of millions of years, to see one of his decedents, an Israeli Jew by the name of Jesús, having a nail hammered through his feet. (The very feet that Tony provided him with), as a punishment for having a sort of schizophrenic discourse with a god who was created by man to explain the existence of feet in absence of the knowledge of the existence of Tony.
Sunday, February 7, 2016
Neural Networks and Deep Learning online book
http://neuralnetworksanddeeplearning.com/index.html
I've recently got into the topic of deep learning having been interested in Neural Nets for some years. Here's a good resource. It's a free book that you can donate if you wish.
I've recently got into the topic of deep learning having been interested in Neural Nets for some years. Here's a good resource. It's a free book that you can donate if you wish.
Tuesday, December 29, 2015
How to get π Pi in OSX (use option-p)
It can be really hard to find the Pi character in the Special Character search in OSX. It it buried in the Greek alphabet in the Maths Symbols.
Option-P will print it.
Option-P will print it.
⌥ - P
How to view the Special characters in Xcode. How to get Maths characters
I'm not sure if it has recently changed, but in Xcode when you select Edit -> Emoji & Symbols you get (I think by default) this smaller Special Chars tool.
To get access to the more familiar view with a search select the icon in the top right.

The view I am more familiar with with a search and math category.

To get access to the more familiar view with a search select the icon in the top right.

The view I am more familiar with with a search and math category.

Monday, December 28, 2015
Closures syntax simplification in Swift
I think the process of simplification for the closure syntax is quite interesting
This is an initial way of passing a function as an argument, sometime called a delegate function. The example is a simply multiplication of two numbers.
This is an initial way of passing a function as an argument, sometime called a delegate function. The example is a simply multiplication of two numbers.
func doSomething(operation: (Double, Double) -> Double) {
theReturnValue = operation( 2, 3)
}
func multiply(op1: Double, op2: Double) -> Double {
return op1 * op2
}
// The main calling of the method
DoSomething(multiply)
The first step that Swift makes to simplify this is to make the multiply function an inline function, a lambda or Closure. We place the code inline, use the "in" keyword and move the curly brace.
func doSomething(operation: (Double, Double) -> Double) {
theReturnValue = operation( 2, 3)
}
func multiply(op1: Double, op2: Double) -> Double {
return op1 * op2
}// The main calling of the method
DoSomething( { op1: Double, op2: Double) -> Double in
return op1 * op2
})
But is tidied up further because Swift, like C# in this situation, is very good with type inference. So we can remove the type declaration of the arguments and return type because it already knows them.
func doSomething(operation: (Double, Double) -> Double) {
theReturnValue = operation( 2, 3)
}
// The main calling of the method
DoSomething({ (op1:, op2:) -> in
return op1 * op2
})
Now we can tidy this up a little, by putting the return on the same line as the declaration
, but also remove the return keyword because we are returning an expression and it knows we are going to return a Double.
func doSomething(operation: (Double, Double) -> Double) {
theReturnValue = operation( 2, 3)
}
// The main calling of the method
DoSomething({ (op1:, op2:) -> in op1 * op2 })
Cool. But Swift doesn't need you to name the arguments as it will use $0 and $1 for the first two args if names are not provided. So we can write:
func doSomething(operation: (Double, Double) -> Double) {
theReturnValue = operation( 2, 3)
}
// The main calling of the method
DoSomething({ $0 * $1 })
One last thing. The last argument can be moved outside of the parenthesis.
func doSomething(operation: (Double, Double) -> Double) {
theReturnValue = operation( 2, 3)
}
// The main calling of the method
DoSomething() { $0 * $1 }
Other arguments would go inside the parenthesis of DoSomething(...), but in this case there are no other args so we can remove the parenthesis entirely.
func doSomething(operation: (Double, Double) -> Double) {
theReturnValue = operation( 2, 3)
}
// The main calling of the method
DoSomething { $0 * $1 }
Quite interesting.
Monday, December 21, 2015
How to remove backups from Time Machine
We have a few Macs in the house and a few Time Machine devices setup. As a number of Macs share a Time Machine disk I have found that one Macs' backups can monopolise the disk through one reason or another which prevents another mac from doing a backup because of lack of space.
I could have managed this better by partitioning the disk and that's something I'll do in future, but for the time being I wanted to remove some old unwanted backups to free up some space.
This can take a very long time.
To remove a specific backup I used Time Machine Utility:
sudo tmutil delete /Volumes/drive_name/Backups.backupdb/mac_name/YYYY-MM-DD-hhmmss
I compacted the remaining sparse file by using
sudo hdiutil compact [path and name of sparsefile]
You can list the backups by using:
tmutil list backups
I could have managed this better by partitioning the disk and that's something I'll do in future, but for the time being I wanted to remove some old unwanted backups to free up some space.
This can take a very long time.
To remove a specific backup I used Time Machine Utility:
sudo tmutil delete /Volumes/drive_name/Backups.backupdb/mac_name/YYYY-MM-DD-hhmmss
I compacted the remaining sparse file by using
sudo hdiutil compact [path and name of sparsefile]
You can list the backups by using:
tmutil list backups
Unavailable
If you see the time machine is unavailable then you probably have it mounted and this will prevent you from deleting files. Unmount (eject) and try again.tmutil docs
https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man8/tmutil.8.htmlhdiutil docs
https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/hdiutil.1.htmlSunday, December 20, 2015
Python Virtualenv on OSX
Install virtualenv
Johns-MBP:~ johnroberts$ pip install virtualenv
Johns-MBP:~ johnroberts$ mkdir -p ~/Virtualenvs
Johns-MBP:~ johnroberts$ mkdir -p ~/Projects
Johns-MBP:~ johnroberts$ cd ~/Virtualenvs/
Create the virtual environments
Johns-MBP:~ johnroberts$ virtualenv foobar
New python executable in foobar/bin/python2.7
Also creating executable in foobar/bin/python
Installing setuptools, pip, wheel...done.
Johns-MBP:~ johnroberts$ virtualenv -p python3 foobar-py3
Running virtualenv with interpreter /usr/local/bin/python3
Using base prefix '/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5'
New python executable in foobar-py3/bin/python3.5
Also creating executable in foobar-py3/bin/python
Installing setuptools, pip, wheel...done.
This should get Virtualenv in place.
Activate an environment
We made the Python environment, now we need to activate it.
Johns-MBP:~ johnroberts$ source foobar/bin/activate
(foobar)Johns-MBP:~ johnroberts$
Notice the "(foobar)" which shows that we are now in the environment.
What version of python are we using
We can check which version of python
(foobar)Johns-MBP:~ johnroberts$ which python
/Users/johnroberts/foobar/bin/python
This shows that we are using python from our environment.
(foobar)Johns-MBP:~ johnroberts$ python --version
Python 2.7.10
We can also check pip
(foobar)Johns-MBP:~ johnroberts$ which pip
/Users/johnroberts/foobar/bin/pip
Use pip to see what packages are here
(foobar)Johns-MBP:~ johnroberts$ pip list
pip (7.1.2)
setuptools (18.2)
wheel (0.24.0)
If I did pip list outside of this environment I'd get a lot of packages (I won't list them here)
Install the packages for this environment
(foobar)Johns-MBP:~ johnroberts$ pip install numpy
Collecting numpy
Downloading numpy-1.10.2-cp27-none-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (3.7MB)
100% |████████████████████████████████| 3.7MB 143kB/s
Installing collected packages: numpy
Successfully installed numpy-1.10.2
Cool as a cucumber.
List of Dependencies
Make a list of dependencies for this project and view it using cat
(foobar)Johns-MBP:~ johnroberts$ pip freeze --local > requirements.txt
(foobar)Johns-MBP:~ johnroberts$ cat requirements.txt
numpy==1.10.2
wheel==0.24.0
The list of dependencies is very useful for recreating other environments using pip. Create the environment and then use pip and the requirements.txt file to install the dependencies.
pip install -r requirements.txt
pip install -r requirements.txt
Get out of the environment - deactivate
We just type deactivate
(foobar)Johns-MBP:~ johnroberts$ deactivate
Johns-MBP:~ johnroberts$
Notice that "(foobar)" has been removed. We are no longer in that environment.
Remove the Virtual Environment
Once deactivated, we can remove:
Johns-MBP:~ johnroberts$ rm -rf foobar/
Simple.
Saturday, December 19, 2015
Latest Python on El Capitan
El Capitan OSX comes with Python 2.7 but you might like to get the latest version and ensure you keep it updated.
I use Homebrew which was installed before I updated Python so I won't write how to install it.
Find http://brew.sh
xcode-select --install
brew install python
pip all be installed by brew
brew install python3
I use Homebrew which was installed before I updated Python so I won't write how to install it.
Find http://brew.sh
GCC
You will need the latest GCC compiler. For that you can instal Xcode. If you instal a fresh version on Xcode you might need to run the following to install the command line tools:xcode-select --install
Python 2.7
Run the following:brew install python
pip all be installed by brew
Python 3
Run the following:brew install python3
Virtualenv
If you're running two versions of Python on the same system you may benefit from looking at virtualenvSaturday, October 24, 2015
Installing numpy and scipy for OSX - using Homebrew
The place I found for instructions on how best to do this, and it has been edited recently, is
https://joernhees.de/blog/2014/02/25/scientific-python-on-mac-os-x-10-9-with-homebrew/
I have copied the script from Jörn's page to here for my personal reference. But all credit is Jörn's
I did need X11 installed and I thought this was possible via Homebrew but I had a problem so I resorted to downloading it from Quartz page. It took a while. It used to be distributed by Apple but no longer.
# install PIL, imagemagick, graphviz and other
# image generating stuff
brew install libtiff libjpeg webp little-cms2
pip install Pillow
brew install imagemagick --with-fftw --with-librsvg --with-x11
brew install graphviz --with-librsvg --with-x11
brew install cairo
brew install py2cairo # this will ask you to download xquartz and install it
brew install qt pyqt
# install virtualenv, nose (unittests & doctests on steroids)
pip install virtualenv
pip install nose
# install numpy and scipy
# there are two ways to install numpy and scipy now: via pip or via brew.
# PICK ONE, i prefer pip for proper virtualenv support and more up-to-date versions.
pip install numpy
pip install scipy
# OR:
# (if you want to run numpy and scipy with openblas also remove comments below:)
#brew install openblas
brew install numpy # --with-openblas
brew install scipy # --with-openblas
# test the numpy & scipy install
python -c 'import numpy ; numpy.test();'
python -c 'import scipy ; scipy.test();'
# some cool python libs (if you don't know them, look them up)
# matplotlib: generate plots
# pandas: time series stuff
# nltk: natural language toolkit
# sympy: symbolic maths in python
# q: fancy debugging output
# snakeviz: cool visualization of profiling output (aka what's taking so long?)
#brew install Caskroom/cask/mactex # if you want to install matplotlib with tex support and don't have mactex installed already
brew install matplotlib --with-cairo --with-tex # cairo: png ps pdf svg filetypes, tex: tex fonts & formula in plots
pip install pandas
pip install nltk
pip install sympy
pip install q
pip install snakeviz
# ipython with parallel and notebook support
brew install zmq
pip install ipython[all]
# html stuff (parsing)
pip install html5lib cssselect pyquery lxml BeautifulSoup
# webapps / apis (choose what you like)
pip install Flask Django tornado
# semantic web stuff: rdf & sparql
pip install rdflib SPARQLWrapper
# graphs (graph metrics, social network analysis, layouting)
pip install networkx
brew install graph-tool
# maintenance: updating pip libs
pip install pip-tools # you'll then have a pip-review command, see Updating section below
https://joernhees.de/blog/2014/02/25/scientific-python-on-mac-os-x-10-9-with-homebrew/
I have copied the script from Jörn's page to here for my personal reference. But all credit is Jörn's
I did need X11 installed and I thought this was possible via Homebrew but I had a problem so I resorted to downloading it from Quartz page. It took a while. It used to be distributed by Apple but no longer.
Notice that some files are downloaded from pip and not brew.
Also, I installed the brew install Caskroom/cask/mactex so that I could run matpltlib with latex fonts and formulas. This does take a while to download. Not sure why.
Possible errors when installing pip pyquery and lxml
You might find compile errors fatal error: 'libxml/xmlversion.h' file not found
You can google solutions to this and this link has a few approaches to solve the problem:
# install PIL, imagemagick, graphviz and other
# image generating stuff
brew install libtiff libjpeg webp little-cms2
pip install Pillow
brew install imagemagick --with-fftw --with-librsvg --with-x11
brew install graphviz --with-librsvg --with-x11
brew install cairo
brew install py2cairo # this will ask you to download xquartz and install it
brew install qt pyqt
# install virtualenv, nose (unittests & doctests on steroids)
pip install virtualenv
pip install nose
# install numpy and scipy
# there are two ways to install numpy and scipy now: via pip or via brew.
# PICK ONE, i prefer pip for proper virtualenv support and more up-to-date versions.
pip install numpy
pip install scipy
# OR:
# (if you want to run numpy and scipy with openblas also remove comments below:)
#brew install openblas
brew install numpy # --with-openblas
brew install scipy # --with-openblas
# test the numpy & scipy install
python -c 'import numpy ; numpy.test();'
python -c 'import scipy ; scipy.test();'
# some cool python libs (if you don't know them, look them up)
# matplotlib: generate plots
# pandas: time series stuff
# nltk: natural language toolkit
# sympy: symbolic maths in python
# q: fancy debugging output
# snakeviz: cool visualization of profiling output (aka what's taking so long?)
#brew install Caskroom/cask/mactex # if you want to install matplotlib with tex support and don't have mactex installed already
brew install matplotlib --with-cairo --with-tex # cairo: png ps pdf svg filetypes, tex: tex fonts & formula in plots
pip install pandas
pip install nltk
pip install sympy
pip install q
pip install snakeviz
# ipython with parallel and notebook support
brew install zmq
pip install ipython[all]
# html stuff (parsing)
pip install html5lib cssselect pyquery lxml BeautifulSoup
# webapps / apis (choose what you like)
pip install Flask Django tornado
# semantic web stuff: rdf & sparql
pip install rdflib SPARQLWrapper
# graphs (graph metrics, social network analysis, layouting)
pip install networkx
brew install graph-tool
# maintenance: updating pip libs
pip install pip-tools # you'll then have a pip-review command, see Updating section below
Sunday, August 9, 2015
Problem with NodeJs - node --debug server.js:72 - throw er; // Unhandled 'error' event
When playing around with debugging NodeJs and entering the following:
$ node --debug server.js
I got this error:
events.js:72
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE
at errnoException (net.js:905:11)
at Server._listen2 (net.js:1043:14)
at listen (net.js:1065:10)
This is caused by starting and stopping these debug processes, but leaving one running.
Run the following to identify the running process and then kill it.
Johns-MBP:server john$ ps aux | grep node
This will present something like this:
john 2799 0.0 0.3 3129308 52852 ?? S 11:38AM 0:01.30 /usr/local/Cellar/nvm/0.18.0/v0.10.33/bin/node --debug-brk=49961 --nolazy server.js
john 3023 0.0 0.0 2432772 660 s002 S+ 2:37PM 0:00.00 grep node
This has told us the processId to kill. So run kill -9 [the process id]
eg
Johns-MBP:server johnroberts$ kill -9 2799
Subscribe to:
Posts (Atom)