Skip to content

Instantly share code, notes, and snippets.

View ndevenish's full-sized avatar

Nicholas Devenish ndevenish

View GitHub Profile
@ndevenish
ndevenish / remove_head.py
Created September 6, 2019 15:10
Removes header lines from all python files in the current directory
import os
from pathlib import Path
# Presence of these means we should keep
EXCLUSIONS = {"LIBTBX", "FIXME", "DIALS", "pytest"}
EXCLUDE_FILES = {
"conftest.py",
"util/image_viewer/slip_viewer/frame.py",
"util/installer.py",
@ndevenish
ndevenish / new_dials_command.py
Last active September 12, 2019 11:12
Standard DIALS command_line program boilerplate
"""
dials.new_dials_command
Put a description of your program in the top docstring. This will be
used in the OptionParser to display program help.
"""
from __future__ import absolute_import, division, print_function
import pickle
from __future__ import absolute_import, division, print_function
import glob
import sys
import time
from dials.command_line.find_spots_server import work
FILENAMES = "/path/to/test/files/*.cbf"
@ndevenish
ndevenish / read_yum_repo.py
Last active February 28, 2020 15:34
Read a yum repo and fetch the version and URL of latest package
"""
Read a yum remote repo and get the latest version and url of a package
Prints output to stderr and to stdout:
<version> <url>
"""
import sys
import os
import argparse
import requests
@ndevenish
ndevenish / CMakeLists.txt
Last active April 7, 2020 17:23
Example of failing ispc bool passing
cmake_minimum_required(VERSION 3.8 FATAL_ERROR)
project(ispc_bool)
add_custom_command(OUTPUT booltest.o booltest.h
COMMAND ispc ${CMAKE_SOURCE_DIR}/booltest.ispc -o booltest.o -h booltest.h
DEPENDS booltest.ispc)
add_executable(booltest booltest.cxx booltest.o)
target_include_directories(booltest PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
PRFX=$(HOME)/autobuild/build-Linux-pre-release-gtk3-python
CXXFLAGS=-I$(PRFX)/include/python3.6m/
LDFLAGS=-L$(PRFX)/lib -lpython3.6m -Wl,-rpath=$(PRFX)/lib
all: standalone-python-test
standalone-python-test: standalone-python-test.cc
$(CXX) $^ $(CXXFLAGS) -o $@ $(LDFLAGS)
@ndevenish
ndevenish / bm.cxx
Created April 21, 2020 10:11
Simple benchmark of loop
#include <benchmark/benchmark.h>
#include <scitbx/array_family/accessors/c_grid.h>
#include <scitbx/array_family/tiny_types.h>
#include <scitbx/array_family/versa.h>
using namespace scitbx;
static void BM_loop_inside(benchmark::State& state) {
af::versa<bool, af::c_grid<3> > base(af::c_grid<3>(af::tiny<int, 3>(14, 14, 5)));
@ndevenish
ndevenish / README.md
Last active September 3, 2020 22:09
Example of isort not adhering to configuration in worktree

Basic repo to demonstrate worktree error in isort

clone this. Run isort - no change. Make a worktree:

  $ git worktree add ../second_tree
  $ cat a.py
  import sys

  import c
@ndevenish
ndevenish / git-find-local-commits
Created January 14, 2021 15:00
Find and list commits that are not present upstream
#!/bin/bash
#
# Finds and lists commits that are not present upstream.
#
# Searches in and under the current directory for all .git repositories.
# These are then checked for any local commits that are not present in
# any of the upstream repositories, e.g. commits that have been made
# locally and do not have a known backup anywhere else.
#
# This is helpful to know if e.g. a repository can be safely deleted
@ndevenish
ndevenish / printf_regex.py
Created January 25, 2021 17:06
regex for parsing python printf-style-formatting
re.compile("""
% # Percent
(?:\((?P<mapping>[^)]*)\))? # Mapping key
(?P<flag>[#0\-+ ])? # Conversion Flag
(?P<width>\*|\d+)? # Field width
(?P<precision>\.(?:\*?|\d*))? # Precision
[hlL]? # Unused length modifier
(?P<format>[diouxXeEfFgGcrsa%]) # Conversion type