Skip to content

Instantly share code, notes, and snippets.

View smach's full-sized avatar

Sharon Machlis smach

View GitHub Profile
@smach
smach / NicarLtable.html
Created August 15, 2013 17:27
Test output of googleVis
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!-- saved from url=(0063)http://localhost:34035/custom/googleVis/TableID2f62c93544c.html -->
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>TableID2f62c93544c</title>
<style type="text/css">
body {
color: #444444;
font-family: Arial,Helvetica,sans-serif;
@smach
smach / calc_age.r
Last active August 29, 2015 13:57 — forked from mmparker/calc_age.r
# Useful lubridate function for date subtraction written by mmparker
# Calculate age at a given reference date
# Create an interval between the date of birth and the enrollment date;
# intervals are specific to the two dates. Periods give the actual length
# of time between those dates, so convert to period and extract the year.
calc_age <- function(birthDate, refDate = Sys.Date()) {
require(lubridate)
#!/usr/bin/env ruby
require 'mail'
#### THIS RUBY SCRIPT WAS ORIGINALLY POSTED BY blazeeboy ON GITHUB
mysql_username = 'root'
mysql_password = '123456'
mysql_database = 'test'
system("mysqldump --user=#{mysql_username} --password=#{mysql_password} #{mysql_database} > backup.sql")
@smach
smach / ProportionalElectionResults.R
Created March 27, 2014 02:18
Sample R script for finding winners in a proportional election system
# Sample R script for finding winners in a proportional election system
# by Sharon Machlis
# This example assumes a spreadsheet with a list of candidates with column headers
# Municipality, Party, Place, Name, Variable
# and a spreadsheet with a list of results with column headers
# Municipality, Red, Blue, Green (Red, Blue, Green being sample political party names)
# See sample spreadsheet format at
# https://onedrive.live.com/redir?resid=7DDBA42BF10D288B!662&authkey=!AAFnW1H3wGiZgQU&ithint=file%2c.xlsx
@smach
smach / Test.R
Created November 11, 2014 22:14
Test rCharts Dimple graph to save and then load in RMarkdownn doc
# testGraph
test <- dPlot(
mpg ~ cyl,
data = mtcars,
type = 'bubble',
width=1000,
height=600
)
@smach
smach / Test.Rmd
Created November 11, 2014 22:15
Test R Markdown for rCharts graphs and tooltip problem
---
title: "Dimple Tooltip Test"
author: "Sharon Machlis"
date: "November 11, 2014"
output: html_document
---
```{r, echo=FALSE}
load("testObject.Rda")
suppressPackageStartupMessages(library(rCharts))
@smach
smach / gist:e6d80c8129b94ef639c3
Created November 11, 2014 22:18
Session Info
R version 3.0.2 (2013-09-25)
Platform: x86_64-apple-darwin10.8.0 (64-bit)
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] splines tcltk stats graphics grDevices utils datasets methods base
other attached packages:
install.packages("jsonlite", dependencies = TRUE)
install.packages("RCurl", dependencies = TRUE)
library("jsonlite")
library("RCurl")
base_url <- "https://api.parsely.com/v2"
apikey <- "computerworld.com"
api_secret <- "YOUR SECRET KEY"
@smach
smach / corrviz.R
Created February 28, 2015 20:48
Useful data visualization of a correlation matrix, code from the R Graphics Cookbook by Winston Chang
# Function takes a correlation matrix from the cor() function and outputs a visualization.
# The corrplot package must be installed.
# This code comes from the R Graphics Cookbook by Winston Chang
corrviz <- function(mycorrmatrix){
col <- colorRampPalette(c("#BB4444", "#EE9988", "#FFFFFF", "#77AADD", "#4477AA"))
corrplot::corrplot(mycorrmatrix, method="shade", shade.col=NA, tl.col="black", tl.srt=45, col=col(200), addCoef.col="black")
}
@smach
smach / gist:1660f6cf3d8a68440024
Last active August 29, 2015 14:16
atlantawx.R
url <- "http://forecast.weather.gov/MapClick.php?lat=33.74899931200048&lon=-84.38797796399967&site=all&smap=1#.VPUbWfnF9EI"
library(rvest)
html <- html(url)
forecasthtml <- html_nodes(html, ".row-forecast")
forecast <- html_text(forecasthtml)
# Note: to deal with the lack of spaces now between Today, Tonight, etc. and the start of the forecasts, I added
forecast_formatted <- gsub("day([A-Z])", "day \\1", forecast)
forecast_formatted <- gsub("Night([A-Z])", "Night \\1", forecast_formatted)
forecast_formatted <- gsub("Tonight([A-Z])", "Tonight \\1", forecast_formatted)
forecast_formatted <- gsub("Afternoon([A-Z])", "Afternoon \\1", forecast_formatted)