install numba in osx yosemite with brew

brew tap homebrew/versions
brew install --disable-assertions --rtti llvm33
LLVM_CONFIG_PATH=/usr/local/Cellar/llvm33/3.3_1/bin/llvm-config-3.3 pip install llvmpy
pip install numba
from numba import jit
from numpy import random
# jit decorator tells Numba to compile this function.
# The argument types will be inferred by Numba when function is called.
@jit
def sum2d(arr):
    M, N = arr.shape
    result = 0.0
    for i in range(M):
        for j in range(N):
            result += arr[i,j]
    return result

def sum2dpy(arr):
    M, N = arr.shape
    result = 0.0
    for i in range(M):
        for j in range(N):
            result += arr[i,j]
    return result

a = random.randint(low=-1e8, high=1e8, size=1e4).reshape(1e2,1e2)
%timeit sum2d(a)
%timeit sum2dpy(a)
%timeit a.sum()

Simple fix to lessc missing watch

Less does not have a watch function, as scss have.

Install grunt:

npm install grunt grunt-contrib-watch grunt-contrib-less

Gruntfile.js:

module.exports = function(grunt) {

  // Project configuration.
  grunt.initConfig({
    less: {
      dist: {
        options: { compress: true },
        files: {
          'css/stil.css': 'css/stil.less',
        },
      },
    },
    watch: {
      less: {
        files: 'css/stil.less',
        tasks: 'less',
      },
    },
    
  });

  // Load plugins
  grunt.loadNpmTasks('grunt-contrib-less');
  grunt.loadNpmTasks('grunt-contrib-watch');

  // Default task(s).
  grunt.registerTask('default', ['watch:less']);

};

PHP built-in web server and CakePHP rewrite rules

app/webroot/rewrite.php:

<?php
$path = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
// If the file exists then return false and let the server handle it
if (file_exists($_SERVER["DOCUMENT_ROOT"] . $path)) {
  return false;
} else {
  include __DIR__ . '/index.php';
}
?>

Then start with:

php -S localhost:8080 rewrite.php

Resource: http://www.sitepoint.com/taking-advantage-of-phps-built-in-server/

python segfault on mayavi masking

When enabling “Mask input points” python crashes/segfaults because it tries to allocate 9223372036854775805 elements of 4 bytes (thats 3,7e19 bytes!).

Error message is:

ERROR: In /tmp/-ShMM/VTK5.10.1/Common/vtkDataArrayTemplate.txx, line 144
vtkFloatArray (0x7ff37757da60): Unable to allocate 9223372036854775805 elements of size 4 bytes. 

Seems this is because “Max number of points” is set to 9223372036854775805 by default, and I’ts not possible to change from the mayavi pipeline window (greyed out). Yey!

Anyhow, to fix this, set “Max number of points” before turning masking on. Do it this way:

# Plot
fig = figure(1, size=(400, 400), bgcolor=(1, 1, 1), fgcolor=(0, 0, 0)) # figure with white background
quiver3d(x,y,z,bx,by,bz)

# prevent segfautl (malloc too large) on osx
vectors = fig.children[0].children[0].children[0]
vectors.glyph.mask_points.maximum_number_of_points = 1000 # "Manually" set Maximum number of points
vectors.glyph.mask_input_points = True # turn masking on

Mayavi on OS X Mountain Lion 10.8.5

1. Get homebrew: http://brew.sh/
2. Install homebrew’s version of python:

brew install python

(You should probably get SciPy too: http://fonnesbeck.github.io/ScipySuperpack/)
3. Change path so that /usr/local/bin is listed first: /etc/paths

/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin

4. Close console and open again to get new path.
5. Install pyqt:

brew install pyqt

6. Install version 5.10.1 of vtk (6.0.0 is currently not working):

brew tap  homebrew/science
brew versions vtk #list versions of vtk
cd /usr/local/Library/Taps/homebrew-science/ #so that git finds vtk repository
git checkout 27a4327 /usr/local/Library/Taps/homebrew-science/vtk.rb #checkout version 5.10.1
homebrew install vtk

7. Install mayavi:

pip install mayavi

8. Install ipython:

easy_install ipython

9. Run your mayavi plot:

ipython
execfile('file.py')