Skip to content

Instantly share code, notes, and snippets.

View dpastoor's full-sized avatar

Devin Pastoor dpastoor

  • A2-Ai
  • Rockville, MD
View GitHub Profile
@dpastoor
dpastoor / test.json
Created January 22, 2016 17:32
test-data
{
"name": "myCoolPlot",
data: [{x: 1, y:0}, {x: 2, y: 4}]
}
@dpastoor
dpastoor / async-await.js
Last active February 7, 2016 07:00
example of async await for reading multiple files
let Promise = require('bluebird');
let fs = Promise.promisifyAll(require('fs')); // adds Async() versions that return promises
let path = require('path');
let _ = require('lodash');
/** Returns the number of files in the given directory. */
let countFiles = async function(dir) {
let files = await fs.readdirAsync(dir);
console.log(files);
let paths = _.map(files, (file) => path.join(dir, file));

We're excited to have you attend one of our workshops! Here's a JavaScript (re)fresher to help you get up-to-speed on some features of the language we'll be using.

Let and Const

JavaScript has always had var:

var name = 'Ryan'
library(MASS)
library(shiny)
library(mrgsolve)
library(dplyr)
library(magrittr)
library(parallel)
RNGkind("L'Ecuyer-CMRG")
set.seed(101)
@dpastoor
dpastoor / vec_to_ltm.R
Created March 12, 2016 15:09
vector to lower triangle matrix
b = matrix(0, 2, 2)
b[lower.tri(b, diag=T)] = as.numeric(c("1.23E-01",
"0.00E+00",
"1.54E-01"))
@dpastoor
dpastoor / gist:98ffc68da4dba3198e061bb31633fdae
Created August 10, 2016 15:21
future example for parallel processing very raw
library(microbenchmark)
library(tibble)
library(future)
library(dplyr)
nids <- 16
sleep_times <- data_frame(REP = 1:nids, sleep_time = round(runif(nids, 0, 2), 0))
sleep_times
eager_bm <- function(sleep_times) {
plan(eager)
library(future)
library(mrgsolve)
library(dplyr)
data(extran3)
ipar <- extran3 %>% dplyr::select(ID,CL,VC,KA) %>% distinct(ID)
mod <- mrgsolve:::house()
plan(multiprocess)
f <- list()
for (ii in 1:2) {
@dpastoor
dpastoor / simulation_client.R
Created August 31, 2016 14:15
logging simulations
```{r}
library(pbdZMQ)
library(future)
sim_logger <- function(rep, message = "") {
context <- zmq.ctx.new()
sink <- zmq.socket(context, .pbd_env$ZMQ.ST$PUSH)
zmq.connect(sink, "tcp://localhost:5558")
zmq.send(sink, paste("completed sim", rep, "from process", Sys.getpid(), "with message: ", message))
@dpastoor
dpastoor / all.R
Created November 21, 2016 21:16
ggplot linking scales
library(ggplot2)
t1<-seq(0,40,0.2)
a1<-seq(from =1, to =0, length.out = length(t1))
a2<-seq(from = 1, to = 0.4, length.out = length(t1))
a3<-seq(from = 1, to = 0.6, length.out = length(t1))
df1<-data.frame(time = t1, surv = a1)
df2<-data.frame(time = t1, surv = a2)
df3<-data.frame(time = t1, surv = a3)
@dpastoor
dpastoor / changeDirInGoroutine.go
Created December 2, 2016 14:47
changing dirs in a goroutine leads to issues about what dir expected to be in since the dir is set per os thread
package main
import (
"fmt"
"path/filepath"
"sync"
"time"
)
import "os"