Skip to content

Instantly share code, notes, and snippets.

Avatar

Lee Mendelowitz LeeMendelowitz

View GitHub Profile
@LeeMendelowitz
LeeMendelowitz / gist:f6da6480eb87cb55c1ad
Last active Aug 29, 2015
Predict.lm not working for matrix data
View gist:f6da6480eb87cb55c1ad
# Make a dataset where Y is cubic in X, plus noise:
n <- 1000
x <- runif(n)
x <- sort(x)
eps <- rnorm(n)
beta <- c(1, 2, 3)
X <- poly(x, 3, raw = TRUE)
y <- X %*% beta + eps
# Fit the data
@LeeMendelowitz
LeeMendelowitz / wrap_file_function.py
Last active Aug 29, 2015
Wrapping a file function
View wrap_file_function.py
class wrap_file_function(object):
"""
Wrap a function which takes a file or a str as it's first argument.
If a str is provided, replace the first argument of the wrapped function
with a file handle, and close the file afterwards
Example:
@wrap_file_function('w')
def write_hi(f):
@LeeMendelowitz
LeeMendelowitz / index.html
Created Apr 29, 2014
D3 Merging Enter Selection with Update Selection
View index.html
<!DOCTYPE html>
<html>
<head>
<title>Playing with Enter and Update</title>
<script src="http://d3js.org/d3.v3.min.js"></script>
<style>
p {
color: black;
}
@LeeMendelowitz
LeeMendelowitz / README.md
Last active Dec 6, 2018
D3 Dynamic Table with Nested Data
View README.md

This script is another demonstration of the update, enter, and exit selections in D3. The script also makes use of key functions to bind data to each row, and transitions to animate opacity and delay the removal of rows. This script demonstrates nested data, where an array of values is bounded to each row (<tr>), and then a single value is bound to each cell (<td>) element in the row.

Each row of the table has a unique letter key, which is displayed as the first cell. The remainder of the row is an array of random digits. At each iteration:

  1. A new set of letter keys is randomly selected from the alphabet.
  2. For each letter in the set, a new row with random data will be inserted in the table if the letter is not already in the table.
  3. Any row in the table with a key which is not in the new set is removed.
  4. The number of columns in the table is randomly adjusted. If the new number of columns is larger than the current table, random data is appended to each row. Otherwise, cel
@LeeMendelowitz
LeeMendelowitz / any_all.ipynb
Last active Aug 29, 2015
ipython notebook demonstrating Python generators and the any/all functions.
View any_all.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View lcps.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.