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
## Once you've loaded the dependencies you don't have to load them again in a session | |
## May have to install them via `install.packages(c('RJSONIO', 'plyr'))` first and only once per device | |
# Uses C parser for faster results compared to rjson | |
require('RJSONIO') | |
# Get a quick non-trivial function example | |
require('plyr') | |
# body(x) extracts the function body for x (also could set the function body of x) | |
ddBody <- as.list(body(ddply)) |
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
# For each element, match against the data frame of longer vectors | |
compSlightlySmarter <- function(element, table) { | |
matches <- sapply(table, function(x) { | |
# finds exact matches of element to the 'table' (one column in the longer df) | |
locations <- match(element, as.character(x)) | |
# if there are no unbroken or unordered sequences, it's a match! | |
return(!any(is.na(locations)) & !is.unsorted(locations)) | |
}) | |
if(any(matches)) { | |
# unlike the dumb version, we return matches |
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
long <- data.frame(c("foo","qux","baz","quux"),c("baz","bar","foo","corge")) | |
shrt <- data.frame(c("foo","bar","baz"),c("baz","bar","foo")) | |
concatDumb <- function(data) { | |
listed <- sapply(data, function(x) { | |
# concatenate the character vectors to use substring matching | |
paste0('$', paste(unname(x), collapse = '$'), '$') | |
}) | |
return(unname(listed)) | |
} |
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
/* | |
* sigDigitFind | |
* | |
* Determine position of most significant digit | |
* | |
* Returns a positive number for significant digits left of the radix | |
* and a negative number for right of the radix. | |
* | |
* @param {String} inputFloat A String (optionally a Number) representing a | |
* floating point number. |
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
var numerator = [1,2,3,4]; | |
var denominator = [4,3,2,1]; | |
numerator.map(function(elem, index) { | |
return elem / denominator[index]; | |
}); |
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 | |
for remote in gnarf jugglinmike oconnore protonk rwaldron | |
do | |
git remote add $remote git@github.com:$remote/gaia | |
done |
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
function randme(arr) { | |
var rand = parseInt(Math.random().toString().charAt(3), 10); | |
return arr[rand % arr.length]; | |
}; |
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
function intAdd(arr) { | |
var out; | |
out = arr.reduce(function(l, r) { | |
return l + r; | |
}); | |
return out.toString(2); | |
} | |
intAdd([1,2,3]) | |
// "110" |
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
var initRefs = function(refObj, target) { | |
Object.keys(refObj).forEach(function(key) { | |
var value = refObj[key]; | |
Object.defineProperty(target, key, { | |
// Retain lazy loading of document elements | |
get: function() { | |
delete this[key]; | |
return this[key] = "bananas"; | |
}, | |
configurable: true, |
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(RJSONIO) | |
library(ggplot2) | |
library(reshape2) | |
accel.list <- fromJSON(file.path("~/dev/bocoup", "johnny-five", "accel.json")) | |
accelToDF <- function(x) { | |
sm <- x[["smooth"]] | |
rough <- x[["accel"]] | |
time <- x[["time"]] | |
names(sm) <- c("X", "Y") |