Skip to content

Instantly share code, notes, and snippets.

View bsnacks000's full-sized avatar
🎯
Focusing

Johnny bsnacks000

🎯
Focusing
View GitHub Profile
// use std::fs::File;
use itertools::Itertools;
use std::io::{self, BufRead, BufReader, BufWriter, Write};
use serde::{Deserialize, Serialize};
// use std::path::Path;
#[derive(Serialize, Deserialize)]
struct Item<'a> {
id: i64,
#!/bin/bash
# Simple pattern for exporting a query from postgres into jsonl using psql \copy command
pg_url=$POSTGRES_URL
fpath=$FPATH
psql $pg_url > $fpath << EOF
\copy(select to_jsonb(r) as jl from (select * from my_table) r ) to stdout;
EOF
#!/usr/bin/env python
""" standalone cli script for easy version bumping with pyproject.
"""
import argparse
import toml
import pathlib
import sys
import re
import os
import subprocess
@bsnacks000
bsnacks000 / version_tag.py
Created December 16, 2021 14:53
version tag for github CI workflows with poetry
"""
Assuming you have pyproject.toml we will read in the current version tag into the environment tag: VERSION_TAG
This will be available in your workflow now.
Place this at the root of .github folder
"""
import toml
import os
import sys
@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.
""" 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 / 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
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"~/.conan/**"
],
"defines": [],
"compilerPath": "/usr/bin/clang",
@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):
# 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