This file contains 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
#!/bin/bash | |
IPADDR="" | |
if [ -f /usr/bin/ec2metadata ] | |
then | |
IPADDR=`timeout 1 ec2metadata --public-hostname` | |
fi | |
if [ "$IPADDR" = "" ] | |
then |
This file contains 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
# A minimal R Markdown example | |
A quote: | |
> Markdown is not LaTeX. | |
To compile me, run this in R: | |
library(knitr) | |
knit('001-minimal.Rmd') |
This file contains 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
# Example taken from glmnet | |
library(glmnet) | |
# Gaussian | |
x=matrix(rnorm(100*20),100,20) | |
y=rnorm(100) | |
fit1=glmnet(x,y) | |
print(fit1) | |
coef(fit1,s=0.01) # extract coefficients at a single value of lambda | |
predict(fit1,newx=x[1:10,],s=c(0.01,0.005)) # make predictions |
This file contains 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(quantmod) | |
symetf = c('XLY','XLP','XLE','XLF','XLV','XLI','XLB','XLK','XLU','SPY', "GOOG") | |
end<- format(Sys.Date(),"%Y-%m-%d") | |
start<-format(Sys.Date() - 365,"%Y-%m-%d") | |
dat0 = (getSymbols(symetf[1], src="google", from=start, to=end, auto.assign = F, warnings = FALSE,symbol.lookup = F)) | |
n = NROW(dat0) ; l = length(symetf) | |
dat = array(dim = c(n,NCOL(dat0),l)) ; ret = matrix(nrow = n, ncol = l) | |
for (i in 1:l){ | |
dat0 = (getSymbols(symetf[i], src="google", from=start, to=end, auto.assign = F,warnings = FALSE,symbol.lookup = F)) | |
dat[1:n,,i] = dat0 |
This file contains 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
The Normal Distribution | |
======================= | |
The normal distribution is defined as follows: | |
$$latex | |
f(x;\mu,\sigma^2) = \frac{1}{\sigma\sqrt{2\pi}} e^{ -\frac{1}{2}\left(\frac{x-\mu}{\sigma}\right)^2 } | |
$$ | |
To generate random draws from a normal distribution we use the **rnorm** function: |
This file contains 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
This is a test |
This file contains 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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<title>OpenCPU demo app</title> | |
<meta http-equiv="content-type" content="text/html; charset=UTF-8"> | |
<!-- ocpu library --> | |
<script src="//code.jquery.com/jquery-1.10.2.min.js"> </script> | |
<script src="//public.opencpu.org/js/opencpu-0.4.js"> </script> |
This file contains 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
#Assume httr 0.4 | |
library(httr) | |
stopifnot(packageVersion("httr") >= "0.4") | |
#submit a package to CRAN, step 1 | |
submit <- function(name, email, pkg, comment = "Thank you", popup = TRUE){ | |
stopifnot(file.exists(pkg)) | |
req1 = httr::POST ( | |
url = "http://xmpalantir.wu.ac.at/cransubmit/index2.php", | |
encode = "multipart", |
This file contains 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
# The data stream is not JSON itself. It contains lines with JSON data. Therefore | |
# this example manually collapses it into a JSON array. The file is also quite | |
# large, so we would need to do some batch processing by splitting the file before | |
# feeding it to R. This example shows how to read first 20 records. | |
library(jsonlite) | |
gzdata <- gzcon(url("http://78.46.48.103/sample/hourly_14.json.gz")) | |
records <- readLines(gzdata, n = 20) | |
close(gzdata) | |
json <- paste0("[", paste0(records, collapse=","), "]") |
This file contains 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
# Version 1 | |
deparse_vector1 <- function(x) { | |
stopifnot(is.character(x)) | |
vapply(x, deparse, character(1), USE.NAMES=FALSE) | |
} | |
# Version 2 | |
deparse_vector2 <- function(x) { | |
stopifnot(is.character(x)) | |
if(!length(x)) return(x) |
OlderNewer