Skip to content

Instantly share code, notes, and snippets.

View clbarnes's full-sized avatar

Chris Barnes clbarnes

View GitHub Profile
@clbarnes
clbarnes / reverse_beta.py
Last active March 25, 2016 22:08
Get the alpha and beta parameters of the beta distribution from a mean and variance
def get_beta_params(mu, var):
"""
From this answer http://stats.stackexchange.com/a/12239/101211
"""
alpha = mu**2 * ( ((1-mu)/var) - 1/mu )
beta = alpha * (1/mu - 1)
assert alpha > 0 and beta > 0
return alpha, beta
@clbarnes
clbarnes / git_eject.py
Created April 5, 2016 19:47
Back up all git repos below a given directory to a (large) USB stick. Will break with git-LFS, I think.
#!/usr/bin/env python
from subprocess import call
import os
import argparse
parser = argparse.ArgumentParser(description='Do an emergency backup of all git repositories.')
parser.add_argument('output_dir', help='Root directory whither to back up the git repos.')
parser.add_argument('--input', '-i', nargs='+', default=('.',), help='Root directory(s) within which to look for git \
repos.')
parser.add_argument('--git', '-g', default='git', help='Path to git binary')
@clbarnes
clbarnes / install_pycharm
Last active April 6, 2016 20:06
Requires sudo. Change username where indicated. Usage is `install_pycharm path/to/pycharm_archive.tar.gz`.
#!/bin/bash
set -e
USERNAME = "cbarnes" # change this
COMPRESSION = ".tar.gz"
STARTING_DIR = pwd
ARCHIVE_DIR = dirname $1
FOLDER_NAME = basename $1 $COMPRESSION
@clbarnes
clbarnes / contents.py
Created April 15, 2016 18:37
Python 3 script for recursively creating contents pages for directories containing markdown (.md) files
import os
import argparse
parser = argparse.ArgumentParser(description='Generate contents pages for the given directory and all subdirectories.')
parser.add_argument('root', nargs='+', default=['.'], help='Target directory.')
parser.add_argument('--dryrun', '-d', action='store_true', help='Do not actually write the contents files.')
args = parser.parse_args()
@clbarnes
clbarnes / full_mapping.csv
Last active May 12, 2016 22:02
C. elegans cell names including numbers sometimes do and sometimes don't have 0s in the middle for sorting purposes. Interconvert them with these functions.
ADAL ADAL
ADAR ADAR
ADEL ADEL
ADER ADER
ADFL ADFL
ADFR ADFR
ADLL ADLL
ADLR ADLR
AFDL AFDL
AFDR AFDR
@clbarnes
clbarnes / neuron_install.md
Last active February 29, 2024 13:11
These instructions are for installing NEURON and NetPyNE with linux and a conda environment.

Install instructions

These instructions are for installing NEURON and NetPyNE with linux and a conda environment.

Create a neuron directory in your home directory, put the gzipped source files in it, and expand them.

cd $HOME
mkdir neuron
mv iv-mm.tar.gz neuron
import os
import csv
FILE_EXT = '.dat'
SEARCH_TERMS = ('one line to search for \n', 'another line to search for\n')
file_list = [f for f in os.listdir() if f.endswith(FILE_EXT)]
output = [['file name', 'search term 1 exists', 'search term 2 exists']]
@clbarnes
clbarnes / ode_constraints.py
Last active May 14, 2021 12:33
Decorator to wrap a derivative function in order to constrain the output of an ODE solver
"""
Note that this constrains the dependent variable from going *any further* past the constraints.
The ODE will still treat it as if it were at the value of the constraint,
and with a small step size any problems should be minimal,
but you may still have slightly out-of-range numbers in your solution.
"""
import numpy as np
from functools import wraps
@clbarnes
clbarnes / source.sh
Created October 6, 2016 19:09
File to add to /etc/bash_completion.d to allow bash to autcomplete conda environments after `source activate`
#!/bin/bash
_complete_source_activate_conda(){
if [ ${COMP_WORDS[COMP_CWORD-1]} != "activate" ]
then
return 0
fi
local cur=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=($(ls ~/anaconda3/envs | xargs -I dirs bash -c "compgen -W dirs $cur"))
return 0
}
@clbarnes
clbarnes / environment.yml
Created November 15, 2016 18:57
CATMAID environment.yml
name: catmaid
dependencies:
- backports=1.0=py27_0
- boost=1.60.0=py27_0
- decorator=4.0.10=py27_0
- enum34=1.1.6=py27_0
- get_terminal_size=1.0.0=py27_0
- gevent=1.1.2=py27_0
- greenlet=0.4.10=py27_0
- icu=54.1=0