Linediff : Comparing files snippet by snippet

When performing big code changes like refactoring, comparing files can become tedious and time consuming. One way to reduce the load is to compare the file function by function or even snippet by snippet since, most of the time this is what you actually need. A plugin for vim that works very closely to the default diff tool of git vimdiff is linediff.vim.

Cheetsheet

  • ^V and use movement commands to select text
  • :Linediff to put selected text into buffer
  • repeat for second snippet
  • Use diffget and diffput and rest of vimdiff commands as usual
  • Save both buffers once done

Evaluating mesh volume from surface

One of the first tests one needs to implement when generating meshes is a volume test. The main idea like in many other tests is to evaluate the same quantity in two different ways and then compare the results. If everything is correct the results should be close up to some rounding precision error.

When dealing with surface vs volume calculation a familiar method from mutivariable calculus is the Divergence theorem [1] :

[Read More]

Removing white pixels from figures

Quite often, especially when you are working with presentations, you may realize that you need to remove the white background from your figures. One way is to use any photo editing software like Gimp for example and remove the background. But if you have a lot of files and you don’t need smoothing or any other effect you can also use a simple script like this:

#!/usr/bin/env python 
#source : http://stackoverflow.com/a/765829
from PIL import Image
import sys
white = (255, 255, 255, 255)
transparent = (255, 255, 255, 0)
for infile in sys.argv[1:]:
    img = Image.open(infile)
    img = img.convert("RGBA")

    pixdata = img.load()

    for y in xrange(img.size[1]):
        for x in xrange(img.size[0]):
            if pixdata[x, y] == white:
                pixdata[x, y] = transparent

    img.save(infile + "_modified", "PNG")

source

[Read More]