Skip to content

Instantly share code, notes, and snippets.

View Protonk's full-sized avatar
🗯️
Before the hinge

Adam Hyland Protonk

🗯️
Before the hinge
View GitHub Profile
@Protonk
Protonk / johnnyfive.R
Created July 17, 2013 14:18
Useful mostly for forcing sub-second timing in R
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")
@Protonk
Protonk / aes_string_test.R
Last active December 19, 2015 16:49
how does aes_string work?
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)
@Protonk
Protonk / ggsavetest.R
Created July 9, 2013 22:45
both seem to work
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) {
# 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)])
@Protonk
Protonk / reducethis.js
Last active December 19, 2015 02:39
don't think the former is more readable.
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 ];
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]
@Protonk
Protonk / browserasplode.html
Last active December 18, 2015 15:48
The things I do for prototypes... See also http://jsperf.com/prototypes-vs-hiding
<!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>
@Protonk
Protonk / outerMore.R
Last active December 18, 2015 14:49
gist for SO question
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)
@Protonk
Protonk / notquitefusion.js
Last active December 18, 2015 10:29
Adjust the smoothing parameter w/ the sensor slider value.
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
## 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