Skip to content

Instantly share code, notes, and snippets.

View bsweger's full-sized avatar

Becky Sweger bsweger

View GitHub Profile
@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 / 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 / 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';
@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 / 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 / useful_pandas_snippets.md
Last active November 13, 2024 19:55
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 / Taxes Paid and Personal Income.ipynb
Last active November 21, 2017 22:22
Federal Taxes by State
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@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)