Skip to content

Instantly share code, notes, and snippets.

View agalea91's full-sized avatar

Alexander Galea agalea91

View GitHub Profile
@agalea91
agalea91 / github_deploy_key_setup.md
Created June 24, 2020 15:59
How to setup a deploy key for repo on shared server environment

GitHub Deploy Key Setup

  1. Generate key
ssh-keygen
...
cp ./key-name* ~/.ssh
  1. Go to GitHub repo and add key-name.pub
@agalea91
agalea91 / create_jupyter_nb_venv.txt
Last active August 9, 2023 19:46
Create virtual environment for Jupyter Notebook
# Creating a virtual env kernel
# -----------------------------
$ python -m venv .venv
$ source .venv/bin/activate
(.venv) $ pip install ipykernel
(.venv) $ python -m ipykernel install --user --name=proj-name
# Managing the kernel
# -----------------------------
$ jupyter kernelspec list
@agalea91
agalea91 / init_logging.py
Created July 30, 2019 17:30
Initialize python logging with file handler
def init_logging(level='debug'):
import logging
import os
import datetime
from pytz import timezone
if level == 'debug':
LOGGING_LEVEL = logging.DEBUG
elif level == 'info':
LOGGING_LEVEL = logging.INFO
@agalea91
agalea91 / jsonl_io.py
Last active August 5, 2021 06:07
Dump / load JSON line data.
import json
def dump_jsonl(data, output_path, append=False):
"""
Write list of objects to a JSON lines file.
"""
mode = 'a+' if append else 'w'
with open(output_path, mode, encoding='utf-8') as f:
for line in data:
json_record = json.dumps(line, ensure_ascii=False)
@agalea91
agalea91 / clean.py
Last active April 25, 2019 01:06
Clean out old auto-save notebooks. Run this script from the notebooks folder, which should have archive, py and html children dirs.
import sys
import os
import glob
import click
@click.command()
@click.option(
'--whitelist',
'-w',
default='',
@agalea91
agalea91 / .gitignore
Created March 4, 2019 19:31
My default .gitignore for python projects
# Misc python development files
.DS_Store
.vscode/
.ipynb_checkpoints/
__pycache__/
*.py[cod]
*.swp
*.swo
# Don't commit data or archived notebooks (by default)
@agalea91
agalea91 / README.md
Last active March 4, 2019 02:37
Starting README.md for my projects

project_name

project_description

Project Tree

├── LICENSE
├── README.md          <- The top-level README for developers using this project.
│
@agalea91
agalea91 / jupyter_notebook_config.py
Last active March 3, 2020 07:30
Jupyter Config file with post-save hooks
# File path:
# ~/.jupyter/jupyter_notebook_config.py
import os
from subprocess import check_call
import datetime
import re
def timestamped_file(fname):
return bool(re.match('.*\d{4}-\d{2}-\d{2}\.ipynb', fname))
@agalea91
agalea91 / init_py_project.sh
Last active March 7, 2020 23:24
Initialize a data science python project
# __author__ = 'Alex Galea'
# __license__ = MIT
# __version__ = '0.1.0'
# Build with cookiecutter
# pip install cookiecutter
# Template reference - http://drivendata.github.io/cookiecutter-data-science/
echo "Building cookiecutter template to start"
cookiecutter https://github.com/drivendata/cookiecutter-data-science
@agalea91
agalea91 / jupyter_default.py
Last active July 8, 2019 05:35
Default code to run at the top of a Jupyter Notebook
import pandas as pd
import numpy as np
import os
import sys
import re
import datetime
import time
import glob
import json
from tqdm import tqdm, tqdm_notebook