Skip to content

Instantly share code, notes, and snippets.

View mpkocher's full-sized avatar

M. Kocher mpkocher

View GitHub Profile
@mpkocher
mpkocher / DataClasses.ipynb
Created May 25, 2019 01:55
Overview of Dataclasses, namedtuple, typing.NamedTuple, attrs and pydantic
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mpkocher
mpkocher / Declined.scala
Last active July 2, 2022 23:46
ZIO 1.x + Decline Example for creating CLI tools and running them with scala-cli.
//> using platform "jvm"
//> using scala "2.13.8"
//> using lib "dev.zio::zio:1.0.14"
//> using lib "com.monovore::decline:2.2.0"
//> using mainClass "DeclinedApp"
// Runnable using `scala-cli run Declined.scala -- --user Ralph --alpha 3.14`
import zio.{ExitCode, ZEnv, ZIO, Task, RIO, IO, UIO, URIO}
import zio.console._
@mpkocher
mpkocher / amzlink.py
Last active September 21, 2021 12:13 — forked from pybites/amzlink.py
@mpkocher
mpkocher / boiler.py
Last active March 30, 2021 02:55
MK common Python utils
# Common core utils are too small that don't warrant creating a package
from argparse import ArgumentParser, Namespace, ArgumentDefaultsHelpFormatter
import csv
import functools
import logging
import sys
from typing import Callable as F
from typing import List, TypeVar, Type, Iterator
from pydantic import BaseModel
@mpkocher
mpkocher / scrape_gibson.py
Last active March 18, 2021 07:04
Scrape Gibson.com
import sys
import json
import logging
from typing import List, Tuple, Dict, Any
from selenium import webdriver
from bs4 import BeautifulSoup
import pandas as pd
log = logging.getLogger(__name__)
@mpkocher
mpkocher / pydantic-cli-sharing-subparse-options.py
Created October 29, 2020 22:54
Sharing Subparser Options in pydantic-cli
"""
Example of Using a Subparser
Demonstration of using two Pydantic data models to
build a subparser and sharing options.
The major friction point and limitation is the order in which the options appear in --help.
For example,
@mpkocher
mpkocher / compose_functions.py
Created March 31, 2014 16:18
compose functions in python
def compose(*funcs):
"""Functional composition
[f, g, h] will be f(g(h(x)))
"""
def compose_two(f, g):
def c(x):
return f(g(x))
return c
return functools.reduce(compose_two, funcs)
@mpkocher
mpkocher / Functional-Python-Part-2.ipynb
Last active September 14, 2020 21:43
Functional-Python-Part-2
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import $ivy.`com.zaxxer:nuprocess:2.0.0`, com.zaxxer.nuprocess._
import scala.collection.JavaConverters._
import java.nio.ByteBuffer
import scala.concurrent.{Future, Promise}
class ProcessHandler extends NuAbstractProcessHandler {
private var nuProcess: NuProcess = null
override def onStart(nuProcess: NuProcess): Unit = {
@mpkocher
mpkocher / walrus_fstring_example.py
Last active May 9, 2020 21:35
Exploring Py 3.8 Walrus + F-string Tweet By Raymond Hettinger
#!/usr/bin/env python3
"""
Requires Python 3.8
Expanding on a Tweet from RH using walrus and f-strings
https://twitter.com/raymondh/status/1153085050650423296
"""
import logging