Skip to content

Instantly share code, notes, and snippets.

View LeeMendelowitz's full-sized avatar

Lee Mendelowitz LeeMendelowitz

View GitHub Profile
@LeeMendelowitz
LeeMendelowitz / excel_macro
Created April 8, 2016 17:32
Excel Macro for exporting all sheets as csv
Sub ExportSheetsToCSV()
Dim xWs As Worksheet
Dim xcsvFile As String
For Each xWs In Application.ActiveWorkbook.Worksheets
xWs.Copy
xcsvFile = xWs.Name & ".csv"
Application.ActiveWorkbook.SaveAs Filename:=xcsvFile, _
FileFormat:=xlCSV, CreateBackup:=False
Application.ActiveWorkbook.Saved = True
Application.ActiveWorkbook.Close
@LeeMendelowitz
LeeMendelowitz / README
Last active August 29, 2015 14:18
Airport Survey
The Washington Post Aiport Survey
http://www.washingtonpost.com/express/wp/2015/03/31/national-reagan-dca-17-years-later-locals-still-cant-agree-on-the-name-of-the-airport-in-question/?wprss=rss_traffic
@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
@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 / 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 / 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 / README.md
Last active August 29, 2015 14:15
DC Metro Metrics Data Download
@LeeMendelowitz
LeeMendelowitz / DC_Metrorail_Ridership.mac.csv
Last active May 1, 2021 18:12
Replace "^M" carriage return control character with newline
We can make this file beautiful and searchable if this error is corrected: It looks like row 71 should actually have 2 columns, instead of 1 in line 70.
Date,Total 1/1/04,129000 1/2/04,419000 1/3/04,222000 1/4/04,140000 1/5/04,564000 1/6/04,609000 1/7/04,609000 1/8/04,611000 1/9/04,624000 1/10/04,201000 1/11/04,135000 1/12/04,618000 1/13/04,660000 1/14/04,661000 1/15/04,628000 1/16/04,594000 1/17/04,236000 1/18/04,148000 1/19/04,220000 1/20/04,617000 1/21/04,647000 1/22/04,687000 1/23/04,640000 1/24/04,221000 1/25/04,136000 1/26/04,436000 1/27/04,517000 1/28/04,614000 1/29/04,655000 1/30/04,633000 1/31/04,215000 2/1/04,134000 2/2/04,615000 2/3/04,598000 2/4/04,659000 2/5/04,652000 2/6/04,603000 2/7/04,238000 2/8/04,141000 2/9/04,621000 2/10/04,650000 2/11/04,660000 2/12/04,651000 2/13/04,644000 2/14/04,273000 2/15/04,168000 2/16/04,241000 2/17/04,634000 2/18/04,648000 2/19/04,665000 2/20/04,664000 2/21/04,258000 2/22/04,145000 2/23/04,622000 2/24/04,646000 2/25/04,657000 2/26/04,653000 2/27/04,638000 2/28/04,251000 2/29/04,151000 3/1/04,619000 3/2/04,647000 3/3/04,660000 3/4/04,663000 3/5/04,660000 3/6/04,253000 3/7/04,172000 3/8/04,630000 3/9/04,661000 3/10/
@LeeMendelowitz
LeeMendelowitz / rename_files.py
Created October 31, 2014 18:44
Rename files in a directory by removing non-alphanumeric characters that shouldn't be in a filename.
"""
Recurseively rename all files in a directory by replace whitespace with underscores
and erasing all non-('a-zA-Z0-9' or '_' or '-' or '.') characters.
"""
import re, os, shutil, argparse, sys
parser = argparse.ArgumentParser(description = "Rename all files in directory by replacing whitespace with underscores.")
parser.add_argument('directories', metavar="DIR", nargs='*', default = [os.getcwd()], help="directories to walk. Default: CWD")
err = sys.stderr.write
@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.