Skip to content

Instantly share code, notes, and snippets.

View EoinTravers's full-sized avatar

Eoin Travers EoinTravers

  • Institute of Cognitive Neuroscience, University College London
  • London
View GitHub Profile
@EoinTravers
EoinTravers / dag.R
Last active April 30, 2020 13:05
Testing DAG in brms/rstan
library(brms)
library(rstan)
## Simulate data
bxy = 2
bxz = 3
byz = 4
e = .1
n = 1000
@EoinTravers
EoinTravers / permutation_test.R
Created April 14, 2020 21:43
What happens if we permute after fitting?
library(tidyverse)
# Arguments: Sigma of old predictor, Sigma of new predictor, N cases
compare_methods = function(s0, s1, n){
print(c(s0, s1, n))
y = rnorm(n, 0, 1)
x0 = y + rnorm(n, 0, s0) # Old predictor
x1 = y + rnorm(n, 0, s1) # New predictor to evaluate
m0 = lm(y ~ x0)
@EoinTravers
EoinTravers / psychopy_compound.py
Last active January 31, 2020 11:59
Treat a list of psychopy visual components as a single object.
from psychopy import visual
from psychopy.tools.colorspacetools import hsv2rgb
import numpy as np
win = visual.Window(
size=[800, 600], fullscr=False, screen=0,
gammaErrorPolicy='ignore',
color=(1, 1, 1), colorSpace='rgb', units='height')
class CompoundStim():
from psychopy import visual, event, core
win = visual.Window(size=(600, 400), fullscr=False, units='height',
color=[1.,1.,1.], colorSpace='rgb',
gammaErrorPolicy='ignore')
my_text = visual.TextStim(win=win, color='black',
pos=[.33, 0], height=.05, wrapWidth=.66,
text='')
@EoinTravers
EoinTravers / dplyr.R
Last active August 17, 2018 11:55
dplyr as a CLI. Never use awk again.
#!/usr/bin/env Rscript
# (Don't forget: `chmod +x dplyr`)
# Copyright 2018 Eoin Travers <eoin.travers@gmail.com>
#
# This file is free software: you may copy, redistribute and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation, either version 2 of the License, or (at your
# option) any later version.
#
# This file is distributed in the hope that it will be useful, but
@EoinTravers
EoinTravers / git-diary.py
Created April 5, 2018 10:38
See git commits over the last N days, across all your local repositories. A tool for disorganised people, who are trying to do better.
#!/usr/bin/env python2
"""
Run this script in the folder that contains all of your Git repositories
to see an ordered summary of your commits from the past N days.
Output is tab-delimited, so suggested usage (to see last month's worth of work) is:
cd ~/git_repo_folder/
python git-diary.py 30 | column -ts $'\t'
"""
@EoinTravers
EoinTravers / find_references.py
Created August 17, 2016 15:40
Find and print references from an APA formatted paper.
import re
with open('Paper.txt', 'r') as f:
paper = f.read()
words = paper.split(' ')
refs = []
go_back_by = 5 # Default number of words to show before year.
last = 0
for i in range(len(words)):
@EoinTravers
EoinTravers / d3.legend.js
Last active May 27, 2016 13:02
Dynamic Scatterplot
// d3.legend.js
// (C) 2012 ziggy.jonsson.nyc@gmail.com
// MIT licence
(function() {
d3.legend = function(g) {
g.each(function() {
var g= d3.select(this),
items = {},
svg = d3.select(g.property("nearestViewportElement")),
@EoinTravers
EoinTravers / BetterBibLatexCiteKeyForMarkdown.js
Last active June 18, 2017 02:51 — forked from liob/BibTexCiteKeyForMarkdown.js
A modification of BibTexCiteKeyForMarkdown, exporting citations in BetterBibLatex format (i.e. "@TRAVERS2015")
{
"translatorID": "",
"translatorType": 3,
"label": "Better BibLateX key for Markdown",
"creator": "Eoin Travers. Forked from BibTex key for Markdown, created by liob based on the works of Peter O'Brien, Simon Kornblith and Richard Karnesky",
"target": "bib",
"minVersion": "2.1.9",
"maxVersion": null,
"priority": 200,
"inRepository": true,
@EoinTravers
EoinTravers / bibtexSort.py
Last active August 29, 2015 14:13
Manually sorts bracketed BibTex citations in Pandoc Markdown
#!/usr/bin/env python
# Manually sorts bracketed BibTex citations in Pandoc Markdown.
# pandoc-citeproc will do with automatically for most csl styles,
# but has no option to override the sorting order for specific
# groups of references - for example if you wish to say
# "Smith's (1997; 2001; Aardvark & Smith, 1990) work with ant colonies ..."
# References are sorted by author, then by year, then by title,
# as per the APA system.