Skip to content

Instantly share code, notes, and snippets.

@bjodah
bjodah / .gitignore
Last active August 4, 2020 20:04
Script to compile symengine with memory sanitizer enabled.
mount_*/
environment_*/
output.log
#include <pybind11/pybind11.h>
#include <pybind11/numpy.h>
#include <numpy/arrayobject.h>
namespace py = pybind11;
template<typename T>
py::object create_numpy_scalar(T val) {
// usage requires initialized NumPy C-API (call _imoprt_array() before use)
py::object dt = py::dtype::of<T>();
@bjodah
bjodah / test_repo.sh
Created July 17, 2018 23:03
Convenience script for use with drone (v0.4) cli (http://readme.drone.io/0.4/devs/cli/)
#!/bin/bash -uex
# usage:
#
# $ sudo ./test_repo.sh pycvodes/
#
# $ sudo ./test_repo.sh pynleq2 -e PYNLEQ2_NLEQ2_ROOT_URL=http://secret.example.com/nleq2/
#
# Depends on drone CLI client:
#
# http://readme.drone.io/0.4/devs/cli/
@bjodah
bjodah / gist:a0a7bf852ed4a5743d9127ea506e2698
Created April 4, 2018 07:24
conda inspect on conda-forge's emacs
$ conda inspect linkages -n test emacs
WARNING: pyldd disagrees with ldd/otool. This will not cause any
WARNING: problems for this build, but please file a bug at:
WARNING: https://github.com/conda/conda-build
WARNING: and (if possible) attach file /home/bjorn/miniconda3/envs/test/bin/ctags
WARNING:
ldd/otool gives:
('linux-vdso.so.1', '')
('libc.so.6', '/lib/x86_64-linux-gnu/libc.so.6')
pyldd gives:
@bjodah
bjodah / echo.py
Created February 1, 2018 16:29
Context manager echo-ing new local variables
import inspect
import pprint
class Echo:
""" Context maganger for echoing variable assignments (in CPython)
Examples
--------
>>> with Echo():
... foo = 42
#!/usr/bin/env python
# This file should work with both Python 2 & Python 3:
#
# $ python2 -m pytest enmako.py
# $ python3 -m pytest enmako.py
import io
import argh
from mako.template import Template
#include "header.hpp"
#include <stdlib.h>
#include <vector>
using namespace std;
namespace ops {
Powers :: Powers() {}
Powers::~Powers() {}
# -*- coding: utf-8; mode: cython -*-
# distutils: language = c++
from struct_ex cimport OutVectors
cdef class PyClass:
cdef OutVectors *thisptr
def __cinit__(self, int x=1, int y=1):
self.thisptr = new OutVectors(x, y)
@bjodah
bjodah / backup-github.sh
Created October 17, 2016 15:57 — forked from rodw/backup-github.sh
A simple script to backup an organization's GitHub repositories, wikis and issues.
#!/bin/bash
# A simple script to backup an organization's GitHub repositories.
# NOTE: if you have more than 100 repositories, you'll need to step thru the list of repos
# returned by GitHub one page at a time, as described at https://gist.github.com/darktim/5582423
GHBU_BACKUP_DIR=${GHBU_BACKUP_DIR-"github-backups"} # where to place the backup files
GHBU_ORG=${GHBU_ORG-"<CHANGE-ME>"} # the GitHub organization whose repos will be backed up
# (if you're backing up a user's repos instead, this should be your GitHub username)
GHBU_UNAME=${GHBU_UNAME-"<CHANGE-ME>"} # the username of a GitHub account (to use with the GitHub API)
@bjodah
bjodah / _eulerfw.pyx
Last active October 11, 2016 11:22
Dealing with exceptions
# -*- coding: utf-8; mode: cython -*-
# distutils: language = c++
cimport numpy as cnp
cnp.import_array() # Numpy C-API initialization
import numpy as np
cdef extern from "numpy/arrayobject.h":
void PyArray_CLEARFLAGS(cnp.ndarray, int)