Skip to content

Instantly share code, notes, and snippets.

@stuartcampbell
stuartcampbell / toggle-jupyter-code.py
Created July 22, 2017 01:44
Toggle raw code blocks on/off in Jupyter Notebooks
from IPython.display import HTML
HTML('''<script>
code_show=true;
function code_toggle() {
if (code_show){
$('div.input').hide();
} else {
@stuartcampbell
stuartcampbell / bsui
Last active May 8, 2017 00:30
Bluesky Startup Script
#! /bin/bash
if [ -z "$BS_ENV" ]; then
BS_ENV=collection-17Q2.0
fi
source /opt/conda/bin/activate $BS_ENV && ipython --profile=collection
@stuartcampbell
stuartcampbell / rpmmacros
Created November 17, 2016 21:31
My RPM macros file
# This is basically my default RHEL7 one
%_topdir %(echo $HOME)/rpmbuild
%_smp_mflags %( \
[ -z "$RPM_BUILD_NCPUS" ] \\\
&& RPM_BUILD_NCPUS="`/usr/bin/nproc 2>/dev/null || \\\
/usr/bin/getconf _NPROCESSORS_ONLN`"; \\\
if [ "$RPM_BUILD_NCPUS" -gt 16 ]; then \\\
echo "-j16"; \\\
@stuartcampbell
stuartcampbell / RPM_Training.md
Last active July 22, 2017 01:45
Training on building RPMs for NDAV

Packages to install

On RHEL

sudo yum install rpmdevtools rpmbuild rpmlint mock

On Fedora

sudo dnf install rpmdevtools rpmbuild rpmlint mock
@stuartcampbell
stuartcampbell / arch_list_pkgs_using_stdlib.sh
Created December 10, 2015 21:13
List Arch packages to rebuild
#!/bin/bash
while read pkg; do
mapfile -t files < <(pacman -Qlq $pkg | grep -v /$)
grep -Fq libstdc++.so.6 "${files[@]}" <&- 2>/dev/null && echo $pkg
done < <(pacman -Qmq)
@stuartcampbell
stuartcampbell / print_diamond_peaks.py
Last active November 16, 2015 21:28
Print Diamond Peaks
# d-values for diamond
diamond = PoldiCreatePeaksFromCell(SpaceGroup='F d -3 m', Atoms='C 0 0 0', a=3.567925, LatticeSpacingMin=0.4, OutputWorkspace='diamond')
diamond = [float(item['d']) for item in diamond] # extract the d-values
diamond.extend((.4093,.4327,.5379,.5947)) # add in peaks from Ashfia
diamond = list(set(diamond)) # remove duplicates
#diamond=[item for item in diamond if item > binning[0] and item < binning[-1]]
diamond.sort()
print diamond
@stuartcampbell
stuartcampbell / jenkins-clean-slave-workspaces.groovy
Created October 6, 2015 16:20
A jenkins script to clean up workspaces on slaves which have < 10GB of free space
// Check if a slave has < 10 GB of free space, wipe out workspaces if it does
import hudson.model.*;
import hudson.util.*;
import jenkins.model.*;
import hudson.FilePath.FileCallable;
import hudson.slaves.OfflineCause;
import hudson.node_monitors.*;
for (node in Jenkins.instance.nodes) {
@stuartcampbell
stuartcampbell / get_milestones_from_github.py
Created June 3, 2015 15:59
Get a list of milestones from github and deal with paging
def get_milestones_from_github():
print('Getting list of all milestones from Github.')
req = requests.get('https://api.github.com/repos/mantidproject/mantid/milestones',
params={'state': 'all'})
# print(r)
_milestones = {}
for milestone in req.json():
# print(milestone)
_milestones[milestone['title']] = milestone['number']
@stuartcampbell
stuartcampbell / iterate_n_lines.py
Created June 1, 2015 15:36
Iterating over 3 lines at a time (for stdout) in Python
import subprocess
import itertools
# execute some command
since = "--since='{0}-{1}-1'".format(str(year), str(month))
until = "--before='{0}-{1}-{2}'".format(str(year), str(month), str(days_in_month[month-1]))
args = ['git', 'log', '--pretty=format:"%ai %aE"', '--shortstat', since, until]
sub = subprocess.Popen(args, stdout=subprocess.PIPE, close_fds=True, cwd='/path/to/git/repo/clone')
for line1,line2,line3 in itertools.izip_longest(*[sub.stdout]*3):
@stuartcampbell
stuartcampbell / gist:e1c508e93d13814a6c93
Created May 18, 2015 18:52
Issue Migration Planning

Auth as reporter if no key - authenticate as mantid-builder, then append either @ or "First Lastname" from trac

Use correct datetime

Append link to trac at end of description Append trac keywords .....

construct list of labels