Skip to content

Instantly share code, notes, and snippets.

View jrnold's full-sized avatar

Jeffrey Arnold jrnold

View GitHub Profile
@jrnold
jrnold / yasnippet-autoinsert-example.el
Created November 13, 2010 19:54
Use yasnippet templates with aut-insert-mode in emacs
(defun yas/expand-by-uuid (mode uuid)
"Exapnd snippet template in MODE by its UUID"
(yas/expand-snippet
(yas/template-content
(yas/get-template-by-uuid mode uuid))))
;; Yasnippet templates used in auto-insert mode
(require 'autoinsert)
(auto-insert-mode)
(setq auto-insert-query nil)
%% Note, the definitions of TeX and LaTeX are in texnames.sty file
%% Code from texnames.sty
\ifx\sc\undefined
\def\sc{%
% If there is no \scriptfont for the current family, use a fixed
% font. What more can we do?
\expandafter\ifx\the\scriptfont\fam\nullfont
\font\temp = cmr7 \temp
\else
@jrnold
jrnold / gist:1236095
Created September 22, 2011 21:20
Run Amelia in parallel
library("Amelia")
library("foreach")
## or backend of choice
library("doMC")
registerDoMC()
ameliapar <- function(x, m=5, p2s=0, ...) {
impdata <- foreach (i = 1:m,
.combine = "c",
.packages="Amelia") %dopar% {
@jrnold
jrnold / protoGibbs.R
Created October 2, 2011 13:19
A general gibbs sampler object using the proto R package.
library("proto")
library("mvtnorm")
##' Gibbs sampler
##'
##' General Gibbs sampler object.
##'
##' TODO
GibbsSampler <- proto(expr = {
@jrnold
jrnold / gist:2373386
Created April 13, 2012 03:24
tikz line example
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[black] (-3,0) -- (4,0);
\draw (-1.5, -0.1) -- (-1.5, 0.1) node[above] {FOOO};
\foreach \x in {-2,-1,0,1,2,3}
\draw (\x,0) -- (\x,-0.1) node[below] {$\x$};
@jrnold
jrnold / foo.rst
Created April 23, 2012 06:00
knitr rendering for restructured text / sphinx
roptions

dev='png',highlight=FALSE

print(2 + 2)

cat("hello")

@jrnold
jrnold / syntax_example.R
Created August 11, 2012 17:25
R language example for syntax highlighting tests
#!/usr/bin/env Rscript
### Example R script for syntax highlighting
# This is also a comment
## Valid names
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUV0123456789._a <- NULL
.foo_ <- NULL
._foo <- NULL
@jrnold
jrnold / foo.cpp
Created August 17, 2012 08:22
compiling stan model as shared object
// Code generated by Stan version 1.0
#include <stan/model/model_header.hpp>
namespace foo_namespace {
using std::vector;
using std::string;
using std::stringstream;
using stan::agrad::var;
@jrnold
jrnold / gist:3741130
Created September 18, 2012 03:48
S4 defintiions of mcmc and mcmc.list
##' Redefine mcmc as S4 class
setClass("mcmc", contains="matrix",
representation(start="numeric",
end="numeric",
thin="numeric"))
setOldClass("mcmc", S4Class="mcmc")
setClass("mcmc.list", contains="list",
validity = function(object) {
if (length(object@.Data) == 0) {
@jrnold
jrnold / mcmcseGenerics.R
Created September 25, 2012 23:38
Generic functions for mcmcse package
## Monte Carlo Standard Error
## @export
setGeneric("mcse", function(x, ...) {
ret <- mcmcse::mcse(x, ...)
ifelse(is.na(ret), c(est=NA, se=NA), unlist(ret))
})
setMethod("mcse", "matrix", function(x, ...) {
t(apply(x, 2, mcse, ...))
})