Skip to content

Instantly share code, notes, and snippets.

View cbare's full-sized avatar
👹
¯\_(ツ)_/¯

Christopher Bare cbare

👹
¯\_(ツ)_/¯
View GitHub Profile
@cbare
cbare / parse_dicom_dt.py
Created July 3, 2022 22:49
Parse a Dicom formatted datetime string and return a Python datetime.
import datetime as dt
import pytest
import re
def parse_dicom_dt(dicom_dt):
"""
Parse a Dicom formatted datetime string and return a Python datetime.
The Dicom format is "YYYYMMDDHHMMSS.FFFFFF&ZZXX" described here:
"""
A simple HTTPS server
Generate cert and key with:
```sh
openssl req -newkey rsa:4096 -x509 -sha256 -days 3650 -nodes -subj '/CN=localhost' -out ./ssl/cert.pem -keyout ./ssl/key.pem
```
Test with httpie:
@cbare
cbare / extract_darwin_to_csv.py
Created November 22, 2021 23:19
Convert JSON output from V7 Darwin to csv.
"""
Convert JSON output from V7 Darwin to csv.
"""
import json
import os.path
import pandas as pd
filenames = [f"{name}.json" for name in list('abcde')]
data_dir = "data/lizzie-reader-study-test-part-1"
import os
import io
import boto3
import json
import csv
# grab environment variables
ENDPOINT_NAME = 'xgboost-2020-02-01-16-28-38-417'
runtime= boto3.client('runtime.sagemaker')
@cbare
cbare / icd10.py
Created January 30, 2020 22:01
Look up ICD10 codes.
"""
Look up ICD10 codes.
Using data from the CDC's refence page here:
https://www.cdc.gov/nchs/icd/icd10cm.htm
"""
import sys
from xml.etree import ElementTree as et
x = et.parse('/Users/christopherbare/Downloads/icd10cm_tabular_2020.xml')
@cbare
cbare / speakers.py
Created July 11, 2018 00:00
Reformat the output of Amazon Transcribe so it's readable.
"""
Reformat the output of Amazon Transcribe
usage: python3 speakers.py asrOutput.json
"""
import json
import sys
# read in the JSON output of Amazon Transcribe
with open(sys.argv[1]) as f:
library('RPostgreSQL')
library('dplyr')
library('lubridate')
library('tidyr')
# Get external reviews with UTC timestamps from the DB
# \copy (select distinct o.observation_id, o.collection_date, o.vendor_id, v.name, reviewed_at_utc, reviewed_by from ops.review r join analysis.observation o on r.observation_id=o.observation_id join analysis.vendor v on o.vendor_id=v.vendor_id where reviewed_at_utc >= '2017-05-01' order by reviewed_at_utc) TO '/Users/cbare/Desktop/external-reviews.tsv' WITH NULL AS '';
# df <- read.table('/Users/cbare/Desktop/external-reviews.tsv', stringsAsFactors=F)
# get data via a query
@cbare
cbare / type_check_me.py
Last active January 24, 2018 19:25
a bit of Python code with type annotations
"""
This is a bit of Python code with type annotations.
To type check this code with [mypy](http://mypy-lang.org/) like this:
mypy mypy/type_check_me.py
"""
from typing import List, TypeVar, Optional, Sequence
def gcd(a: int, b: int) -> int:
@cbare
cbare / external-review-counts-by-state.R
Last active January 29, 2018 19:18
Travels in the Tidyverse: R code to count reviews by external physicians
# compile stats on external clinical reviews
library('RPostgreSQL')
library('dplyr')
library('lubridate')
library('tidyr')
# Get external reviews with UTC timestamps from the DB
# \copy (select distinct o.observation_id, o.collection_date, o.vendor_id, v.name, reviewed_at_utc, reviewed_by from ops.review r join analysis.observation o on r.observation_id=o.observation_id join analysis.vendor v on o.vendor_id=v.vendor_id where reviewed_at_utc >= '2017-05-01' order by reviewed_at_utc) TO '/Users/cbare/Desktop/external-reviews.tsv' WITH NULL AS '';
# get a table of addresses from user-management
[alias]
gr = log --graph --full-history --all --color \n --pretty=tformat:\"%x1b[31m%h%x09%x1b[32m%d%x1b[0m%x20%s%x20%x1b[33m(%an)%x1b[0m\"
plog = log --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit -n 20
ls = log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate
ll = log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --numstat
cdiff = diff --cached
branches = branch --list -vva --color
remotes = remote --verbose
[color]
ui = auto