Skip to content

Instantly share code, notes, and snippets.

@flovv
flovv / ghosteryScrape.r
Created September 28, 2015 19:11
getDatafromGhostery
require(rjson)
library(httr)
require(gtools)
dataframeFromJSON <- function(l) {
l1 <- lapply(l, function(x) {
x[sapply(x, is.null)] <- NA
unlist(x)
})
@flovv
flovv / WordCorrectByGoogle
Created October 4, 2015 15:23
Spelling correction using google's "did you mean ..." function
library(RCurl)
didYouMean=function(input){
input=gsub(" ", "+", input)
doc=getURL(paste("http://www.google.com/search?q=",input,"/", sep=""))
dym=gregexpr(pattern ='Did you mean',doc)
srf=gregexpr(pattern ='Showing results for',doc)
require(jsonlite)
require(V8)
#Task: get the Data from the last table: http://www.thebrandticker.com/en/
## public XHR needs a JS time-stamp.
#http://www.thebrandticker.com/ticker.json?1436337115096
#http://www.thebrandticker.com/brands.json?1436337115102
## daily stock market data from Yahoo
getStockMarketData <- function(symbol = "VOW4.DE"){
require(stringr)
if(str_detect(symbol, ":")){
symbol <- paste(str_split_fixed(symbol, ":", 2)[,2], str_split_fixed(symbol, ":", 2)[,1], sep=".")
}
URL <- paste("http://ichart.finance.yahoo.com/table.csv?ignore=.csv&s=",symbol)
@flovv
flovv / gettingSoccerOdds.R
Last active January 17, 2016 15:08
Soccer Betting Odds
require(rvest)
require(stringr)
url <- "http://www.wettfreunde.net/bundesliga-absteiger-wetten/"
# Darmstadt
1/2.25
1/2.3
mv <- html(url)
@flovv
flovv / gettingZeitOnlineResults.R
Created January 17, 2016 15:09
Getting Content from the "Zeit-online"
#devtools::install_github("chgrl/diezeit")
library(diezeit)
require(ggplot2)
library(plyr)
require(stringr)
require(ggthemes)
options(stringsAsFactors = FALSE)
@flovv
flovv / GFKPanelSizes
Last active January 24, 2016 11:44
illustrate the relationship between panel-based measurement error and panel sizes for GFK and Nielsen
# a simple script to illustrate the relationship between panel-based measurement error and panel sizes
# simple case of party estimate!
require(plyr)
require(ggplot2)
require(ggthemes)
n=1000
p=5
@flovv
flovv / scrapeJSSite.R
Last active May 10, 2018 02:18
Scrape JS sites using Phantom.js and R
options(stringsAsFactors = FALSE)
require(rvest)
scrapeJSSite <- function(dfrom, dto, date="2016-03-27"){
## change Phantom.js scrape file
url <- paste0("https://www.busliniensuche.de/suche/?From=",dfrom,"&To=",dto,"&When=",date,"&ShowRidesharing=false&Company=Alle+Busunternehmen&Passengers=1&SearchMode=0&Radius=15000")
lines <- readLines("scrape_final.js")
lines[1] <- paste0("var url ='", url ,"';")
@flovv
flovv / GoogleVisionAPI.R
Created March 28, 2016 16:04
Using Google's Vision API for cace detection, logo recognition and OCR.with R
## please see flovv.github.com for a short blog post on running the code.
#devtools::install_github("MarkEdmondson1234/googleAuthR")
require(googleAuthR)
require(RCurl)
### plug in your credentials
## create project- enable billing- -- enable APIs Vision APi -- go to credentials create OAuth 2.0 client ID: copy client_id and client_secret from JSON file.
@flovv
flovv / AirBnB_Demographics.R
Created July 3, 2016 15:30
Analyzing AirBnB demographics
## gather data:
require(Roxford)
images <- list.files("sample bilder/")
facekey = "API KEY"
for(i in images[1:200]){
dff <- getFaceResponse(paste0("sample bilder/",i), facekey)