Skip to content

Instantly share code, notes, and snippets.

Avatar

Lee Mendelowitz LeeMendelowitz

View GitHub Profile
@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.
@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 / 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 / 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 / error.R
Created Jul 23, 2014
Gist demonstrating an R error
View error.R
# 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 Aug 29, 2015
DC Metro Metrics Data Download
View README.md
@LeeMendelowitz
LeeMendelowitz / README.md
Last active Aug 29, 2015
Take a snapshot of a page with phantom JS
View README.md

To run, download PhantomJS

From the terminal:

phantomjs snapshot.js > output.html
View 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 Aug 29, 2015
Bash one-liners
View bash.md

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 Mar 7, 2015
Time R Function Calls
View time_call.R
############################################################
# 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