Skip to content

Instantly share code, notes, and snippets.

library(ggplot2)
yDistribution <- function(x) { return(1/x) }
xSampleDistribution <- function(x) { return((2 ^ x) * 10) }
x <- c()
y <- c()
for (i in 0:8) {
sampleCount <- xSampleDistribution(i)
x <- c(x, rep(i, sampleCount))
@steveharoz
steveharoz / README.md
Created October 24, 2013 21:45 — forked from mbostock/.block
@steveharoz
steveharoz / packages.R
Last active January 2, 2016 18:39
R Setup - run after a new install of R
install.packages('Cairo')
install.packages('data.table')
install.packages('extrafont')
install.packages('ggplot2')
install.packages('lubridate')
install.packages('plyr')
install.packages('dplyr')
install.packages('rjson')
install.packages('stringr')
install.packages('XML')
@steveharoz
steveharoz / gist:8444541
Created January 15, 2014 20:59
A simple small CSV
Year,Make,Model,Length
1997,Ford,E350,2.34
2000,Mercury,Cougar,2.38
@steveharoz
steveharoz / numpy to text.py
Created February 6, 2014 00:41
Convert npy files to tab delimited tables
import struct
import numpy as np
import os
def parseNPY(path, fileJustName):
# load from the file
inputFile = os.path.join(path, fileJustName + ".npy")
matrices = np.load(inputFile)
outputfile = os.path.join(path, fileJustName)
@steveharoz
steveharoz / shuffler.js
Last active August 29, 2015 13:57
Shuffler
// Randomly samples an element from an array and prevents the same element
// from being returned twice unless separated by some number of samples
//
// Constructor parameters
// array: the original array to shuffle and use
// proximityLimit: minimum number of samples between returning the same element (max: array.length/2)
// Methods
// Next(): get the next item
//
// sample use:
@steveharoz
steveharoz / anscombe.R
Last active August 29, 2015 13:57
Melted Anscombe's Quartet
library(reshape2)
library(plyr)
library(ggplot2)
library(grid)
anscombe2 = melt(anscombe, measure.vars=c('x1', 'x2', 'x3', 'x4'), variable.name='number', value.name='x')
anscombe2$number = substring(anscombe2$number, 2)
anscombe2 = adply(anscombe2, 1, function(r){
r['y'] = r[paste0('y', r['number'])]
return(r)
@steveharoz
steveharoz / mandelbrot.R
Last active August 29, 2015 14:02
Mandelbrot image in R
library(ggplot2)
library(grid)
library(doParallel)
library(itertools)
resolution = 1000
iterations = 100
threshold = 10
# image range
@steveharoz
steveharoz / README.md
Last active August 29, 2015 14:04 — forked from mbostock/.block
Colorful Rotating Voronoi

I'm just adding a little color to Mike Bostock's demo.

Mario Klingemann has made some beautiful Voronoi diagrams. This is my attempt to recreate them using D3. To achieve the curved cells, each side of the Voronoi polygon is subdivided into three equal-length segments and then joined using the "basis-closed" line interpolator. There are some discontinuities in the animation when the sides of a polygon approach zero which could likely be avoided by adding a minimum-length threshold to the subdivision.

If you’d like to see other instances of this pattern, Mario describes the algorithm on Flickr.

@steveharoz
steveharoz / multiple.R
Created August 6, 2014 01:53
Multiple plots in R
# Multiple plot function
# from http://www.cookbook-r.com/Graphs/Multiple_graphs_on_one_page_(ggplot2)/
#
# ggplot objects can be passed in ..., or to plotlist (as a list of ggplot objects)
# - cols: Number of columns in layout
# - layout: A matrix specifying the layout. If present, 'cols' is ignored.
#
# If the layout is something like matrix(c(1,2,3,3), nrow=2, byrow=TRUE),
# then plot 1 will go in the upper left, 2 will go in the upper right, and
# 3 will go all the way across the bottom.