Skip to content

Instantly share code, notes, and snippets.

View victorkristof's full-sized avatar

Victor Kristof victorkristof

View GitHub Profile
@victorkristof
victorkristof / sticky-footer.sass
Created March 25, 2015 09:41
Bootstrap sticky footer in Sass.
@victorkristof
victorkristof / flask-flash-bootstrap
Created March 26, 2015 12:52
Flask flash messages as Bootstrap alert.
{% 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">&times;</span></button>
<!-- <strong>Title</strong> --> {{ message }}
</div>
{% endfor %}
{% endif %}
@victorkristof
victorkristof / datenum-to-datetime.py
Last active March 31, 2023 14:59
Convert Matlab datenum into Python datetime
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
@victorkristof
victorkristof / datetime-to-timestamp.py
Last active September 14, 2015 08:54
Convert Python datetime into timestamp
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())
@victorkristof
victorkristof / Docker snippets.md
Last active August 29, 2015 14:26
Useful pieces of code to use with Docker.

Docker snippets

Useful pieces of code to use with Docker.

Start boot2docker

boot2docker start
eval "$(boot2docker shellinit)"
@victorkristof
victorkristof / ipython-notebook-multiple-kernels-venv.md
Last active July 29, 2018 10:59
IPython Notebook with multiple kernels and virtualenv

IPython Notebook with multiple kernels and virtualenv

Explanations of how to install and use IPython Notebook with a venv and multiple virtualenv (one for Python 2 and one for Python 3).

Step-by-step installation

We run step-by-step and detail all the operations. A quicker, more concise guide can be found at the end of this gist.

Create virtualenv

We create first one venv for each version of Python.

mkvirtualenv -p /path/to/python2.7 venv-name
deactivate
@victorkristof
victorkristof / git-fatal-crlf-fix.md
Created September 14, 2015 08:52
Fix for Git's CRLF fatal error

Fix for Git's CRLF fatal error

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
@victorkristof
victorkristof / gp-increasing-series.ipynb
Last active September 28, 2015 12:19
Gaussian Process to fit increasing time series
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@victorkristof
victorkristof / rename_sequential.sh
Last active March 29, 2016 20:58
Rename all files in a directory with sequential numbers
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
@victorkristof
victorkristof / jupyter-notebook-remote.md
Last active June 3, 2016 15:42
Jupyter Notebook on remote server

How to use a remote Jupyter Notebook

On the remote server

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).