Skip to content

Instantly share code, notes, and snippets.

View bsnacks000's full-sized avatar
🎯
Focusing

Johnny bsnacks000

🎯
Focusing
View GitHub Profile
curl https://raw.githubusercontent.com/github/gitignore/master/Python.gitignore > .gitignore
# basic setup for a single droplet with ssh and firewall config
# reference: https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-18-04
1. Login in as root
$ root@xxx.xxx.xxx.xxx
2. Add a non-root user, give sudo privelages and transfer ssh public key
$ adduser sammy
$ usermod -aG sudo sammy
$ rsync --archive --chown=sammy:sammy ~/.ssh /home/sammy
# for dev purposes or machines that aren't opened up to the public
# ref: https://www.humankode.com/ssl/create-a-selfsigned-certificate-for-nginx-in-5-minutes
# 1. make a local directory...create a conf file for localhost config
$ sudo nano localhost.conf
# paste this in there...
-------------------------------
[req]
default_bits = 2048
# based on the digital ocean guides
# This is for configuring nginx to proxy_pass to multiple backend servers
# from a gateway server.
# 1. install
$ sudo apt update
$ sudo apt install nginx
# 2. adjust firewall
$ sudo ufw allow 'Nginx Full'
# based on digital ocean for 18.04
$ sudo apt update
$ sudo apt install postgresql postgresql-contrib
# make a new non-postgres user for the system without switching roles
$ sudo -u postgres createuser --interactive
$ sudo -u postgres createdb <your-user-name>
# setup a db password for user
@bsnacks000
bsnacks000 / dal.py
Created January 3, 2019 17:36
Sqlalchemy DAL
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, scoped_session
from contextlib import contextmanager
import logging
l = logging.getLogger(__name__)
class DataAccessLayer(object):
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"~/.conan/**"
],
"defines": [],
"compilerPath": "/usr/bin/clang",
@bsnacks000
bsnacks000 / ipywidget_wrapper.py
Created June 10, 2020 15:08
ipywidget wrapper
""" Defines a generic interface for composable widgets. Panels are the view layer, Datastores are the model.
Downloaders should fill the datastores with data. Panels should register observers to implement parts of the API. This could be
as simple as downloading and displaying data, or calling custom APIs that call things.
"""
import abc
import IPython
import ipywidgets as widgets
import inspect
""" A high-level API that wraps the sklearn Pipeline interface. If designed well we should be able to use this base class to
encapsulate elements of jupyter notebook script. A user should subclass and override the specified hook methods of these classes
to build a workflow for deployment and benchmarking.
"""
import abc
#from sklearn.externals.joblib import parallel_backend warning says to use parallel backend from joblibe directly...
from joblib import parallel_backend
from sklearn.model_selection import GridSearchCV, RandomizedSearchCV,\
ParameterGrid, ParameterSampler
@bsnacks000
bsnacks000 / yearmonth.py
Created August 27, 2021 20:51
YearMonth pydantic type
from typing import Any, List, NamedTuple, Optional
import pydantic
import datetime
import re
_ym_re = re.compile(r'[0-9]{4}-[0-9]{2}')
class YearMonth(NamedTuple):
"""A custom YearMonth type. Can validate against YYYY-MM, ('YYYY', 'MM') or (int, int).
Checks that year and month are valid ISO 8601 ranges.