Skip to content

Instantly share code, notes, and snippets.

@rcackerman
rcackerman / direct2food.py
Created July 3, 2012 22:42
Finding a block of text using a string
import urllib2
from bs4 import BeautifulSoup
import re
def findBlockWithString(string, childtag, contentattrs, soup):
"""Finds tag within a block of HTML, using a string search. It goes through 3 steps:
it finds the 'tag' that includes the 'string' we're looking for, within the soup defined
by the program, then finds the parent HTML tag. Finally it finds the tag wanted
using the tag attribute, "contentattrs".
import csv, ast, re
with open("/Users/rackerman/Projects/provider directory scrapers/d2h_listings.txt") as infile:
listings = ast.literal_eval(infile.read())
with open("/Users/rackerman/Projects/provider directory scrapers/d2h.csv", "w") as outfile:
fieldnames = ["Program Contact", "Program/Facility Location", "Total Number of Units",
"Housing Type", "Services", "Location(s)", "Sobriety Requirement", "Populations served",
"Eligibility requirements", "How to apply", "Required documents", "Additional information"]
outfile.write(u'\ufeff'.encode('utf8')) # BOM (optional...Excel needs it to open UTF-8 file properly)
@rcackerman
rcackerman / breadcrumb.php
Created September 21, 2012 21:34
breadcrumb code
// WooCommerce Compatable Breadcrumbs
function limelight_breadcrumbs()
{
global $post, $wp_query;
if ( ! $home ) $home = __( 'Home', 'limelight' );
$home_link = home_url();
$delimiter = ' » ';
$currentBefore = '<span class="current">';
$currentAfter = '</span>';
$wrap_before = ' <nav id="breadcrumbs">';
@rcackerman
rcackerman / homebrew-python27.markdown
Last active October 10, 2025 20:23
Installing/updating Python 2.7 with Homebrew

Installing Python 2.7 with Homebrew

For Mac 10.8.x

1) Install XCode 4.4

Get it from the App Store.

@rcackerman
rcackerman / pearwithmamp.md
Created December 6, 2012 21:10
PEAR with MAMP

PEAR doesn't work immediately, even if you're working with the PEAR rolled in with MAMP. Make sure to change these things, as they are originally set to use usr/bin or usr/lib:

  • PEAR executables directory bin_dir /Applications/MAMP/bin/php/php5.4.4/bin
  • PEAR documentation directory doc_dir /Applications/MAMP/bin/php/php5.4.4/lib/php/doc
  • PHP extension directory ext_dir /Applications/MAMP/bin/php/php5.4.4/lib/php/extensions/no-debug-non-zts-20100525
  • PEAR directory php_dir /Applications/MAMP/bin/php/php5.4.4/lib/php
 Configuration (channel pear.php.net):
=====================================
Auto-discover new Channels auto_discover 1
@rcackerman
rcackerman / gistools.md
Last active December 31, 2015 20:39
Installing gis tools with homebrew

Installing gdal:

brew update
pip install numpy
brew install lzlib
xcode-select --install

Gdal has been moved to homebrew/science, so:

@rcackerman
rcackerman / do.py
Created October 30, 2014 00:24
Why isn't this working?? :-(
def get_dict_keys(url):
keys = []
op = s.urlopen(url)
bs = BeautifulSoup(op)
keys_th = bs.find('table', class_ = 'intv').find('tr').find_all('th')
[keys.append(key.string) for key in keys_th]
print keys
keys
@rcackerman
rcackerman / emptydataframes.R
Last active August 29, 2015 14:09
How to add to an empty data frame.
# as.numeric prevented weird row names, for some reason
SumStats <- function(df){
out <- data.frame(row.names = FALSE)
for (name in names(df)[2:length(names(df))]) {
min = as.numeric(min(df[[name]]))
p20 = as.numeric(quantile(df[[name]], probs=0.20, na.rm=TRUE))
mean = as.numeric(mean(df[[name]]))
median = as.numeric(median(df[[name]]))
@rcackerman
rcackerman / concats.py
Created January 12, 2015 21:25
Creating conditional concatenated columns in Pandas
import pandas as pd
import numpy as np
# for text columns A and B
df['rel'] = ''
df.ix[(df.A == df.B), 'rel'] = df.A
df.ix[(df.A != df.B), 'rel'] = df.A + "/" + df.B
# for number columns A and B
df['rel'] = np.nan
@rcackerman
rcackerman / readinglist.md
Last active August 29, 2015 14:14
Steps to S3
  1. Created AWS account, then IAM account and S3 bucket.
  2. Gave IAM access to the S3 bucket via the user page https://console.aws.amazon.com/iam/home#users/<username>/attachPolicy
  3. Copied app/assets/images and app/assets/csv
  4. Added CORS