This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| getLongURL.curl <- function(shorturl){ | |
| # uses curl statement to get expanded url from t.co links (or any link) | |
| # loop through until there's no location attribute... that's the long link. | |
| newurl <- shorturl | |
| url <- "" | |
| while(url != newurl){ | |
| data <- system(paste0("curl -I ", newurl), intern=T) | |
| if(sum(grepl("location: ", tolower(data))) == 0){ | |
| url <- newurl | |
| }else{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # faceted | |
| ggplot(df, aes(x=factor(game), y=score)) + | |
| geom_bar(stat="identity",aes(fill=factor(game))) + facet_grid(.~name) + | |
| coord_cartesian(ylim=c(50, 150)) + scale_y_continuous(breaks=a[a%%10==0]) + | |
| scale_fill_discrete(name="Game") + xlab("") + ylab("Score") | |
| ggsave("faceted_bowling.jpg") | |
| # dodged | |
| ggplot(df, aes(x=factor(name), y=score)) + | |
| geom_bar(position="dodge", stat="identity",aes(fill=factor(game))) + |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(rgl) | |
| file <- "data.txt" | |
| smooth <- TRUE | |
| # this data file is a list of heights... z | |
| # x and y are not given, I just create matrices for them | |
| z <- read.delim(file, header=F, sep="|") | |
| z[,1] <- NULL # first column is all nulls... junk | |
| z <- as.matrix(z) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| server <- function(){ | |
| while(TRUE){ | |
| writeLines("Listening...") | |
| con <- socketConnection(host="localhost", port = 6011, blocking=TRUE, | |
| server=TRUE, open="r+") | |
| data <- readLines(con, 1) | |
| print(data) | |
| response <- toupper(data) | |
| writeLines(response, con) | |
| close(con) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| client <- function(){ | |
| while(TRUE){ | |
| con <- socketConnection(host="localhost", port = 6011, blocking=TRUE, | |
| server=FALSE, open="r+") | |
| f <- file("stdin") | |
| open(f) | |
| print("Enter text to be upper-cased, q to quit") | |
| sendme <- readLines(f, n=1) | |
| if(tolower(sendme)=="q"){ | |
| break |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import socket | |
| client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
| client_socket.connect(("localhost", 6011)) | |
| while 1: | |
| data = raw_input ( "Enter text to be upper-cased, q to quit\n" ) | |
| client_socket.send(data) | |
| if ( data == 'q' or data == 'Q'): | |
| client_socket.close() | |
| break; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| client_id <- "client id here" | |
| client_secret <- "client secret here" | |
| redirect_uri <- "https://localhost/oauth2callback" | |
| auth_url <- "https://accounts.google.com/o/oauth2/auth" | |
| scope <- "https://www.googleapis.com/auth/prediction" | |
| api_key <- "api key here" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| code_url <- paste0(auth_url, "?client_id=", client_id, "&redirect_uri=", | |
| redirect_uri, "&response_type=code&scope=", scope) | |
| browseURL(code_url) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| code <- "paste your code from the last step here" | |
| token.curl.request <- paste0('curl -k --header "Content-Type: application/x-www-form-urlencoded" --data "code=', | |
| code, '&client_id=', client_id, '&client_secret=', | |
| client_secret, '&redirect_uri=', redirect_uri, | |
| '&grant_type=authorization_code', | |
| '" https://accounts.google.com/o/oauth2/token') | |
| token <- system(token.curl.request, intern=T) | |
| token_code <- fromJSON(paste(token, collapse=""))$access_token |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| hosted.model <- "sample.languageid" | |
| model.url <- "https://www.googleapis.com/prediction/v1.5/hostedmodels/" | |
| model.curl.request <- paste0('curl -k --header "Content-Type: application/json" --data \'{"input":{"csvInstance":["Como se llama?"]}}\' -H "Authorization: Bearer ', token_code, '" https://www.googleapis.com/prediction/v1.5/hostedmodels/sample.languageid/predict?key=', api_key, " --verbose") | |
| system(model.curl.request, intern=T) |
OlderNewer