Skip to content

Instantly share code, notes, and snippets.

@bjodah
bjodah / test_repo.sh
Last active June 7, 2016 11:40
Local test runner for Drone CI using Drone CLI (http://readme.drone.io/devs/cli/)
#!/bin/bash -u
# usage:
#
# $ git clone git://github.com/bjodah/chempy
# $ ./test_repo.sh chempy
if [[ $1 == */ ]]; then
>&2 echo "$1 ends with a slash"
exit 1
@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)
@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)
# -*- 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)
#include "header.hpp"
#include <stdlib.h>
#include <vector>
using namespace std;
namespace ops {
Powers :: Powers() {}
Powers::~Powers() {}
#!/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
@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
@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 / 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 / setup.py
Last active December 7, 2018 17:30
A faster version (12.8x speedup) of the ray tracer at: http://www.reddit.com/r/tinycode/comments/169ri9/ray_tracer_in_140_sloc_of_python_with_picture/ It uses Cython for speed but I am pretty certain there are lots of opportunities for optimization! To compile: python setup.py build_ext --inplace To run: python tiny_tracer.py
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
setup(
cmdclass = {'build_ext': build_ext},
ext_modules = [Extension("tracer", ["tracer.pyx"])]
)