Skip to content

Instantly share code, notes, and snippets.

@nhoffman
nhoffman / pyscript.py
Last active February 20, 2024 22:30
Python script template
#!/usr/bin/env python3
"""A simple python script template.
"""
import os
import sys
import argparse
@nhoffman
nhoffman / setup.py
Created April 15, 2023 17:52
setup.py pattern for creating multiple entry points
from setuptools import setup, find_packages
from pathlib import Path
with open("README.md", "r") as readme:
long_description = readme.read()
scripts_dir = Path(__file__).parent / 'openaiwrappers' / 'scripts'
scripts = [fn.stem for fn in scripts_dir.iterdir()
if not fn.stem.startswith('__')]
@nhoffman
nhoffman / git_commit_graph.py
Created October 28, 2017 15:03
Git commit graph
from scipy.interpolate import interp1d
import numpy as np
import shlex
import subprocess as sp
import prettyplotlib as ppl
from matplotlib import pyplot as plt
from matplotlib.ticker import FuncFormatter
import io
@nhoffman
nhoffman / sql2csv.py
Created December 23, 2022 06:27
Export MS SQL queries to csv
#!/usr/bin/env python3
"""Reformat sqlcmd output to csv
- writes output of the sql query to a temporary file
- saves query as unicode and converts utf-16 to utf-8
- replaces "NULL" with empty cells
"""
import os
@nhoffman
nhoffman / prompt.sh
Created July 9, 2012 20:05
prompt and window titles for zsh (any maybe bash)
#########################################
## Set prompt, iTerm2 window and tabs ##
#########################################
# Color constants used in the prompt
BLACK="%{%}"
BOLD_BLACK="%{%}"
RED="%{%}"
BOLD_RED="%{%}"
GREEN="%{%}"
@nhoffman
nhoffman / medialab_cap_topics.user.js
Last active May 31, 2022 20:55
userscript for medialab inspection proof
// ==UserScript==
// @name medialab_cap_topics
// @namespace http://tampermonkey.net/
// @version 0.6
// @description Add a menu to MediaLab inspection proof to filter CAP checklist items
// @author Noah Hoffman
// @match https://www.medialab.com/lms/admin/ad_ic_viewchecklist.aspx?*
// @require http://code.jquery.com/jquery-3.4.1.min.js
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant none
@nhoffman
nhoffman / scrape_urls.py
Created December 13, 2021 21:04
scrape urls from an html file
#!/usr/bin/env python3
"""Scrape all urls from an html document
"""
import os
import sys
import argparse
@nhoffman
nhoffman / report-template.Rmd
Last active June 7, 2021 20:19
rmarkdown template
---
title: [title]
author: Noah Hoffman
date: "`r format(Sys.time(), '%Y-%m-%d')`"
output:
html_document:
toc: true
---
# setup
@nhoffman
nhoffman / get_classifications.py
Created August 29, 2019 17:03
Reformat of output/per_pquery_assign (output of 'gappa assign')
#!/usr/bin/env python3
"""Reformat of output/per_pquery_assign (output of 'gappa assign')
see https://github.com/lczech/gappa/wiki/Subcommand:-assign
Use "afract" for filtering, based on two criteria.
1. keep lineages with afract => min-afract
2. keep ranks with a cumulative value of afract >= min-total
@nhoffman
nhoffman / cwlog.py
Created October 7, 2019 03:41
Show cloudwatch log events
#!/usr/bin/env python3
"""Show cloudwatch log events.
Examples:
Show log stream containing the most recent event for a log group:
cwlog.py -g /aws/lambda/lambda-labreport