Skip to content

Instantly share code, notes, and snippets.

Avatar

Noam Ross noamross

View GitHub Profile
@noamross
noamross / findmins.R
Last active Jan 21, 2016
Ways to find the N minimum value in a vector
View findmins.R
#Looking for a fast way to find the N minimum values in a vector of values. For use in finding nearest neighbors when one already has a (large) distance matrix.
x <- runif(5000)
n <- 3
system.time({ # What I'm using now
for(i in 1:10000) {
a <- sort(x)[1:n]
b <- match(a, x)
}
@noamross
noamross / pandocwithbib
Created May 22, 2012
This is my live preview script for a pandoc file
View pandocwithbib
#!/bin/bash
text=`cat`
echo -E $text | grep -o '@\w*' | sort -n | uniq | sed -n 's/@\(.*\)/\\citation\{\1\}/p' >> ~/smallbib.aux
bibtool --preserve.key.case=on -s -d -x ~/smallbib.aux /Users/noamross/Dropbox/Public/library.bib -o ~/smallbib.bib
echo -E "$text" | pandoc -f markdown -t html --smart --mathjax --bibliography=/Users/noamross/smallbib.bib --csl=/Users/noamross/Dropbox/Public/pd/ecology.csl --template=/Users/noamross/Dropbox/Public/pd/noam.html --base-header-level=2
rm ~/smallbib.*
@noamross
noamross / pjt.md
Created May 22, 2012
pandoc jekyll template
View pjt.md

$if(title)$ title: $title$ $endif$ $if(author)$ author: $author$ $endif$ $if(tags)$ tags: $tags$ $endif$

@noamross
noamross / gist:2832732
Created May 30, 2012
Convert/ google upload script
View gist:2832732
#!/bin/bash
filename="$TM_FILEPATH"
basename="${filename%.*}"
text=`cat `
echo -E $text | grep -o '@\w*' | sort -n | uniq | sed -n 's/@\(.*\)/\\citation\{\1\}/p' >> ~/smallbib.aux
bibtool --preserve.key.case=on -s -d -x ~/smallbib.aux /Users/noamross/Dropbox/Public/library.bib -o ~/smallbib.bib
@noamross
noamross / jsbookmarklet
Created Aug 8, 2012
A bookmarklet that takes you straight to the JSTOR pdf
View jsbookmarklet
javascript:(function() {window.location=window.location.toString().replace(/^http:\/\/www\.jstor\.org\/stable\/.*\/(.*?)$/,'http://www.jstor.org/stable/pdfplus/$1.pdf?acceptTC=true');}())
@noamross
noamross / organize_pdfs
Created Oct 5, 2012
Remove cover pages from PDFs and make links to sync recent additions
View organize_pdfs
#!/bin/bash
# This script is set to run any time a new file is added to my "Papers" folder, using launchd
# 1 - Find papers with JSTOR or Science cover sheets and remove the first page
text1="kind:pdf Your use of the JSTOR archive indicates your acceptance of" #JSTOR papers
text2="kind:pdf is published weekly, except the last week in December" #Science papers
#Add more of these as you find text snippets that identify cover sheets from different publishers. Then add more loops belo
@noamross
noamross / bash.scpt
Created Oct 9, 2012
Run bash script from quicksilver
View bash.scpt
using terms from application "Quicksilver"
on process text _bashcom
do shell script "/bin/bash -ic '" & _bashcom & "'"
end process text
end using terms from
@noamross
noamross / BashGrowl.scpt
Created Oct 16, 2012
BashGrowl: Run Command in Bash and display output as Growl Notificaiton
View BashGrowl.scpt
# Save this in ~/Libary/Application Support/Quicksilver/Actions and relaunch
# Quicksilver. Then just enter a text bash command and activate "BashGrowl" in
# the second pane. I like it for todo.txt and system status calls.
using terms from application "Quicksilver"
on process text theCommand
set _text to do shell script "/bin/bash -ic " & quoted form of theCommand
try
tell application "System Events"
View RbasicFunctions_example.r
#########################################
## R example functions ##
## R. Peek (rapeek@ucdavis.edu) ##
## 11-02-2012 ##
print.functions <- function(){
cat("Rounding etc.:\n",sep="")
cat("---------\n",sep="")
cat("roundup(x, numdigits=0) - correct rounding of .5 etc.\n",sep="")
cat("round.largest(x) - round to largest digit, i.e., 54 -> 50 \n",sep="")
@noamross
noamross / fishlakes.csv
Created Nov 9, 2012
GAMs using mgcv and amphibian presence/absence dataset
View fishlakes.csv
We can make this file beautiful and searchable if this error is corrected: It looks like row 2 should actually have 1 column, instead of 35. in line 1.
#Data provided for purpose of R example only. Not for other use without permission. Contact Rosemary Hartman (rosehartman at gmail dot com.)
lake.ID,name,treatment,shorline,sizehectars,elevation,fish.y.n,fish.breeding,BUBO.breeding,PSRE.breeding,TAGR.present,RACA.present,RACA.breeding,adult.RACA,YOPY.RACA,meta.RACA,RACA.eggs,RACA.larvae,veg.extent,transect.with.veg,ave.0.1m,ave.0.5m,ave.1m,bank.slope,pH,LGWD,SMWD,silt.0.1,silt.total,area.10cm,vegetated.area,near.type,count.RACApops.1K,count.lakes1K,weighted.dist
533,East Boulder,Co,1356.4,11.4,2034.8448,y,y,y,y,n,y,y,6,2,0,0,350,2.28,0.292,0.722916667,5.016666667,10.68333333,0.092475736,8.1,0,0.0417,0.376,0.3472,980.56,3092.59,RACA,5,10,0.8268
534,Mosquito,Co,555.65,2.221,2017,y,y,y,y,n,y,y,2,0,0,0,70,0.425,0.292,0.520833333,4.291666667,14.2875,0.067204288,9,0.25,0.478,0.375,0.6806,289.4,236.15,RACA,0,2,0.52
537,Upper Boulder,Co,530.48,2.009,1927,y,y,y,y,n,y,y,3,5,0,0,240,1.17,0.875,0.46,5.125,14.11666667,0.068711911,8.3,0.04,0,0.875,0.9306,244.02,620.66,FI