A sample of a simple implementation of keystroke logging required for plain text entry fields in SBTs
Forked from Lonnie Smith's Pen Keystroke logging implementation. Reimplemented using JsDiff.
# r code to test and install libraries if not already installed. | |
# code taking from stackoverflow | |
pkgInstall <- function(x) | |
{ | |
if (!require(x,character.only = TRUE)) | |
{ | |
install.packages(x,dep=TRUE) | |
if(!require(x,character.only = TRUE)) stop("Package not found") | |
} |
// see range.js and selection.js for the source | |
// so we have 3 things to work with: | |
// CKEditor.dom selections, ranges, and bookmarks | |
// first, to get the CKeditor instance, use | |
var editor = CKEDITOR.instances.editor1; | |
// selection something in the editor, and get the selection: | |
var sel = editor.getSelection(); |
# A function that takes a vector or a list of strings and a regex pattern, | |
# and returns a vector of strings that matches the regex patterns. Don't | |
# have parameter checking, error handling, etc. | |
# The key lesson learned is that regmatches() is badly designed | |
# as it silently drops any non-matched elements. As a result, the length | |
# of the returned vector may nor may not be the same as the input. | |
# had to use the good-o substring() trick. | |
# The second lesson is that when the regex pattern contains several (), such |
# I am mystified by how Traminer handles the data format. | |
# Here's the data from the 2015 NAEP Reading tryout study, SC block | |
# where I transformed the data to simplify the structure. | |
# Then I try to use seqformat() or seqdef() to turn the existing data frame | |
# in to a TraMineR object. | |
sc %>% filter(readingTime>0) %>% group_by(student) %>% arrange(readingTime) %>% | |
mutate(c1=1:n(), c2=2:(n()+1), t0=c(1, readingTime[1:n()-1])) %>% | |
select(student, c1, c2, state2, t0, readingTime, event2) %>% na.omit() ->scSPELL |
# A function to back fill NAs in a vector with the last non-NA value | |
# https://gist.github.com/garyfeng/27e7f8e406192a8cb33a | |
backFillNA<- function (x) { | |
nas<- which(is.na(x)) | |
# trick from http://stackoverflow.com/questions/24837401/find-consecutive-values-in-vector-in-r | |
naList<-split(nas, cumsum(c(1, diff(nas) != 1))) | |
# get the backfill values | |
valueList<-lapply(naList, function(nalist) { | |
prev<- nalist[1]-1 |
# taken from | |
# http://cran.rstudio.com/web/packages/dplyr/vignettes/nse.html | |
# What if you need to mingle constants and variables? Use the handy lazyeval::interp(): | |
library(lazyeval) | |
# Interp works with formulas, quoted calls and strings (but formulas are best) | |
interp(~ x + y, x = 10) | |
#> ~10 + y | |
interp(quote(x + y), x = 10) | |
#> 10 + y |
# To create an operator to extract a named member of a list that is in a list. | |
# This may sound confusing, but imagine you have a data.frame where a variable/column is a list of lists, | |
# and the lists have named members, e.g., | |
# df$itinary <- list(list(from="NYC", to="LA", via="train"), list(from="LA", to="SF"), ...) | |
# You want to get the "from" value of itinary as a vector. You can do | |
# df$itinary@"from" or `@`(df$itinary, "via") | |
# Typically you'd use ```sapply(x, function(m) {m[["from"]]})```. The following is an extention to the idea in 2 ways: | |
# 1). We define a in-fix operator `@` that does so in a way that is syntactically more natural | |
# 2). We added error handling, in the case of bad indecies, etc. | |
require(testthat) |
A sample of a simple implementation of keystroke logging required for plain text entry fields in SBTs
Forked from Lonnie Smith's Pen Keystroke logging implementation. Reimplemented using JsDiff.
<style> | |
/* | |
Taken from http://moderndata.plot.ly/custom-styling-for-ipython-notebooks-with-3-lines-of-code/ | |
Modified for Gary Feng's Jupyter notebooks | |
*/ | |
/* | |
html { | |
font-size: 62.5% !important; } |