Skip to content

Instantly share code, notes, and snippets.

View kjaanson's full-sized avatar

Kaur Jaanson kjaanson

  • Estonia
View GitHub Profile
@kjaanson
kjaanson / conda_installs.md
Created March 1, 2023 21:10
Conda installs

conda create --name neurokone python=3.8 deepspeed pytorch==1.12.1 torchvision==0.13.1 torchaudio==0.12.1 cudatoolkit=11.6 -c pytorch -c conda-forge -c deepspeed

@kjaanson
kjaanson / fetch_cert_from_keyvault.py
Created October 18, 2019 09:02
Fetching certificate and its key from Azure KeyVault
"""Fetches cert and private key from specified keyvault using MSI auth
and stores these in specified folder."""
import os
from msrestazure.azure_active_directory import MSIAuthentication
from azure.keyvault import KeyVaultClient
from OpenSSL import crypto
import base64
import argparse
@kjaanson
kjaanson / dec_registry.py
Last active January 25, 2018 18:14
Dynamic addition of methods to class with decorators
class MainClass:
DYN_METHOD_REGISTRY = {}
def __init__(self):
print(f"This class has dynamically added methods: {self.DYN_METHOD_REGISTRY.keys()}")
def runmethods(self):
for name, fp in self.DYN_METHOD_REGISTRY.items():
@kjaanson
kjaanson / getter_and_setter.py
Created January 20, 2018 21:47 — forked from luhn/getter_and_setter.py
Using getters and setters with SQLAlchemy
class Table(Base):
id = Column(Integer, primary_key=True)
_name = Column('name', String(24))
@property
def name(self):
return self._name;
@name.setter
def name(self, value):
@kjaanson
kjaanson / flask skeleton folder tree
Created January 8, 2018 08:51 — forked from efazati/Py Flask Skeleton
flask folders and files structure
.
├── deploy.py
├── project
│   ├── application.py
│   ├── apps
│   │   ├── articles
│   │   │   ├── forms.py
│   │   │   ├── __init__.py
│   │   │   ├── models.py
│   │   │   └── views.py
@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
@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 / 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 / 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 / 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