Skip to content

Instantly share code, notes, and snippets.

View jkaupp's full-sized avatar

Jake Kaupp jkaupp

View GitHub Profile
@bds
bds / SparkLines in R
Created December 30, 2010 14:27
Sample sparkline plot using ggplot
library(ggplot2)
sparkLinePlot <- function(df, plot.file) {
highest <- subset(df, outcomes == max(outcomes))
lowest <- subset(df, outcomes == min(outcomes))
p <- ggplot(df, aes(x=date, y=outcomes)) +
geom_line() +
opts(panel.border = theme_rect(linetype = 0),
@ryangray
ryangray / buttondown.css
Created February 22, 2012 06:45
A clean, minimal CSS stylesheet for Markdown, Pandoc and MultiMarkdown HTML output.
/*
Buttondown
A Markdown/MultiMarkdown/Pandoc HTML output CSS stylesheet
Author: Ryan Gray
Date: 15 Feb 2011
Revised: 21 Feb 2012
General style is clean, with minimal re-definition of the defaults or
overrides of user font settings. The body text and header styles are
left alone except title, author and date classes are centered. A Pandoc TOC
@meefen
meefen / lsa_mds.R
Last active September 30, 2019 20:17
Analyze Text Similarity in R: Latent Semantic Analysis and Multidimentional Scaling
# load required libraries
library(tm)
library(ggplot2)
library(lsa)
# 1. Prepare mock data
text <- c("transporting food by cars will cause global warming. so we should go local.",
"we should try to convince our parents to stop using cars because it will cause global warming.",
"some food, such as mongo, requires a warm weather to grow. so they have to be transported to canada.",
"a typical electronic circuit can be built with a battery, a bulb, and a switch.",
@briatte
briatte / crayola.R
Last active December 18, 2015 16:49
Crayola color vector for R
crayola <- structure(c("#EFDECD", "#CD9575", "#FDD9B5", "#78DBE2", "#87A96B",
"#FFA474", "#FAE7B5", "#9F8170", "#FD7C6E", "#000000", "#ACE5EE",
"#1F75FE", "#A2A2D0", "#6699CC", "#0D98BA", "#7366BD", "#DE5D83",
"#CB4154", "#B4674D", "#FF7F49", "#EA7E5D", "#B0B7C6", "#FFFF99",
"#1CD3A2", "#FFAACC", "#DD4492", "#1DACD6", "#BC5D58", "#DD9475",
"#9ACEEB", "#FFBCD9", "#FDDB6D", "#2B6CC4", "#EFCDB8", "#6E5160",
"#CEFF1D", "#71BC78", "#6DAE81", "#C364C5", "#CC6666", "#E7C697",
"#FCD975", "#A8E4A0", "#95918C", "#1CAC78", "#1164B4", "#F0E891",
"#FF1DCE", "#B2EC5D", "#5D76CB", "#CA3767", "#3BB08F", "#FEFE22",
"#FCB4D5", "#FFF44F", "#FFBD88", "#F664AF", "#AAF0D1", "#CD4A4C",
@Btibert3
Btibert3 / parse-jsonp.R
Created October 26, 2013 22:43
Parse JSONP with R
# http://stackoverflow.com/questions/9455437/parse-jsonp-with-r/9463929#9463929
j <- readLines('http://live.nhl.com/GameData/20112012/2011020908/Roster.jsonp')
j <- sub('[^\\{]*', '', j) # remove function name and opening parenthesis
j <- sub('\\)$', '', j) # remove closing parenthesis
library(rjson)
res <- fromJSON(j)

This is a short demo of how to use brew and knitr in combination with each other to get the best of the templating facilities in brew and the literate programming functions in knitr. The main idea is to write a function brew_knit

# Preprocess template using brew and then run knit on the output
brew_knit <- function(template, params, ...){
 brew::brew(template, envir = list2env(params))
 input = gsub(".Rnwe", '.Rnw', template)
 knitr::knit(input)
}
@ojessen
ojessen / passwd_prototype.R
Created January 27, 2014 20:30
Protoype password handling with hash
require(digest)
require(shiny)
ui <- basicPage(
uiOutput("register"),
actionButton("doRegister",label="Register"),
verbatimTextOutput("resultRegister"),
uiOutput("login"),
---
title: "SO22524822"
author: "Thell"
date: "03/21/2014"
output: html_document
---
```{r setup}
# A killPrefix hook.
default_output_hook <- knitr::knit_hooks$get("output")
@Bouke
Bouke / gist:10454272
Last active September 22, 2023 17:23
Install FreeTDS, unixODBC and pyodbc on OS X

First, install the following libraries:

$ brew install unixodbc
$ brew install freetds --with-unixodbc

FreeTDS should already work now, without configuration:

$ tsql -S [IP or hostname] -U [username] -P [password]
locale is "en_US.UTF-8"

locale charset is "UTF-8"

@ramhiser
ramhiser / latlong2fips.r
Created May 6, 2014 03:35
Latitude/Longitude to FIPS Codes via the FCC's API
# FCC's Census Block Conversions API
# http://www.fcc.gov/developers/census-block-conversions-api
latlong2fips <- function(latitude, longitude) {
url <- "http://data.fcc.gov/api/block/find?format=json&latitude=%f&longitude=%f"
url <- sprintf(url, latitude, longitude)
json <- RCurl::getURL(url)
json <- RJSONIO::fromJSON(json)
as.character(json$County['FIPS'])
}