Skip to content

Instantly share code, notes, and snippets.

@bsweger
bsweger / Spending Category.html
Created February 16, 2012 19:21
HTML Snippets for 2013 President's Budget
<script type="text/javascript" src="/media/uploads/publications/presidents_budget_fy2013/swfobject.js"></script>
<script type="text/javascript">
// For version detection, set to min. required Flash Player version, or 0 (or 0.0.0), for no version detection.
var swfVersionStr = "11.1.0";
// To use express install, set to playerProductInstall.swf, otherwise the empty string.
var xiSwfUrlStr = "/media/uploads/publications/presidents_budget_fy2013/playerProductInstall.swf";
var flashvars = {datafile: "/media/uploads/publications/presidents_budget_fy2013/info/budget-category.txt"}
var params = {};
params.quality = "high";
params.bgcolor = "#ffffff";
@bsweger
bsweger / .bash_profile
Created July 6, 2012 19:32
.bash_profile - start ssh-agent
# adopted from https://confluence.atlassian.com/display/BITBUCKET/Set+up+SSH+for+Git#SetupSSHforGit-installpublickey, which was adopted from a GitHub script
if [ -r ~/.profile ]; then . ~/.profile; fi
case "$-" in *i*) if [ -r ~/.bashrc ]; then . ~/.bashrc; fi;; esac
echo
echo "Yo"
echo
SSH_ENV="$HOME/.ssh/environment"
@bsweger
bsweger / useful_pandas_snippets.md
Last active March 4, 2026 19:59
Useful Pandas Snippets

Useful Pandas Snippets

A personal diary of DataFrame munging over the years.

Data Types and Conversion

Convert Series datatype to numeric (will error if column has non-numeric values)
(h/t @makmanalp)

@bsweger
bsweger / .pythonstartup.py
Created December 23, 2025 19:55
Python REPL startup file
import contextlib
import csv
import datetime as dt
import json
import os
import pprint
import subprocess
import sys
import tempfile
from dataclasses import dataclass
@bsweger
bsweger / .README.md
Last active August 28, 2024 20:09
Accessing Cloud-Based Hubverse Data

Cloud-Based Hubs

The Hubverse is in the processing of making hub data available via publicly-accessible AWS S3 buckets.

Cloud-based hubs "mirror" the data stored in a hub's GitHub repository and provide a few advantages for data consumers:

  • No need to clone a repository to access data
  • Cloud-based model-output files are in parquet format, which is easier to work with and more performant

The examples here use the CDC's FluSight Forecast Hub, which is available in the following S3 bucket:

@bsweger
bsweger / markdown-table-to-html.py
Last active August 22, 2024 16:25
Convert markdown table rows to html (we converted some markdown tables to html so we could use the "scope" attribute in the header rows for accessibility).
#tabedata.txt is a file that contains the piped markdown table rows
with open ('markdownrows.txt') as f:
content = f.readlines()
rows = []
for c in content:
cells = c.split('|')
cells = ['<td>{}</td>'.format(cell.strip()) for cell in cells]
rows.append(cells)
@bsweger
bsweger / make_samples.py
Created March 14, 2024 22:21
generate variant hub sample output data
from itertools import product
import pandas as pd
import numpy as np
def make_sample(
n_samples: int = 2,
n_horizons: int = 3,
n_variants: int = 3,
n_locations: int = 2,
samples_joint_across: list[str] = None
@bsweger
bsweger / .zshrc
Last active November 15, 2020 19:25
Raspberry Pi 4 Notes
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
# Path to your oh-my-zsh installation.
export ZSH="/home/becky/.oh-my-zsh"
# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
@bsweger
bsweger / ipython-virtualenv.py
Created August 27, 2011 23:58
make iPython virtual env aware (Windows)
#------------------------------------------------------------------------------
# Make things VirtualEnv aware (Windows version).
# More info: http://www.swegler.com/becky/blog/2011/08/28/python-django-mysql-on-windows-7-part-3-ipython-virtual-environments/
# add this to the end of ipython_config
# (or course, for virtualenvs created via --no-site-packages, it would
# be much easier just to install iPython)
#------------------------------------------------------------------------------
import sys
import site
from os import environ
@bsweger
bsweger / pre-django-mysql.sql
Last active May 1, 2019 20:18
initial MySQL setup before hooking up a Django project
#create the database
CREATE DATABASE [dbname] CHARACTER SET utf8;
#create user
CREATE USER 'django_user'@'localhost' IDENTIFIED BY 'thepassword';
#give user permissions to db (probably not a great idea to GRANT ALL unless you really have to)
# (replace django.* with [mydatabasename].*)
GRANT ALL ON django.* TO 'django_user'@'localhost';