Skip to content

Instantly share code, notes, and snippets.

Victor Kristof victorkristof

Block or report user

Report or block victorkristof

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View git-fatal-cr-lf-fix.md

UNIX to DOS (adding CRs)

sed -e 's/$/\r/' inputfile > outputfile

DOS to UNIX (removing CRs)

sed -e 's/\r$//' inputfile > outputfile

Convert to DOS

perl -pe 's/\r\n|\n|\r/\r\n/g' inputfile > outputfile

Convert to UNIX

@victorkristof
victorkristof / epetition-explorer.ipynb
Last active Jul 27, 2016
UK parliament ePetition explorer.
View epetition-explorer.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@victorkristof
victorkristof / jupyter-notebook-remote.md
Last active Jun 3, 2016
Jupyter Notebook on remote server
View jupyter-notebook-remote.md

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

@victorkristof
victorkristof / rename_sequential.sh
Last active Mar 29, 2016
Rename all files in a directory with sequential numbers
View rename_sequential.sh
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 / gp-increasing-series.ipynb
Last active Sep 28, 2015
Gaussian Process to fit increasing time series
View gp-increasing-series.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@victorkristof
victorkristof / git-fatal-crlf-fix.md
Created Sep 14, 2015
Fix for Git's CRLF fatal error
View git-fatal-crlf-fix.md

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 / ipython-notebook-multiple-kernels-venv.md
Last active Jul 29, 2018
IPython Notebook with multiple kernels and virtualenv
View ipython-notebook-multiple-kernels-venv.md

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 / Docker snippets.md
Last active Aug 29, 2015
Useful pieces of code to use with Docker.
View Docker snippets.md

Docker snippets

Useful pieces of code to use with Docker.

Start boot2docker

boot2docker start
eval "$(boot2docker shellinit)"
@victorkristof
victorkristof / datetime-to-timestamp.py
Last active Sep 14, 2015
Convert Python datetime into timestamp
View datetime-to-timestamp.py
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 / datenum-to-datetime.py
Last active Jun 6, 2019
Convert Matlab datenum into Python datetime
View datenum-to-datetime.py
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
You can’t perform that action at this time.