Skip to content

Instantly share code, notes, and snippets.

View mhkeller's full-sized avatar

Michael Keller mhkeller

View GitHub Profile
@mhkeller
mhkeller / gist:3685743
Created September 9, 2012 17:11
XPath scraping in R
library("XML")
library("RCurl")
url = "http://thecaucus.blogs.nytimes.com/"
xpath = '//*[@id="entry-230579"]/div/text()'
page = getURL(url)
tree = htmlTreeParse(page, useInternalNodes=TRUE)
text = getNodeSet(tree, '//*[@id="entry-230579"]/div')
text
find: ([a-z]) (["])([a-z])
replace: $1 \\$2$3
find: .""
replace: ./""
find: ([a-z])(["]) ([a-z])
replace: $1\\$2 $3
@mhkeller
mhkeller / [The Listserve] Against Drift
Created September 25, 2012 18:32
[The Listserve] Against Drift, 9/25/12: Solid Ps.
I was raised in a very Catholic household, but lately a bit of my once-strong Catholic identity has been peeling away. I haven't been to church since May, I'm questioning my thoughts on a lot of the Church's social doctrines, and I don't pray nearly as often as I used to.
I got some bad news from home recently about a friend, and only several days later did I even think to pray. Realizing that I had forgotten that astounded me, because in other times that would have been my first instinct. Trying to pray, however, felt no better. I felt weird asking for God's help--like a friend who hasn't called you back in months but suddenly needs a place to crash. I ended up calling my mom and asking her to pray, because I feel like my prayers have by now lost whatever potency they may have ever held.
If I'm going to be a lapsed Catholic, I want it to be a product of reading and honest questioning, investigating the philosophical arguments for Catholicism, really narrowing down what I agree with. Basically, I want to ha
@mhkeller
mhkeller / gist:3796135
Created September 27, 2012 19:58
Stacked bar chart in HTML/CSS
All of the google results for this are outdated / don't work. Here's a simple fiddle that stakes div relative to the bottom of its container div.
http://jsfiddle.net/9pXpU/
<div class="colWrapper">
<div class="barContainer">
<div class="bar" style="background-color:#b4cde2;"></div>
<div class="bar" style="background-color:#7ca7cc;"></div>
<div class="bar" style="background-color:#6094c1;"></div>
@mhkeller
mhkeller / gist:3824308
Created October 3, 2012 01:07
Point to Polygon intersect PostGIS
UPDATE point_table SET polygon_id = poly_table.poly_id FROM poly_table WHERE ST_Intersects(point_table.the_geom, poly_table.the_geom);
@mhkeller
mhkeller / gist:3834498
Created October 4, 2012 15:45 — forked from abelsonlive/gist:3751902
google geocoding API, R
Forked from @BrianAbelson
library('rjson') # For parsing json in R
library('RCurl') # For sending an http request
library('plyr') # For ddply
# Takes an data frame with a unique id column and an address column at the very least
# it returns a data frame with the uid, lat, lng and specificity of geocoding
# use the uid to join these results back to your data if you want
# you can also accomplish roughly the same thing with a for loop instead of ddply
@mhkeller
mhkeller / gist:3835047
Created October 4, 2012 17:14
Input Google Doc to R
csvData <- getURL("https://docs.google.com/spreadsheet/pub?key=[YOUR-KEY-GOES-HERE]&output=csv")
df <- read.csv(textConnection(csvData), stringsAsFactors = FALSE)
location_type stores additional data about the specified location. The following values are currently supported:
"ROOFTOP" indicates that the returned result is a precise geocode for which we have location information accurate down to street address precision.
"RANGE_INTERPOLATED" indicates that the returned result reflects an approximation (usually on a road) interpolated between two precise points (such as intersections). Interpolated results are generally returned when rooftop geocodes are unavailable for a street address.
"GEOMETRIC_CENTER" indicates that the returned result is the geometric center of a result such as a polyline (for example, a street) or polygon (region).
"APPROXIMATE" indicates that the returned result is approximate.
@mhkeller
mhkeller / gist:3840454
Created October 5, 2012 15:20
iPad iPhone media queries
<!--[if !IE]>-->
<link type="text/css" rel="stylesheet" media="only screen and (max-device-width: 480px)" href="css/iPhone.css" />
<link type="text/css" rel="stylesheet" media="only screen and (min-device-width: 768px) and (max-device-width: 1024px)" href="css/iPad.css" />
<!--<![endif]-->
@mhkeller
mhkeller / gist:3840492
Created October 5, 2012 15:27
Inline media queries
/*
* MEDIA QUERIES
*/
/* tablet landscape / netbook */
@media screen and (max-width: 1024px) {}
/* iPad Retina Display (2048x1536 264ppi) */
@media screen and (max-width: 1536px) and (resolution: 264ppi) {}