Skip to content

Instantly share code, notes, and snippets.

View wush978's full-sized avatar
👶
Working with my baby

Wush Wu wush978

👶
Working with my baby
View GitHub Profile
argv <- commandArgs(TRUE)
suppressPackageStartupMessages(library(quantmod))
# getSymbols("^TWII")
# saveRDS(TWII, "TWII.Rds")
TWII <- readRDS("TWII.Rds")
print(TWII[argv[1]])
library(Rcpp)
cppFunction(code='
void hello() {
Rcout << "hello" << std::endl;
}')
hello()
# 應該出現hello
get_mat <- function(n) {
retval <- diag(1, n)
retval[lower.tri(retval)] <- 1
retval[,rev(1:n)]
}
@wush978
wush978 / custom.css
Created May 19, 2014 05:23
R Tutorial css template
img.fit100 {
max-width:100%;
max-height:100%;
}
/* copy from https://github.com/asimihsan/going_faster_with_python/blob/9dd25b5638ad73c0e2154024079379dc5f711d18/doc/presentation/slidify/assets/css/aicustom1.css */
/*
@import url(http://fonts.googleapis.com/css?family=Source+Sans+Pro:400,600,700,900,400italic,600italic,700italic,900italic&subset=latin,latin-ext);
@import url(http://fonts.googleapis.com/css?family=Inconsolata:400,700&subset=latin,latin-ext);
split.withleading <- function(x, a) {
Map(function(i,j) x[i:j], a, cumsum(diff(c(a, length(x)+1))))
}
gregexpr.extract_subpattern <- function(pattern, text, pattern.name) {
r <- gregexpr(pattern, text, perl=TRUE)
sapply(seq_along(r), function(i) {
if (r[[i]] == -1) return("")
a <- attributes(r[[i]])
stopifnot(isTRUE(all.equal(pattern.name, a$capture.names)))
substring(text[i], a$capture.start, a$capture.start + a$capture.length - 1)
})
}
@wush978
wush978 / vectorPlusScalar.cpp
Created June 27, 2014 13:15
Demo of `Rcpp::sugar::Plus_Vector_Primitive`
#include <Rcpp.h>
using namespace Rcpp;
//[[Rcpp::export]]
SEXP vectorPlusScalar(NumericVector src) {
int z = 1;
return wrap(src + z);
}
@wush978
wush978 / pbdMPI_communicator_testing.R
Created July 1, 2014 08:26
`mpirun -np 4 Rscript -e "library(devtools);source_gist('ae4bae08454d0fe8f64c')"`
library(pbdMPI)
{ # setting mpi environment
.size <- comm.size()
.rank <- comm.rank()
# .hostname <- system("hostname", intern=TRUE)
.hostname <- paste(.rank %% 2)
hostname <- allgather(.hostname, unlist=TRUE)
group <- split(seq_along(hostname) - 1, hostname)
.group <- as.integer(which(names(group) == .hostname) - 1)
.group.rank <- as.integer(which(group[[.hostname]] == .rank) - 1)
@wush978
wush978 / a.R
Last active August 29, 2015 14:03
source("b.R")
hello()
cat("asdkfja;sldfa;sl\n")