Skip to content

Instantly share code, notes, and snippets.

View casallas's full-sized avatar

Juan Sebastián Casallas casallas

  • Iowa State University, Arts et Métiers ParisTech
  • Chalon-sur-Saône, France
View GitHub Profile
@casallas
casallas / svn2git.md
Last active August 29, 2015 13:56
Using svn2git
  1. Get authors:

svn log --quiet http://path/to/root/of/project | grep -E "r[0-9]+ \| .+ \|" | cut -d'|' -f2 | sed 's/^ //' | sort | uniq

  1. Make an authors.txt file containing, e.g.,
author = Name LastName <auth@mail.com>
author2 = Name2 LastName2 <auth2@mail.com>
@casallas
casallas / knitr-include-child.Rnw
Created May 13, 2014 23:30
knitr include (not input) child
This chunk below is from the child document.
<<set-parent, echo=FALSE, cache=FALSE>>=
if(!exists("master_mode")) master_mode <- F
if(!master_mode)
knitr::set_parent('knitr-include.Rnw')
@
<<test-child, out.width='2in', fig.show='asis'>>=
1+1
@casallas
casallas / wilcox_nont.r
Created May 18, 2014 09:20
Non-transitive dice and the wilcoxon test
# Based on http://notstatschat.tumblr.com/post/63237480043/rock-paper-scissors-wilcoxon-test
d1 <- c(4, 4, 4, 4, 0, 0)
d2 <- c(3, 3, 3, 3, 3, 3)
d3 <- c(6, 6, 2, 2, 2, 2)
d4 <- c(5, 5, 5, 1, 1, 1)
wilcox.test(d1, d2, alternative="greater")
wilcox.test(d2, d3, alternative="greater")
wilcox.test(d3, d4, alternative="greater")
wilcox.test(d4, d1, alternative="greater")
@casallas
casallas / check.packages.R
Created July 23, 2014 05:14
Check installed R packages
res <- apply(installed.packages(), 1, function(ip){require(package=ip["Package"], lib.loc=ip["LibPath"], character.only=T)})
res[res==F]
@casallas
casallas / ezpolar_ggplot2.md
Last active August 29, 2015 14:07
ezpolar in ggplot2

Mimicing Matlab's ezpolar in R, with ggplot2

In MATLAB/octave plotting stuff in polar coordinates is really easy, e.g. the cardioid $r(\theta) = 1+cos(\theta)$, $0 &lt; \theta &lt; 2\pi$ is as simple as:

ezpolar('1+cos(t)',[0,2*pi])

In ggplot, more verbose is needed

@casallas
casallas / pipe_qplot_benchmark.R
Created December 31, 2014 04:06
A small benchmark to compare the 'ans' and 'with' forms of 'freduce'
library(microbenchmark) # microbenchmark
library(pryr) # mem_used
library(ggplot2) # qplot
devtools::dev_mode(T)
benchmark_pipe_qplot <- function(x){
library(magrittr)
print(mem_used())
cat("------\n")
@casallas
casallas / rexex_ex.md
Last active August 29, 2015 14:13
ag/ack/atom regex example

Suppose you want to change the following

original new
a \ttimes b -> =
a \\ttimes b -> =
a_2 \ttimes b -> a_2 \btimes b
a_2 \\ttimes b -> a_2 \\btimes b
a_{2} \ttimes b -> a_{2} \btimes b
a_{2} \\ttimes b -&gt; a_{2} \\btimes b
@casallas
casallas / iipp.R
Last active August 29, 2015 14:13
||++ for R
# return a if a is defined and not null, otherwise return b
`%|%` <- function(a, b){
try({
if(!is.null(eval(substitute(a))))
return(a)
}, silent=TRUE);
b
}
# assign b to a if a is undefined or null, compare to ruby's ||=
@casallas
casallas / under_subs.md
Created March 24, 2015 21:18
Underlined subscript LaTeX

For some reason the following generates some errors in LaTeX (even though the output is correct)

$S_\underline{0}$

My solution was to enclose the underline statement within \mathrm

$S_\mathrm{\underline{0}}$
@casallas
casallas / det_test_font_tex.md
Created March 25, 2015 15:16
Detecting and testing font in LaTeX