Skip to content

Instantly share code, notes, and snippets.

Avatar

Will Furnass willfurnass

View GitHub Profile
@willfurnass
willfurnass / shear_stress.m
Last active Aug 29, 2015
Calculate steady-state boundary shear stress in pressurised water pipes
View shear_stress.m
function tau_a = shear_stress(D, Q, k_s, T, den)
%{ Hydraulic shear stress at pipe wall (in Pa).
%
% Params:
% D -- internal diameter (m)
% Q -- flow (m^3s^-1)
% k_s -- roughness height (m)
% T -- temperature; defaults to 10degC)
% den -- density defaults to 1000kg/m^3
%
@willfurnass
willfurnass / zotero_shorttitle_as_bibtex_key.patch
Created Feb 20, 2016
Patch Zotero's translators/BibTeX.js so non-empty shortTitle values used as BibTeX key when exporting Zotero library.
View zotero_shorttitle_as_bibtex_key.patch
--- BibTeX.js.orig 2015-07-03 07:18:37.000000000 +0100
+++ BibTeX.js 2015-08-09 14:21:08.779706944 +0100
@@ -1176,7 +1176,11 @@
if(!type) type = "misc";
// create a unique citation key
- var citekey = buildCiteKey(item, citekeys);
+ if (item.shortTitle==''){
+ var citekey = buildCiteKey(item, citekeys);
+ } else {
@willfurnass
willfurnass / bng.py
Created Mar 1, 2016
Convert alphanumeric British National Grid references to/from easting northing integer pairs
View bng.py
import numpy as np
myriad_codes = np.array((
None, None, None, None, "HP", None, None,
None, None, None, "HT", "HU", None, None,
None, "HW", "HX", "HY", "HZ", None, None,
"NA", "NB", "NC", "ND", None, None, None,
"NF", "NG", "NH", "NJ", "NK", None, None,
"NL", "NM", "NN", "NO", None, None, None,
None, "NR", "NS", "NT", "NU", None, None,
@willfurnass
willfurnass / ruffus_simple_test.py
Created Jan 11, 2017
Simple test of the Ruffus workflow manager
View ruffus_simple_test.py
#!/usr/bin/env python
from __future__ import print_function
from ruffus import transform, suffix, pipeline_run
# A test of using Ruffus to locally run a very simple pipeline comprised of
# tasks defined as Python functions
# Can run this from a conda environnment created using
# conda create -n drmaatest -c bioconda python=2.7 ruffus drmaa
View ruffus_simple_drmaa_test.py
#!/usr/bin/env python
# A test of whether Ruffus can be used to submit jobs to a cluster using the
# DRMAA API, sharing the DRMAA session between threads to allow multiple jobs to
# be submitted at once without burdening the head node with multiple DRMAA
# sessions.
# Can run this from a conda environnment created using
# conda create -n drmaatest -c bioconda python=2.7 ruffus drmaa
View tmux_cheatsheet.md

tmux tips

Default prefix: <ctrl>b

Session management

  • tmux new -s session_name - creates a new tmux session named session_name
  • tmux a - attach to first available session
  • tmux attach -t session_name - attaches to an existing tmux session named session_name
  • tmux switch -t session_name - switches to an existing session named session_name
@willfurnass
willfurnass / README.md
Created Jun 1, 2017
Separating Reveal.js from your presentation content using git subrepo
View README.md

Initialise a git repository:

cd somedir
git init

Install git subrepo if you haven't done so already:

https://github.com/ingydotnet/git-subrepo#installation
@willfurnass
willfurnass / jsv_crlf_rejecter.tcl
Created Apr 9, 2018
Grid Engine JSV snippet to reject jobs containing CRLF
View jsv_crlf_rejecter.tcl
#!/usr/bin/tclsh
set sge_root $env(SGE_ROOT)
source "$sge_root/util/resources/jsv/jsv_include.tcl"
proc jsv_on_start {} {
jsv_send_env
}
proc lexists name {
@willfurnass
willfurnass / export_data.py
Created Feb 20, 2019
Python snippet to export data to a file in a particular format
View export_data.py
import os
from typing import Dict
import numpy as np
def export_data(data: Dict[np.ndarray],
filename: str,
cols_per_line: int = 8) -> None:
"""Export dictionary of 1d float arrays to a file.
@willfurnass
willfurnass / python_debug_env.md
Last active Aug 25, 2020
Setting up a Python debug environment to investigate a segfaulting Python C extension
View python_debug_env.md

Notes on setting up a Python debug environment

Used to investigate a segfault in a Python C extension within a Python package.

  1. Install debug Python build using pyenv then check is available for use:

    pyenv install -g 3.8.5
    pyenv versions