Skip to content

Instantly share code, notes, and snippets.

View ndevenish's full-sized avatar

Nicholas Devenish ndevenish

View GitHub Profile

Example showing SwiftBond not connecting to an NSButton properly

@ndevenish
ndevenish / setup.py
Created June 22, 2016 16:16
Replacement setup.py for py3exiv2, that allows building on OSX
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import sys
import os
import glob
import subprocess
from setuptools import setup, find_packages, Extension
#include <Servo.h>
#define PIN_X_STEP 4
#define PIN_X_DIR 7
#define PIN_Y_STEP 6
#define PIN_Y_DIR 5
#define PIN_Z 2
#define PIN_ENABLE 3
Servo zServo;
@ndevenish
ndevenish / print_stacktrace.c
Last active January 19, 2018 11:50
Print a python stacktrace from a c method
#include <iostream>
#include <Python.h>
inline void print_stacktrace()
{
std::cout << "==== Python Stacktrace ======================================" << std::endl;
PyObject *module_name, *pyth_module, *pyth_func;
// Import the python traceback module
module_name = PyString_FromString("traceback");
pyth_module = PyImport_Import(module_name);
@ndevenish
ndevenish / read_libtbx_env.py
Created August 1, 2017 22:24
Read a libtbx env_config file into a dictionary for serialization
#!/usr/bin/env python
import pickle
from pprint import pprint
import yaml
from libtbx.env_config import environment, module, build_options
from libtbx.path import relocatable_path, absolute_path
def dict_from_module(m, include_name=True):
@ndevenish
ndevenish / read_env.py
Last active August 17, 2017 14:05
Read a libtbx environment file and dump it's structure to the terminal
#!/usr/bin/env python3
"""
Reads a libtbx_env file and dumps the entire contents.
Some structures e.g. module dictionaries refer to the same object in multiple
places. These will be dumped multiple times. Anything that refers back to a
previous level will show as "__selfreference__". Relocatable paths are just
shown as the regular, joined path (from inspection all base off of the build
path anyway).
@ndevenish
ndevenish / CMakeLists.txt
Last active March 4, 2024 22:47
Very simple "Getting started" boost-python CMakeLists.txt
cmake_minimum_required(VERSION 3.5)
# Find python and Boost - both are required dependencies
find_package(PythonLibs 2.7 REQUIRED)
find_package(Boost COMPONENTS python REQUIRED)
# Without this, any build libraries automatically have names "lib{x}.so"
set(CMAKE_SHARED_MODULE_PREFIX "")
# Add a shared module - modules are intended to be imported at runtime.
@ndevenish
ndevenish / envdiff.py
Last active November 7, 2017 17:15
Diffs the environments from sourcing a script
#!/usr/bin/env python
# coding: utf-8
"""
Works out the environmental changes from sourcing a script.
Usage:
source_diff.py [--bash | --modules] <script> [<arg> [<arg> ...]]
source_diff.py -h | --help
111/920 Tests without an instantiation:
./cctbx_project/simtbx/nanoBragg/tst_nanoBragg_basic.py
./cctbx_project/cctbx/examples/tst_structure_factor_derivatives_3.py
./cctbx_project/cctbx/examples/tst_space_subgroups.py
./cctbx_project/cctbx/examples/tst_structure_factor_derivatives_2.py
./cctbx_project/cctbx/examples/tst_exp_i_alpha_derivatives.py
./cctbx_project/cctbx/examples/tst_phase_o_phrenia.py
./cctbx_project/cctbx/examples/tst_structure_factor_derivatives.py
./cctbx_project/cctbx/examples/tst_g_exp_i_alpha_derivatives.py
./cctbx_project/cctbx/examples/tst_structure_factor_derivatives_4.py
@ndevenish
ndevenish / bootstrapbootstrap.sh
Last active June 21, 2023 17:30
Bootstrap bootstrap.
#!/bin/bash
set +e
DOC=$(cat <<'END_HEREDOC'
bootstrapbootstrap.sh
Bootstraps bootstrap. Installs python/openssl/certificates so that
bootstrap can bootstrap on distributions old enough to own several
boots with which to wear straps on.