Skip to content

Instantly share code, notes, and snippets.

View ashander's full-sized avatar

Jaime Ashander ashander

View GitHub Profile
@jimhester
jimhester / ternary.R
Last active November 9, 2021 19:17
Ternary operator in R
``` r
`?` <- function(x, y) {
y <- substitute(y)
if (!is.call(y) || !identical(as.symbol(":"), y[[1]])) stop("Invalid", call. = FALSE)
eval(call("if", x, y[[2]], y[[3]]))
}
T ? 1
#> Error: Invalid
@mmcclimon
mmcclimon / mklatex
Created November 4, 2013 23:56
Automatically converts Pandoc Markdown to PDF with live preview, via latexmk.
#!/bin/bash
############################
# CONFIG: Change these as necessary
############################
# pandoc
PANDOC_CMD="pandoc"
PANDOC_OPTS="-s --latex-engine=xelatex"
# latexmk
@vjt
vjt / copy-from-time-machine.sh
Last active October 29, 2024 18:08
Copy data from a Time Machine volume mounted on a Linux box.
#!/bin/bash
#
# Copy data from a Time Machine volume mounted on a Linux box.
#
# Usage: copy-from-time-machine.sh <source> <target>
#
# source: the source directory inside a time machine backup
# target: the target directory in which to copy the reconstructed
# directory trees. Created if it does not exists.
#
@ashander
ashander / em3_plants.R
Created July 18, 2011 20:44
Abstracted EM applied to plant growth
data(PlantGrowth)
pg<-subset(PlantGrowth,group!='ctrl')
pg$group=factor(pg$group)
pg1= pg[pg$group=='trt1',]
pg2= pg[pg$group=='trt2',]
hist(pg$weight)
lines(density(pg1$weight), col='blue')
lines(density(pg2$weight), col='red')
@cboettig
cboettig / em2.R
Created June 15, 2011 21:10
abstract expectation maximization algorithm
data(faithful)
attach(faithful)
#Assumes two gaussian populations of eruptions
W = waiting
# Guess of the parameters:
s = c(p=0.5, mu1=50, mu2=90, sigma1=30, sigma2=30)
# EXPECTATION STEP
expectation_step <- function(observed, parameters){