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,Total1/1/04,1290001/2/04,4190001/3/04,2220001/4/04,1400001/5/04,5640001/6/04,6090001/7/04,6090001/8/04,6110001/9/04,6240001/10/04,2010001/11/04,1350001/12/04,6180001/13/04,6600001/14/04,6610001/15/04,6280001/16/04,5940001/17/04,2360001/18/04,1480001/19/04,2200001/20/04,6170001/21/04,6470001/22/04,6870001/23/04,6400001/24/04,2210001/25/04,1360001/26/04,4360001/27/04,5170001/28/04,6140001/29/04,6550001/30/04,6330001/31/04,2150002/1/04,1340002/2/04,6150002/3/04,5980002/4/04,6590002/5/04,6520002/6/04,6030002/7/04,2380002/8/04,1410002/9/04,6210002/10/04,6500002/11/04,6600002/12/04,6510002/13/04,6440002/14/04,2730002/15/04,1680002/16/04,2410002/17/04,6340002/18/04,6480002/19/04,6650002/20/04,6640002/21/04,2580002/22/04,1450002/23/04,6220002/24/04,6460002/25/04,6570002/26/04,6530002/27/04,6380002/28/04,2510002/29/04,1510003/1/04,6190003/2/04,6470003/3/04,6600003/4/04,6630003/5/04,6600003/6/04,2530003/7/04,1720003/8/04,6300003/9/04,6610003/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.