Skip to content

Instantly share code, notes, and snippets.

View kjaanson's full-sized avatar

Kaur Jaanson kjaanson

  • Estonia
View GitHub Profile
@kjaanson
kjaanson / .gitignore
Created September 18, 2016 09:15
Default .gitignore for Python/Jupyter projects
/*.egg-info
/.spyderproject
.spyderproject
.idea/*
/**/__pycache__
/**/.ipynb_checkpoints
/.doit.db.bak
/.doit.db.dat
/.doit.db.dir
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kjaanson
kjaanson / tmux-cheatsheet.markdown
Created November 14, 2016 12:58 — forked from MohamedAlaa/tmux-cheatsheet.markdown
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@kjaanson
kjaanson / generate_makehtmlscript_tasks.py
Last active February 3, 2017 13:20
Often used generators for DoIt tasks
import glob
import os
from os.path import join
import nbformat as nbf
def generate_makehtmlscript_tasks(dir):
"""
Builds html and scripts from deliver notebooks. Does not execute notebooks.
@kjaanson
kjaanson / nbconvert_bash.md
Created May 13, 2017 21:16
nbconvert commands with options

Run notebook with specified log level

jupyter nbconvert --Application.log_level=10

Running a notebook

jupyter nbconvert --to notebook --execute mynotebook.ipynb
@kjaanson
kjaanson / clear-jupyternb-outputs.pre-commit.sh
Last active April 4, 2024 10:56
Useful git hooks for working with Jupyter notebooks/Data analysis
#!/bin/sh
#
# Pre-commit hook for clearing output cells from commited analysis Jupyter notebooks.
#
echo "Running pre-commit hook to clear output from deliver/*.ipynb notebooks."
for notebook in git diff --cached --name-only -- 'deliver/*.ipynb'
do
echo "Clearing output from $notebook"
jupyter nbconvert --ClearOutputPreprocessor.enabled=True --ClearOutputPreprocessor.remove_metadata_fields=[] --to notebook --inplace $notebook
@kjaanson
kjaanson / mnist.py
Last active February 4, 2019 15:20 — forked from akesling/mnist.py
import os
import struct
import numpy as np
"""
Loosely inspired by http://abel.ee.ucla.edu/cvxopt/_downloads/mnist.py
which is GPL licensed.
"""
def read(dataset = "training", path = "."):
@kjaanson
kjaanson / Git push deployment in 7 easy steps.md
Created October 22, 2017 18:17 — forked from thomasfr/Git push deployment in 7 easy steps.md
7 easy steps to automated git push deployments. With small and configurable bash only post-receive hook
@kjaanson
kjaanson / benchmarking.py
Created November 1, 2017 13:14
Benchmarking and timing decorators for python
import time
def timeit(value_dict=None, print_values=True):
"""Decorator for timing functions with different parameters.
Arguments:
value_dict - dict where to save the timings, uses function args tupple as key
print_values - boolean for printing timings to std out
Usage:
@kjaanson
kjaanson / to_bcp_sql.py
Last active June 19, 2020 03:45
Monkeypatched method for pandas DataFrame to bulk upload dataframe to SQL Server.
"""
Monkeypatching Pandas Dataframe to include `to_bcp_sql` method
that uploads dataframe to mssql server using mssql-tools `bcp`.
Requires mssql-tools to be installed on system and in PATH.
Partly inspired by https://gist.github.com/ajsmith007/d1adb79e152f5f23503b
ToDo:
* Add docs