Skip to content

Instantly share code, notes, and snippets.

@palday
palday / server.R
Created May 6, 2014 01:23
Beta Error
library(shiny)
library(ggplot2)
library(gridExtra)
library(scales)
library(reshape2)
library(zoo)
shinyServer(function(input, output) {
output$distribution <- renderPlot({
@palday
palday / extractbib.py
Last active August 29, 2015 14:01 — forked from tpoisot/extractbib.py
#! /usr/bin/python2
import sys
import codecs
from bibtexparser.bparser import BibTexParser
non_local_fields = ['address',
'annote',
'author',
'booktitle',
@palday
palday / restore_grub_refit.sh
Created October 4, 2012 13:35
Restore a damaged GRUB on Mac using rEFIt
#! /bin/bash
# prep and chroot into the existing system
sudo mkdir -p /mnt/root
sudo mount /dev/sda4 /mnt/root/
sudo mount -t proc none /mnt/root/proc/
sudo mount -o bind /dev /mnt/root/dev
sudo mount --bind /sys /mnt/root/sys
sudo chroot /mnt/root/ /bin/bash
@palday
palday / hg push-all
Created January 29, 2013 13:25
bash-fu to push all mercurial bookmarks
hg bookmarks | awk '{if (NF == 3) print $2; else print $1;}' | xargs -n 1 hg push -f -B
@palday
palday / atlas
Last active December 17, 2015 22:49
ATLAS for R on Debian and Ubuntu
sudo apt-get build-dep atlas
sudo apt-get install build-essential dpkg-dev cdbs devscripts gfortran liblapack-dev liblapack-pic
sudo apt-get source atlas
cd atlas*
sudo fakeroot debian/rules custom
# set n equal to the number of cpus (including virtual HT cpus) minus one
for i in {0..n}; do sudo cpufreq-set -g performance -c$i; done
sudo fakeroot debian/rules custom
sudo apt-get install libatlas-base-dev libatlas-base
sudo dpkg -i libatlas3gf-*.de
@palday
palday / regex.py
Last active December 30, 2015 08:49
Potential regex bug in python -- why isn't "o'clock" part of the match for re.findall()?
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# License: CC-BY-NC-SA 3.0
import re
import codecs
# download kate_chopin_the_awakening_and_other_short_stories.txt
# from Project Gutenberg:
@palday
palday / beyond-cran.R
Last active February 11, 2016 23:20
Useful R packages for mixed effects models
packages.rforge <- c(
"R2admb"
,"lme4.0"
,"glmmADMB"
)
rforge.prefix <- c(
""
,"lme4."
,"coefplot2."
@palday
palday / purge-null
Created January 29, 2013 17:05
A few ways to find and get rid of NULL bites in documents.
tr < file-with-nulls -d '\000' > file-without-nulls
sed 's/\x0//g' file-with-nulls > file-without-nulls
sed 's/\x0/ /g' file-with-nulls > file-without-nulls
grep -P '\000' < file-with-nulls >file-without-nulls
awk '/\000/ { print }'
@palday
palday / talldatasim.jl
Created September 28, 2019 09:50
Tall data test for MixedModels.jl
using Random, DataFrames, MixedModels, PooledArrays
gendata(n::Int, nID::Int, nested=true) = gendata(MersenneTwister(42), n, nID, nested)
function gendata(rng::AbstractRNG, n::Int, nID::Int, nested::Bool)
df = DataFrame(y = zeros(n),
w = rand(rng, n),
x = rand(rng, n),
z = rand(rng, n),
sex = CategoricalArray([randstring(rng,"mf",1) for ii in 1:n]),
group = CategoricalArray(rand(rng, 1:5, n)),
@palday
palday / glmm_disp.jl
Last active February 27, 2020 00:35
Tinkering with GLMMs with dispersion parameters
using MixedModels, RCall, GLM
R"library(lme4)"
R"library(languageR)"
R"lexdec = as.data.frame(lexdec)";
R"lexdec$rt_raw = exp(lexdec$RT)";
R"ldform = rt_raw ~ 1 + Class * NativeLanguage + (1 | Subject) + (1 | Word)";
R"""summary(ldmod <- glmer(ldform, lexdec, family=Gamma(link="identity"),nAGQ=0))"""
lexdec = rcopy(R"lexdec");
ldform = @formula(rt_raw ~ 1 + Class * NativeLanguage + (1 | Subject) + (1 | Word));