Skip to content

Instantly share code, notes, and snippets.

@steveharoz
steveharoz / Welcome to dates.R
Last active January 16, 2016 23:57
Learning how to make a sequence along a time axes
mydate1 = as.Date("2000-01-01")
mydate2 = as.Date("2000-03-01")
# EASY: sequence with every other int
seq(1, 60, by=2)
# HARD: sequence with every other day
seq(mydate1, mydate2, by=???) # day?
# pretend you're new to R
# you don't know about lubridate or POSIX
@steveharoz
steveharoz / ggplot ordering.R
Last active March 4, 2016 22:33
ordering in ggplot2
library(ggplot2)
data = data.frame(
a = rep(LETTERS[24:26], 3),
b = 1:9,
c = rep(LETTERS[1:3], each=3)
)
# uncomment to set facet order by refactoring the data
#data$a = factor(data$a, levels=c('Y', 'X', 'Z'))
@steveharoz
steveharoz / context sensitive.js
Created June 8, 2016 04:36
Weird context sensitivity in javascript es6
a = {number: 1}; // works
a = [1, 2, 3].map( n => 1 ); // works
a = [1, 2, 3].map( n => {number: 1} ); // unexpected ':'
a = [1, 2, 3].map( n => {return {number: 1};} ); // works
@steveharoz
steveharoz / README.md
Created June 27, 2016 22:55
request success despite failure

Run this file on your local machine without a web server

It should fail because (a) chrome doesn't allow requests on a local machine (b) submit.php doesn't exist (or shouldn't in this directory)

But it claims to succeed!

<!DOCTYPE html>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v4.0.0-rc.2.min.js"></script>
<script>
function callback1(arg1) {
console.log("COMPLETED. arg1:" + arg1);
console.log(arg1)
}
function callback2(arg1, arg2) {
@steveharoz
steveharoz / psychometric function target
Created August 19, 2016 15:03
Psychometric function target - what y value on a psychometric function will a staircase hit
downRule = 3 # How many correct answers in a row do you need to drop down a level?
upRule = 1 # How many incorrect answers in a row do you need to step up a level?
stepSizeDown = .25 # If the current staircase value is 1, how much do you subtract to get to the next level down?
stepSizeUp = 1 / (1 - stepSizeDown) - 1 # This assumes that staircase values are fixed
ratio = stepSizeUp / (stepSizeDown + stepSizeUp)
exponent = downRule / upRule
inverseExponent = 1 / exponent # because we're solving in reverse
@steveharoz
steveharoz / index.html
Last active September 3, 2016 09:53 — forked from d3noob/.block
Sankey diagram from formatted JSON
<!DOCTYPE html>
<meta charset="utf-8">
<title>SANKEY Experiment</title>
<style>
.node rect {
cursor: move;
fill-opacity: .9;
shape-rendering: crispEdges;
}
@steveharoz
steveharoz / .block
Last active September 19, 2016 15:09 — forked from mbostock/.block
Gradient Along Stroke
license: gpl-3.0
@steveharoz
steveharoz / .block
Last active January 13, 2022 22:59 — forked from mbostock/.block
Force-Directed Graph
license: gpl-3.0
height: 600
@steveharoz
steveharoz / .block
Last active April 17, 2025 15:11 — forked from mbostock/.block
d3-force testing ground
license: gpl-3.0
height: 1030
scrolling: yes