Skip to content

Instantly share code, notes, and snippets.

Gary Feng garyfeng

  • Educational Testing Service
  • United States
Block or report user

Report or block garyfeng

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
garyfeng /
Last active Jul 17, 2018
The following scripts were used on 2018-07-09 to generate descriptive writing features for 2017 reporting. It's done on Kurt, using the pdia docker. Steps:
# Functions for extracting the descriptive features for the 2017 operational analysis
# Changes from
# - min
import StringIO
import os
import traceback
View CKEditorCursorPosition.js
// sample code for calculating the caret cursor position in CKEditor
// including functions to deal with cross-browser inconsistencies for end-of-the-line
// A hack to get text from HTML
var html2text = function (html) {
// testing the idea of using .toString() with a replacement trick
// knowing that .textContent doesn't preserve the newlines, let's replace </p> with 2 newline chars
// This is ignoring all other HTML/CSS markups, such as <br>, tables, etc.
View Keystroke logging implementation.markdown
garyfeng / HeatmapWithTransparentBackground.svg
Created Jun 2, 2016
Adding a transparent background image to's SVG output. Two changes: (a) set opacity in `<g class="subplot xy" style = "opacity:0.5">`, and (b) adding an image in the "layer-below >> imagelayer" group.
View HeatmapWithTransparentBackground.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View garyfengJupyterStyle.css
Taken from
Modified for Gary Feng's Jupyter notebooks
html {
font-size: 62.5% !important; }
View Keystroke logging implementation.markdown
garyfeng / getListAttribute.r
Last active Sep 23, 2015
Creating an operator to extract a named member of a list that is in a list. Why? Read on. [Now part of the "pdata" library at
View getListAttribute.r
# 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.
garyfeng / interp.r
Created May 30, 2015
R tricks with lazyeval::interp():
View interp.r
# taken from
# What if you need to mingle constants and variables? Use the handy lazyeval::interp():
# 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
garyfeng / backFillNA.r
Last active Jan 13, 2016
A function to back fill NAs in a vector with the last non-NA value
View backFillNA.r
# A function to back fill NAs in a vector with the last non-NA value
backFillNA<- function (x) {
nas<- which(
# trick from
naList<-split(nas, cumsum(c(1, diff(nas) != 1)))
# get the backfill values
valueList<-lapply(naList, function(nalist) {
prev<- nalist[1]-1
garyfeng / importData2TraMineR.r
Created May 30, 2015
TraMineR seqdef() is picky. Sometimes you need to define a new data frame just to get it recognized.
View importData2TraMineR.r
# 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
You can’t perform that action at this time.