Skip to content

Instantly share code, notes, and snippets.

View clbarnes's full-sized avatar

Chris Barnes clbarnes

View GitHub Profile
@clbarnes
clbarnes / autopep8.sh
Created November 3, 2015 16:26
Line for autopep8
autopep8 path/to/project/directory --recursive --in-place --pep8-passes 2000 --verbose
@clbarnes
clbarnes / remove_self_loops.m
Created November 13, 2015 16:04
A proposed function for the Brain Connectivity Toolbox to remove self-loops from an input matrix
function W_ = remove_self_loops(W)
% REMOVE_SELF_LOOPS Removal of self-self connections from an input
% matrix
%
% W_ = remove_self_loops(W);
%
% Return a copy of the input matrix with all self-self connections
% removed (i.e. the primary diagonal set to all 0s).
%
% Inputs: W binary or weighted connectivity matrix
@clbarnes
clbarnes / arbitrary_integration.py
Last active January 20, 2016 22:36
Do you have a multivariate function which you want to integrate? Do you have a blasé attitude towards executing lambdas instantiated from eval strings? Well then look no further!
from inspect import signature
from scipy.integrate import quad
def get_fn_str(fn, lims=(0, 1), existing_string=None, arg_count=0):
"""
Recursively generate a string which, when evaluated, will integrate an arbitrary function over all of its variables within the given limits.
"""
if existing_string is None:
return get_fn_str(fn, lims=lims, existing_string="quad({{}}, {}, {})[0]".format(lims[0], lims[1]),
@clbarnes
clbarnes / timestamped_zip.sh
Created January 30, 2016 21:55
Bash script for making a timestamped zip backup of everything in the current directory
#!/bin/bash
timestamp=$(date +"%Y-%m-%d_%H:%M:%S")
zip -r "backup_$timestamp.zip" *
from problog.tasks import sample
from problog.program import PrologString
modeltext = """
my_uniform(0,10)::a.
0.5::b.
c :- value(a, A), A >= 3; b.
query(a).
query(b).
query(c).
@clbarnes
clbarnes / reinstall_problog.sh
Last active February 24, 2016 21:24
Uninstall and reinstall ProbLog's binaries from a particular conda environment
#!/bin/bash
set -e
STARTING_ENV="$CONDA_DEFAULT_ENV"
if test -z "$1" ; then
TARGET_ENV="$1"
source activate TARGET_ENV
else
@clbarnes
clbarnes / elegans_neuron_classes.py
Created March 8, 2016 19:09
Takes a neuron class in C. elegans and returns a list of neurons belonging to that class
class NodeClassifier:
def __init__(self):
self._nodes = set(NODES)
self._subs = dict(ALLOWED_SUBSTITUTIONS)
def __getitem__(self, key):
if key in self._nodes:
return [key]
ret = []
@clbarnes
clbarnes / module.py
Created March 10, 2016 16:54
Incorporating non-python files (config, data etc.) when installing your python library with setuptools
"""
And here's the easiest way to get that file in modules installed in this way.
"""
import os
import sys
DATAFILE_PATH = os.path.abspath('path_to_something')
@clbarnes
clbarnes / cycle_gen.py
Created March 10, 2016 16:56
Loop through a sequence forever.
def cycle_gen(sequence):
while True:
yield from sequence
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
1
2
3