Skip to main content

Posts

Showing posts with the label programming

Inkscape extension example

Recently, when preparing figures for publications using Inkscape, I decided to simplify my life. Some of the figures can be described as 2x2, 2x3, or even 2x6 grids. Sometimes it is very awkward to rearrange them if you decide to switch from 2x6 to 3x4 or vice versa. It would be nice to have an Inkscape extension, which will minimize the efforts. For the sake of simplicity we assume that all the elements are equal in width and should be rearranged symmetrically with respect to the vertical axis. Also, the element should be ordered according to its relative to the other elements location. The top left element is the first and the bottom right is the last one. So for example, you can visually prepare the elements and then tidy them up with a single click of our magic button. Hint : before developing a similar extension, you may want to check the standard Align and Distribute tool (Ctrl+Shift+A). Before writing any actual code let's take a look at some official Inkscape extensio...

Code sugar and high-level concepts

Let us multiply all the elements from the set {1, 2, 13} by all the elements of {7, 5}. Thinking in imperative languages, one may come with two nested loops (or iterators). Speaking C++ #include <iostream> using namespace std; int main() { int a [] = {1, 2, 13}; int b [] = {7, 5}; for (int i = 0; i < 3; ++i) { for (int j = 0; j < 3; ++j) { cout << a[i] * b[j] << endl; } } return 0; } In Python I'd rather utilize a list comprehension >>>  [a * b for a in [1, 2, 13] for b in [7, 5]] The same goes to the blocks in ruby > [1, 2, 13].each do |x| [7, 5].each { |y| puts x * y } end One may find analogous list comprehensions in Haskell. But they aren't cool here. All you need is applicative functors aka Control.Applicative (*) <$> [1,2,13] <*> [7,5] Bonus: have you noticed, the C++ code contains a bug which is passed by the compiler? There are only two elements in array ...

How to fix 'ImportError: cannot import name QtCore' on Debian Linux

What to do if such import error occurs? >>> import PySide >>> from PySide import QtCore Traceback (most recent call last):   File "<stdin>", line 1, in <module> ImportError: cannot import name QtCore 1. Try to locate where your pyside is installed: $ locate PySide ... /usr/lib/python2.7/dist-packages/PySide /usr/lib/python2.7/dist-packages/PySide/__init__.py /usr/lib/python2.7/dist-packages/PySide/__init__.pyc /usr/lib/python2.7/dist-packages/PySide/phonon.so /usr/lib/python2.7/dist-packages/PySide/QtCore.so /usr/lib/python2.7/dist-packages/PySide/QtDeclarative.so /usr/lib/python2.7/dist-packages/PySide/QtGui.so /usr/lib/python2.7/dist-packages/PySide/QtHelp.so ... Hint: use this to update your file index: $ sudo updatedb 2. The solution is easy: add this to your ~/.bashrc (or ~/.<shell>rc you actually have). export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/python2.7/dist-packages/PySide

How to install pysqlite (python sqlite binding interface) on Ubuntu Linux

First you need development libraries: $ sudo apt-get install libsqlite3-dev Then you have to download pysqlite files from http://code.google.com/p/pysqlite/ Next steps are usual: unpack and change dir After that run (you should have gcc - GNU C compiler - of course): $ python setup.py build After compilation runs successfully you are able to install pysqlite with: $ sudo python setup.py install That's all