Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@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 / main.py
Last active July 12, 2021 12:20
Annotating .py file with pxd for generating fast c-code. Needs Cython 0.19-dev, tested with both Python 2.7 and Python 3.3 Execute by running e.g.: bash run_python.sh bash run_cython_working.sh bash run_cython_not_working.sh
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Mandelbrot example using cython
"""
# stdlib imports
import time
@bjodah
bjodah / example_infer.py
Created October 2, 2013 08:48
Code generation of typed cython code from annotated pure python code (makes cython optional). Proof of concecpt not nearly as mature as e.g. cython pure mode.
from infer import MetaInfer
from infer import types as t
class Vec2(metaclass=MetaInfer):
# Typed slots:
_typed_init_slots = (
('x', t.double, 0.0),
('y', t.double, 0.0)
)
@bjodah
bjodah / Makefile
Last active August 29, 2015 14:01
Benchmark pow() vs explicit multiplication
# Enabling -ffast-math makes the two versions competetive, without it explicit is much faster...
# (~20x for exponent of 5)
CFLAGS ?= -std=c99 -O3 #-ffast-math
LIBS ?= -lrt -lm
.PHONY: all
output.txt: main
$(CC) --version > $@
./$< 42 >> $@
@bjodah
bjodah / _func.pyx
Created June 16, 2014 12:18
Non-type template arguments C++/Cython
# -*- coding: utf-8 -*-
# distutils: language = c++
from func cimport func as _func
def func(double inp):
cdef double out
_func[double, 3](&inp, &out);
return out;
@bjodah
bjodah / demo.py
Last active August 29, 2015 14:03
prototype Dictionary Of Keys based sparse (square) matrix. Implemented in cython.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division,
print_function, unicode_literals)
from sparse import SMat
def _print(a):
{
"metadata": {
"name": "",
"signature": "sha256:ff2051673721abee70ec74bc10add60780735c583e66f767e30c0906bd95ba38"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
@bjodah
bjodah / _func.pyx
Created November 20, 2014 13:05
Compiler crash when gdb_debug=True and multiple tempate typenames are used.
# -*- coding: utf-8 -*-
# distutils: language = c++
from func cimport func as _func
def func(double inp):
cdef double out
_func[double, double](&inp, &out);
return out;
@bjodah
bjodah / .gitignore
Last active March 15, 2021 02:55
pass_pycallback
_myclib.cpp
_myclib.so
build/
cython_debug/