Skip to content

Instantly share code, notes, and snippets.

View LeeMendelowitz's full-sized avatar

Lee Mendelowitz LeeMendelowitz

View GitHub Profile
@LeeMendelowitz
LeeMendelowitz / any_all.ipynb
Last active August 29, 2015 13:55
ipython notebook demonstrating Python generators and the any/all functions.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@LeeMendelowitz
LeeMendelowitz / index.html
Created April 29, 2014 12:51
D3 Merging Enter Selection with Update Selection
<!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 / wrap_file_function.py
Last active August 29, 2015 14:00
Wrapping a file function
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 / gist:f6da6480eb87cb55c1ad
Last active August 29, 2015 14:02
Predict.lm not working for matrix data
# 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 / error.R
Created July 23, 2014 22:41
Gist demonstrating an R error
# The question: why does make.plot.1 cause an error?
# make.plot.2 and make.plot.3 work ok.
#
# I'm trying to use ggplot to make a scatter plot with
# with size mapped to the "s" variable in the dataframe.
# When I try to draw circles on top of the scatter plot using geom_path, I get
# errors.
# The plot works if I choose to not map size or not to draw the circles.
@LeeMendelowitz
LeeMendelowitz / README.md
Last active August 29, 2015 14:15
DC Metro Metrics Data Download
@LeeMendelowitz
LeeMendelowitz / README.md
Last active August 29, 2015 14:16
Take a snapshot of a page with phantom JS

To run, download PhantomJS

From the terminal:

phantomjs snapshot.js > output.html
@LeeMendelowitz
LeeMendelowitz / Knitr_Latex_Template
Created February 25, 2015 19:42
Knitr Latex Template
\documentclass[12pt]{article}
\usepackage[sc]{mathpazo}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage[top=1in, bottom=1in, left=1.5in, right = 1.5in, marginparwidth=0.0in, marginparsep=0.25in]{geometry}
% \geometry{verbose,tmargin=0.75in,bmargin=0.75in,lmargin=0.75in,rmargin=0.75in} %Commented out in favor of the marginnote settings
\setcounter{secnumdepth}{2}
@LeeMendelowitz
LeeMendelowitz / bash.md
Last active August 29, 2015 14:16
Bash one-liners

find with redirected stdout

find . -name '*.aln' | xargs -I {} sh -c 'cut -f 1 "$1" > "$1.cut"' -- {}

This will find all files *.aln and then output the first column to *.aln.cut.

get filetypes

@LeeMendelowitz
LeeMendelowitz / time_call.R
Created March 7, 2015 18:14
Time R Function Calls
############################################################
# Time a call. Execution time is printed. Return the value of wrapped call
time.call <- function(expr) {
start.time <- proc.time()
ret = evalq(expr)
end.time <- proc.time()
print(end.time - start.time)
ret