Skip to content

Instantly share code, notes, and snippets.

@bsweger
bsweger / test-django-install.py
Created August 28, 2011 23:12
test django install
import django
django.VERSION
@bsweger
bsweger / django-startproject-win.py
Created August 28, 2011 23:59
create Django project in Windows 7 virtualenv
#Alternate to the django-admin.py startproject command.
#In windows, using 'django-admin.py startproject' is problematic...the .py extension
#is associated with the main install of Python, not the install on the current virtualenv, which fouls things up (e.g., import errors). Code below:
#1. forces module mode, which will check the path for django-admin (interpreter searches the path for modules but not for scripts)
#2. no more .py extension
#see http://stackoverflow.com/questions/2542674/no-matter-what-i-do-django-admin-py-is-not-found-even-though-its-in-my-path
-m django-admin startproject tutorial
@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 / pandas_pad_using_apply.py
Created July 13, 2016 04:13
Apply a padding function to .csv columns (Pandas)
# example of using a parameterized function as a converter when reading .csv in pandas
import pandas as pd
# a function that will be used to pad datafram column values to a specified length
# (some incoming values are multiple spaces; those should convert to Noe)
padFunction = lambda field, padTo: str(field).strip().zfill(padTo) if len(str(field).strip()) else None
# read file w/o using converters and display list of unique alloc_id values
pa = pd.read_csv(
@bsweger
bsweger / financial_balances_agency.md
Last active June 7, 2017 01:03
financial_balances_agency.md

Retrieve financial balances by agency and fiscal year

Route: /api/v2/financial_balances/agencies

Method: GET

This route retrieves financial balance information by funding agency and fiscal year

Sample Request

/api/v2/financial_balances/agencies?funding_agency=775&amp;fiscal_year=2017

@bsweger
bsweger / Vagrantfile
Created December 17, 2012 02:41
Vagrantfile to set up a Python virtual environment for data analysis
Vagrant::Config.run do |config|
config.vm.define :pythondata do |pythondata_config|
# Every Vagrant virtual environment requires a box to build off of.
pythondata_config.vm.box = "precise64"
# The url from where the 'config.vm.box' box will be fetched if it
# doesn't already exist on the user's system.
pythondata_config.vm.box_url = "http://files.vagrantup.com/precise64.box"
# Forward a port from the guest to the host, which allows for outside
@bsweger
bsweger / Taxes Paid and Personal Income.ipynb
Last active November 21, 2017 22:22
Federal Taxes by State
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bsweger
bsweger / iterm_profile.json
Created December 12, 2017 14:09
Profiles and Dotfiles
{
"Ansi 3 Color" : {
"Green Component" : 0.73333334922790527,
"Blue Component" : 0,
"Red Component" : 0.73333334922790527
},
"Tags" : [
],
"Ansi 12 Color" : {
@bsweger
bsweger / seti_grants.py
Created March 9, 2018 18:40
USASpending API Snippets
# Get SETI Institute grants from USAspending API into a pandas dataframe
import json
import requests
import pandas as pd
from pandas.io.json import json_normalize
uri = 'https://api.usaspending.gov/api/v2/search/spending_by_transaction/'
headers = {'content-type': 'application/json'}
seti_json = []
next = 1
### Keybase proof
I hereby claim:
* I am bsweger on github.
* I am bendystraw (https://keybase.io/bendystraw) on keybase.
* I have a public key ASCmomBSZgzxe3w1YQf-eZwTB3KNg7k4VGD29NN8hhmrDAo
To claim this, I am signing this object: