Skip to content

Instantly share code, notes, and snippets.

@petrelharp
petrelharp / pretty.py
Created March 22, 2023 15:45
python implementation of R's "pretty" breaks for histograms
import numpy as np
def pretty(x, n):
"""
Returns a "pretty" set of bin boundaries roughly of size n
that span x. Use, for instance, like:
plt.hist(x, bins=pretty(x, 40))
"""
# see https://github.com/wch/r-source/blob/trunk/src/appl/pretty.c
# NOTE: still suffers from rounding error, so produces values like 10.000001 sometimes
@petrelharp
petrelharp / review-response-commands.tex
Created August 23, 2018 06:23
Respond to reviewers
\usepackage{lineno}
\usepackage{blindtext}
\usepackage{hyperref}
\linenumbers
%%%%% PUT THIS IN HEADER OF FILE
% % Responses to reviews:
% \input{review-response-commands}
@petrelharp
petrelharp / columnize.sh
Created May 3, 2017 07:02
View a file with lots of columns in chunks of N columns
#!/bin/bash
USAGE="Split a file up into chunks of N columns.
Usage:
$0 N file
"
if [ $# -lt 2 ]
then
echo "$USAGE"
@petrelharp
petrelharp / layout_heights.R
Last active February 3, 2017 22:45
Calculate heights of figure regions approprate for using layout() without space between the plots and all figures staying the same height.
layout_heights <- function (k,dl=0,ncol=1) {
# to set up layout without 'dl' lines between plots
# use like layout(1:5,heights=layout_heights(5))
if (k==1) return(1)
layout(matrix(seq_len(k*ncol),ncol=ncol)) # this changes par("csi")
ds <- dl*par("lheight")*par("csi")
eps=par("mai")[c(1,3)]
dh=(par("din")[2]-sum(eps)-(k-1)*ds)/k
return(c(eps[2]+dh+ds/2,rep(dh+ds,k-2),eps[1]+dh+ds/2)/par("din")[2])
}
@petrelharp
petrelharp / make-slideshow.sh
Created February 1, 2016 02:48
make a quick html slideshow of a bunch of images (with pandoc + slidy)
#!/bin/bash
usage="
Make a reveal.js slideshow, e.g. of the contents of directory
$0 (files to put on slides) > (output html document)
for instance,
make-slideshow.sh *png > index.html
"
@petrelharp
petrelharp / get-bibsonomy.sh
Created February 20, 2015 15:21
download all publications from bibsonomy as bibtex (even if there are more than 1000 of them)
#!/bin/bash
URL="http://www.bibsonomy.org/bib/user/peter.ralph?items=1000&bibtex.start="
OUTFILE="peter.ralph-bibsonomy-$(date '+%Y-%m-%d').bib"
TEMPFILE=$(mktemp "get-bib.tmpXXXX")
if [ -e $OUTFILE ]
then
echo "$OUTFILE already exists. Delete it first."
exit 1
@petrelharp
petrelharp / export-inkscape-layers-svg.sh
Created July 9, 2014 10:41
exports named layers in an inkscape svg file to a pdf (via stdout); for example to make animations for a latex presentation
#!/bin/bash
# $1 is the file to extract layers from
# the rest are names of the layers to export
# modified from https://answers.launchpad.net/inkscape/+question/48164
#
# needs xmlstarlet
#
# Notes:
# - doesn't deal with spaces in layer names