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
#!/bin/bash
# This script uses docker to build a specific symengine commit under CentOS6/GCC8/boost1.72
#
# Example usage:
#
# $ sudo ./docker_symengine_cos6.sh e7d7ae55f4fd6740a48acaea0e7e24542ceda6b7
#
if ! which docker; then
2>&1 echo "You need to have docker installed. See e.g. https://www.docker.com/community-edition#/download"
import math
import datetime
from functools import reduce
MÅNADER_PER_ÅR = 12
DAGAR_PER_ÅR = 365.25
DAGAR_PER_MÅNAD = DAGAR_PER_ÅR / MÅNADER_PER_ÅR
def årlig_tillväxt_i_procent_uttryckt_som_faktor_per_månad(x_procent):
# y**12 == 1 + årlig_aktie_avkastning_procent/100
# log(y) = log(1 + årlig_aktie_avkastning_procent/100)/12
#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 / mount_encfs.sh
Created August 26, 2011 22:33
Mounts an EncFS folder for sharing with other group members
#!/bin/bash
# BASH shell script for mounting an encrypted EncFS folder for
# for sharing with other user/users who are member of $GROUP
# Since EncFS runs in userland, no root privileges are needed.
# Remember to uncomment user_allow_other in /etc/fuse.conf
# It is currently configured to mount the encrypted folder:
# ~/.private
# on the unencrypted mount point (which is created upon mount):
# ~/private
@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"])]
)
@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