Skip to content

Instantly share code, notes, and snippets.

var interupt = make(chan os.Signal)
var terminate = make(chan os.Signal)
signal.Notify(interupt, syscall.SIGINT)
signal.Notify(terminate, syscall.SIGTERM)
select {
case <-interupt:
// TODO: LOG AND SHUTDOWN
os.Exit(0)
break
case <-terminate:
@KCarretto
KCarretto / composition_example.py
Last active December 28, 2018 06:31
Python Design Snippets - Additional snippets from a post on designing python programs
import os
from functools import partial
from typing import Any, Callable, Dict, Tuple
# Type Aliases
LogMap = Dict[str, str]
# Constant values
DEFAULTS: Dict[str, Any] = {
"ALERT_THRESHOLD": 2,
@KCarretto
KCarretto / people.py
Created December 27, 2018 22:06
Python Typing Code Example
"""
Defines concrete types of Person.
"""
from typing import ClassVar, List, Optional
from person import TPerson, Person # Update this to reflect whatever directory structure.
class Friend(Person):
"""
@KCarretto
KCarretto / conftest.py
Last active December 27, 2018 19:25
pytest example
# FILE LOCATION: <project_root>/tests/conftest.py
"""
Include common fixtures used by test cases.
"""
import pytest
@pytest.fixture(scope="module")
def example() -> str:
"""
@KCarretto
KCarretto / Makefile
Created December 27, 2018 18:50
Sphinx example. Automatically generate docs and host on github pages.
# FILE LOCATION: <project_root>/docs/Makefile
# Minimal makefile for Sphinx documentation
#
# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
SOURCEDIR = source
BUILDDIR = build
@KCarretto
KCarretto / setup.py
Created December 27, 2018 18:28
Simple setup.py
"""
Setup info used by pip.
"""
from setuptools import setup, find_packages
setup(
name="my_project",
url="https://github.com/kcarretto/my_project_repo",
author="Kyle Carretto",
author_email="kcarretto@gmail.com",