Skip to content

Instantly share code, notes, and snippets.

View mattspence's full-sized avatar

Matt Spence mattspence

View GitHub Profile
cigar
rebut
sissy
humph
awake
blush
focal
evade
naval
serve
@mattspence
mattspence / cps20152017.r
Created February 21, 2018 22:06
Count First, Second, and Third+ Generations from 2015, 2016, and 2017 CPS Public Use Microdata
library(tidyverse)
download.file("http://thedataweb.rm.census.gov/pub/cps/march/asec2017_pubuse.zip", "asec2017_pubuse.zip")
download.file("http://thedataweb.rm.census.gov/pub/cps/march/asec2016_pubuse_v3.zip", "asec2016_pubuse.zip")
download.file("http://thedataweb.rm.census.gov/pub/cps/march/asec2015_pubuse.zip", "asec2015_pubuse.zip")
unzip("asec2017_pubuse.zip", "asec2017_pubuse.dat")
unzip("asec2016_pubuse.zip", "asec2016_pubuse_v3.dat")
unzip("asec2015_pubuse.zip", "asec2015_pubuse.dat")
gendata <- function(flnm){
read_fwf(flnm,
fwf_cols(rectype=c(1,1),
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
## This is a comment.
##
## R code to do two data visualizations for hospitals and health data.
## Requires healthandhospitals.csv
## Also requires 4 packages: dplyr, ggplot2, reshape2, and scales
## To download those packages, type the following:
setInternet2(TRUE) ## This helps download packages in our firewalled environment
install.packages(c("dplyr", "ggplot2", "reshape2", "scales"), dependencies=TRUE)
@mattspence
mattspence / script
Created October 3, 2013 03:44
script for geolocation and then jQuery post to a web2py controller
<script>
function getLocation() {
if(navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(postLocation);
function postLocation(position)
{
jQuery.post( '{{=URL('set_location')}}',{lat: +position.coords.latitude, lng: +position.coords.longitude });
}
}
@mattspence
mattspence / web2py geolocate
Created October 2, 2013 23:31
Geolocate the browser and store lat,lng in session if and only if it's not already in session
controller:
def index()
return dict(latitude=session.latitude, longitude=session.longitude)
def set_location():
session.latitude = request.vars.lat
session.longitude = request.vars.lng
default/index.html: