Skip to content

Instantly share code, notes, and snippets.

@rcackerman
rcackerman / pdf.rb
Created November 30, 2015 18:56
prawn
class ReportPdf
include Prawn::View
def initialize(notice)
@notice = notice
noc_header
notice_of_claim
verification_header
verification_body
end
@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
@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 / 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 / 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 / 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 / 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 / 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 / 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 = ' &raquo; ';
$currentBefore = '<span class="current">';
$currentAfter = '</span>';
$wrap_before = ' <nav id="breadcrumbs">';
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)