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
library(lme4)
library(lmerTest)
library(dplyr)
data = read.table('~/Desktop/sof_data.csv')
# or
#data = read.table('clipboard')
# Analysing all data
# t test
@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.
@EoinTravers
EoinTravers / html_toggle
Created December 4, 2013 11:53
html_toggle template for ipython nbconvert
{%- extends 'html_basic.tpl' -%}
{%- block header -%}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>{{resources['metadata']['name']}}</title>

This is a pretty ugly hack, and I apologize to everyone concerned, but I've got around this problem like so:

grouped = data.groupby(['code', 'acc'])
means = grouped.mean()
means['nx'] = [group.nx.mean() for name, group in grouped]
means['ny'] = [group.ny.mean() for name, group in grouped]

group1_correct = means.xs('group1').xs(True)
group1_correct['nx'] # Can only be indexed this way
@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 / 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 / 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 / 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 / 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
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='')