Useful pieces of code to use with Docker.
boot2docker start
eval "$(boot2docker shellinit)"
{% with messages = get_flashed_messages(with_categories=true) %} | |
<!-- Categories: success (green), info (blue), warning (yellow), danger (red) --> | |
{% if messages %} | |
{% for category, message in messages %} | |
<div class="alert alert-{{ category }} alert-dismissible" role="alert"> | |
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button> | |
<!-- <strong>Title</strong> --> {{ message }} | |
</div> | |
{% endfor %} | |
{% endif %} |
def datenum_to_datetime(datenum): | |
""" | |
Convert Matlab datenum into Python datetime. | |
:param datenum: Date in datenum format | |
:return: Datetime object corresponding to datenum. | |
""" | |
days = datenum % 1 | |
hours = days % 1 * 24 | |
minutes = hours % 1 * 60 |
def datetime_to_timestamp(dt, epoch=datetime(1970, 1, 1)): | |
""" | |
Convert datetime into timestamp (in seconds). | |
:param dt: Datetime object to convert | |
:param epoch: Base Epoch to be counted from, default is 01.01.1970 | |
:return: Number of seconds since the Epoch | |
""" | |
return int((dt - epoch).total_seconds()) |
Explanations of how to install and use IPython Notebook with a venv and multiple virtualenv (one for Python 2 and one for Python 3).
We run step-by-step and detail all the operations. A quicker, more concise guide can be found at the end of this gist.
We create first one venv for each version of Python.
mkvirtualenv -p /path/to/python2.7 venv-name
deactivate
When a file has been created on a different system from the one you are using, some cariage returns characters cause problems when commiting to git. You can fix this problem by running one of the following commands, depending on your system.
sed -e 's/$/\r/' inputfile > outputfile # UNIX to DOS (adding CRs)
sed -e 's/\r$//' inputfile > outputfile # DOS to UNIX (removing CRs)
perl -pe 's/\r\n|\n|\r/\r\n/g' inputfile > outputfile # Convert to DOS
perl -pe 's/\r\n|\n|\r/\n/g' inputfile > outputfile # Convert to UNIX (Mac OS X)
perl -pe 's/\r\n|\n|\r/\r/g' inputfile > outputfile # Convert to old Mac
find . -name '*.jpg' | # find jpegs | |
awk 'BEGIN{ a=1 }{ printf "mv \"%s\" %02d.jpg\n", $0, a++ }' | # build mv command | |
bash # run that command | |
# Source: http://stackoverflow.com/a/10780250/2086547 |
Start the notebook in no-browser mode and specify a port (different from any other port on the server):
jupyter notebook --no-browser --port=[XXXX]
Optional: start the notebook in tmux
or screen
so that you can later close the terminal while be able to run the notebook (e.g. if you are runing a lon task).