Skip to content

Instantly share code, notes, and snippets.

View agalea91's full-sized avatar

Alexander Galea agalea91

View GitHub Profile
import argparse
def main(*args, **kwargs):
print('\n'.join(args))
if __name__ == '__main__':
parser = argparse.ArgumentParser(
description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter,
)
@agalea91
agalea91 / setup_python.sh
Created May 5, 2020 06:45
Setup python on linux (2020)
sudo apt-get update
sudo apt-get install python3-setuptools python3-dev build-essential
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
sudo python3 get-pip.py
@agalea91
agalea91 / pushup_time_slack.py
Created April 16, 2020 22:52
Send pushup notifications to slack
# -*- coding: utf-8 -*-
import os
import numpy as np
import requests
import sys
if (sys.version_info.major + sys.version_info.minor / 10) < 3.6:
raise SystemError('push.py uses f-strings. Please install python 3.6+')
from slackclient import SlackClient
SLACK_TOKEN = os.environ['SLACK_TOKEN']
@agalea91
agalea91 / squid_proxy_setup.txt
Last active April 6, 2024 06:37
Squid proxy setup on linux server (NO WARRANTY)
# https://linuxize.com/post/how-to-install-and-configure-squid-proxy-on-ubuntu-20-04/
# Install squid
sudo apt update
sudo apt install squid
# Backup config
sudo cp /etc/squid/squid.conf{,.orginal}
# Add allowed IPs
@agalea91
agalea91 / nginx_config_info.txt
Last active May 13, 2020 16:44
Nginx reverse proxy config (NO WARRANTY)
# Website location:
# /var/www/html
# Config file location:
# /etc/nginx/nginx.conf
# Install
sudo apt-get update
sudo apt-get install nginx
sudo service nginx restart
@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 / jupyter_notebook_config.py
Last active October 13, 2021 00:28
Jupyter Config file with post-save hook for saving Notebook as Python script
# 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_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)
season game_number team_name date pull_period pull_time goal_for_time goal_against_time goal_for_timedelta goal_against_timedelta game_end_timedelta
20032004 710 CHI 2004-01-21 3 0 days 00:19:44.000000000 0 days 00:19:47.000000000 0 days 00:00:03.000000000
20032004 205 MIN 2003-11-08 3 0 days 00:19:58.000000000 0 days 00:00:02.000000000
20032004 1230 S.J 2004-04-04 3 0 days 00:18:39.000000000 0 days 00:19:40.000000000 0 days 00:01:01.000000000
20032004 655 PHX 2004-01-13 3 0 days 00:19:03.000000000 0 days 00:19:25.000000000 0 days 00:00:22.000000000