Skip to content

Instantly share code, notes, and snippets.

View dangunter's full-sized avatar
🏠
Working from home

Dan Gunter dangunter

🏠
Working from home
View GitHub Profile
@dangunter
dangunter / Interval-tree-example.ipynb
Created December 11, 2015 16:07
Example of using Python “intervaltree” module to find intervals overlapping some input interval
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@dangunter
dangunter / pbar.py
Created May 8, 2016 15:33
Simple Python text progress bar
"""
Text progress bar
"""
import sys
class PBar(object):
"""Text progress bar.
"""
c0 = '.' # left end marker
c1 = '_' # completed char

Keybase proof

I hereby claim:

  • I am dangunter on github.
  • I am dangunter (https://keybase.io/dangunter) on keybase.
  • I have a public key whose fingerprint is C5CC 7682 13C4 6971 2E3E 7853 6225 E467 93E1 03FB

To claim this, I am signing this object:

@dangunter
dangunter / mock_imports.py
Last active November 8, 2022 10:12
For testing, use the mock module to wrap non-importable code. Also provide hooks for putting back in real functions/classes where needed.
import importlib
from mock import MagicMock, patch
def example():
with patch_modules():
import something.not.importable
print("yay! it worked!")
def patch_modules():
sm = mock_import('not.importable', 'something')
@dangunter
dangunter / biketowork.md
Created December 18, 2016 14:16
Bike to work schedule

Bike/Bart to work

From home to work

Time Location
8:10 Bike to PH BART
8:47 BART to MacArthur to Berkeley
9:17 Downtown Berkeley BART
9:22 Shuttle stop
@dangunter
dangunter / annotate_source
Created September 5, 2018 21:40
annotate source code with a copyright header
#!/usr/bin/env python
"""
Annotate source code with a notice (see NOTICE_TEXT).
An existing notice will be replaced, and if there is no notice
encountered then one will be inserted. Detection of the notice
is exceedingly simple: if any line without a comment is encountered, from
the top of the file, before the standard "separator" of a long string
of comment characters, then the notice will be inserted. Likewise, the
"end" of the notice is either the same separator used for the beginning or
@dangunter
dangunter / dmf_plans_20181102.md
Last active November 5, 2018 20:42
Plans for IDAES Data Management Framework

Plans for IDAES Data Management Framework

JupyterHub on the cloud

  • deploying Docker image of IDAES with solvers on JupyterHub on AWS
  • script and automate so can deploy multiple versions
    • bleeding-edge version deployed through CI
    • last-release version as a sandbox

Collect more/better information from the (new) framework components

In particular need of attention:

@dangunter
dangunter / logging_filter_example.py
Created January 8, 2020 15:17
Logging adapter/filter example
from logging import getLogger, Filter, LoggerAdapter, StreamHandler, Formatter, INFO, ERROR, DEBUG
logger = getLogger("test")
class IdaesModFilter(Filter):
"""Filter that keeps a list of allowed 'modules' in an attribute.
"""
def __init__(self, modules):
self.modules = modules # list of modules to allow
def filter(self, record):
@dangunter
dangunter / many_streams_flowsheet.py
Last active May 7, 2021 23:22
IDAES flowsheet with large number of streams
# Imports
from pyomo.environ import (Constraint,
Var,
ConcreteModel,
Expression,
Objective,
SolverFactory,
TransformationFactory,
value)
from pyomo.network import Arc, SequentialDecomposition
@dangunter
dangunter / get_gh_contributors.py
Last active July 8, 2021 21:19
Get contributors to a Github repo using the Github API
import requests
from typing import List, Dict, Union
def get_contributors(owner: str, repo: str, extra_fields: List[str] = None,
simplify=True) -> Union[List[str], List[Dict[str, str]]]:
"""Get a list of contributors to a Github repo.
Args:
owner: Repository owner (organization)
repo: Repository name