Skip to content

Instantly share code, notes, and snippets.

library(lpSolve)
preds$team <-as.character(preds$team)
obj = preds$prediction
con <- rbind(t(model.matrix(~ FD.Position + 0,preds)), t(model.matrix(~ team + 0, preds)), rep(1,nrow(preds)), preds$Salary)
dir <- c(">=",">=",">=",">=",">=",rep('<=',length(unique(preds$team))),"<=","<=")
rhs <- c(1,2,2,2,2,rep(4,length(unique(preds$team))),9,60000)
result = lp("max", obj, con, dir, rhs, all.bin = TRUE)
preds[which(result$solution == 1),]
@tcash21
tcash21 / server.R
Created January 18, 2016 17:18
Reddit Live Game Thread Swears by Fanbase Dashboard
library(stattleshipR)
library(ggplot2)
library(dplyr)
library(shiny)
library(shinydashboard)
library(RCurl)
## get a free Stattleship API token from www.stattleship.com
set_token("stattleship-token")
import praw
import re
import pandas as pd
import tinys3
## S3 Connection Credentials
conn = tinys3.Connection('S3_ACCESS_KEY','S3_SECRET_KEY',tls=True)
## Login to Reddit
r = praw.Reddit(user_agent='Live r/NFL Game Thread Scraper')
devtools::install_github("stattleship/stattleship-r")
library(stattleshipR)
## Get a free Stattleship API token from www.stattleship.com
set_token('set-your-token')
sport <- 'football'
league <- 'nfl'
ep <- 'game_logs'
devtools::install_github("stattleship/stattleship-r")
library(stattleshipR)
## Sign up for one of these from www.stattleship.com
set_token('your-API-token')
## Set the parameters according to
## playbook.stattleship.com
league <- "nba"
sport <- "basketball"
@tcash21
tcash21 / README.md
Last active December 9, 2015 01:17 — forked from Btibert3/README.md
Testing stattleship, weird error

About

Updated the queryAPI and created a new function, stattle that wraps it and makes walking easier. jsonlite is great, but I started to bump into some issues with dplyr::bind_rows. Right now these two functions play nice together, but needs to be further tested.

Load/Install

## source the functions
devtools::source_url('https://gist.githubusercontent.com/tcash21/44667f7b8578cc8e061e/raw/fdac84a0a445e448427cc3557e8c9393ce1fa470/queryAPI.r')
@tcash21
tcash21 / README.md
Last active December 8, 2015 23:03 — forked from Btibert3/README.md
R function template and some basic tests for the API

About

Get the function out of the RMD file and start to put some structure to it.

Tear it apart.

To source the function

u = "https://gist.githubusercontent.com/Btibert3/c20c59a2b925562aa050/raw/f5a395239b78fc649432cfb6fcb7c22d8877225c/queryAPI.r"
library(ROAuth)
requestURL <- "https://api.twitter.com/oauth/request_token"
accessURL <- "https://api.twitter.com/oauth/access_token"
authURL <- "https://api.twitter.com/oauth/authorize"
consumerKey <- 'XXXXX'
consumerSecret <- 'XXXXXX'
my_oauth <- OAuthFactory$new(consumerKey = consumerKey,
consumerSecret = consumerSecret,
requestURL = requestURL,
library(twitteR)
library(RMySQL)
mydb = dbConnect(MySQL(), user='username', password='password', dbname='tweets', host='hostname', port=3306)
load("OAuth.dat")
registerTwitterOAuth(my_oauth)
## Capture tweets within 150 mile radius of Boston that mention 'Patriots'
p<-tryCatch(searchTwitter("Patriots", geocode=c("42.368750,-71.055279,150mi"), n=750), error=function(e) print(e$message))
@tcash21
tcash21 / app.css
Last active December 25, 2015 03:39
From Big Data meetup 10-9-2013
.well {
width: 250px;
}