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") |
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
testme <- function(d, x, y) { | |
require(ggplot2) | |
plot.out <- ggplot(d) + geom_point(aes_string(x = "Bottom", y = y)) | |
return(plot.out) | |
} | |
test.df <- data.frame(Bottom = 1:10, Left = 10:1) | |
plot.test <- testme(test.df, x = NULL, "Left") | |
print(plot.test) |
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
test <- data.frame(x = 1:10, y = 10:1) | |
ggwrap <- function(data) { | |
require(ggplot2) | |
test.plot <- ggplot(test) + geom_point(aes(x = x, y = y)) | |
ggsave(filename = "~/Desktop/Oliver.png", plot = test.plot) | |
} | |
## or | |
ggwrapOuter <- function(data) { |
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
# more sensible example, perhaps | |
foo <- c(1:10, 50:25, 100:202, -12:-4) | |
bar <- c(8:40, 12:25, 101) | |
data.frame(From = foo, To = foo[match(foo, bar)]) |
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 whatever = ["foo", "bar"]; | |
var axes = ["x", "y"]; | |
// reducify | |
function reduceMe(types, axes) { | |
var container = {}; | |
var inner = {}; | |
types.reduce(function(prev, curr) { | |
container[ curr ] = axes.reduce(function(prev, curr) { | |
inner[ curr ] = [ 0 ]; |
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 A = new Int32Array([1, 0, 0, 0, 1, 0, 0, NaN, 1]); | |
var B = new Float32Array([1, 0, 0, 0, 1, 0, 0, NaN, 1]); | |
var C = new Float32Array([1, 0, 0, 0, 1, Infinity, NaN, undefined, null]); | |
console.log(A); | |
// [1, 0, 0, 0, 1, 0, 0, 0, 1] | |
console.log(B); | |
// [1, 0, 0, 0, 1, 0, 0, NaN, 1] |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Prototypes Asplode</title> | |
</head> | |
<body> | |
<button name='button' class='proto' id='Foo'>Click me...for revealed chaos!</button> | |
<button name='button' class='proto' id='Bar'>Click me...for proto-chaos!</button> | |
<button name='button' class='proto' id='Baz'>Click me...for naive chaos!</button> | |
<script type='text/javascript' src='protowindow.js'></script> |
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
outerMore <- function(..., FUN) { | |
arg.list <- list(...) | |
arg.len <- length(arg.list) | |
if(arg.len < 2) { | |
stop("Not enough arguments to outer()") | |
} | |
if(arg.len == 2) { | |
out <- outer(arg.list[[1]], arg.list[[2]], FUN = FUN) | |
dim(out) <- NULL | |
return(out) |
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 five = require("./lib/johnny-five.js"), | |
board, slider; | |
board = new five.Board(); | |
board.on("ready", function() { | |
var accel = new five.Accelerometer({ | |
pins: [ "I0", "I1" ], | |
freq: 100 |
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
## Count name occurence across years. | |
## see help('byNameCount') for more info | |
us.prop <- byNameCount(usnames) | |
head(us.prop) | |
# Name years.appearing counts.female counts.male prop.male | |
# 1 Aaban 4 0 31 1 | |
# 2 Aabha 1 7 0 0 | |
# 3 Aabid 1 0 5 1 |