I have been using haproxy as front-end reverse proxy and load balancer for one project for several years and I’ve been very happy with it’s stability and performance (although actual load was always very moderate). In another (more recent) project I decide to try nginx in a similar role (but actually I needed also to serve some static files, which was actual reason to try nginx). Continue reading nginx vs haproxy
Yearly Archives: 2013
Voronoi Diagrams
Some time ago I was looking for an algorithms that can generate a ‘map like’ like pictures – e.g. tessellation of a plane into set of more or less random polygons. I found Voronoi diagrams – which give very nice pictures and have many useful properties.
Most common case of Voronoi diagram is known in an Euclidean plane, where we have a set of points (call seeds) then Voronoi diagram splits the plane into areas – called Voronoi cells – around each seed, where inside each area any point is closer to that seed then to any other. Areas are then convex polygons (for Euclidean metric). This definition is best illustrated on the picture below – the Voronoi diagram for 100 random points in range 0-100 – Voronoi cells are marked by red lines, blue points are seeds:
Web Clients Are Getting Thick
Remembering days when client-server rules the world, then days when everybody praised light web clients where all user interface (UI) was prepared on web server and any user action was communicated back to server (this could lead to heavy network traffic – I’ve seen one mainstream ERP program, where a change in one input, say line item quantity, lead to several megabytes being sent over network). I’m quite amused to see how we’re returning back to thick clients and passing more and more UI tasks back to user devices. This probably make sense, taking into account the computing power available in user devices now (my mobile has approximately same computing power (dual core 1.2 GHz ARM CPU) as a reasonable server ten years back(Sun V240 for instance)) and improvement of web browsers and especially their Javascript engines. Normally utilization on an average client machine would be very low, unless client is dealing with digital media, so using available computing power there is an obvious step. Network bandwidth could be now more precious resource then client computing cycles. Continue reading Web Clients Are Getting Thick
Dynamically Mix in Methods into An Instance in Python
As Python is a dynamic language it offers many possibilities how to manipulate object instances during runtime. We may for instance inject methods from another class, achieving similar results as if this instance has this calls as a mix-in super class. This approach could be useful to hack some existing libraries with extra functionality, in case we have to work with created instances.
This function will inject methods from mixin_class into instance assuring that method is properly bound to the instance.
import types
def mixin(instance, mixin_class):
"""Dynamic mixin of methods into instance - works only for new style classes"""
for name in mixin_class.__dict__:
if name.startswith('__') and name.endswith('__') \
or not type(mixin_class.__dict__[name])==types.FunctionType:
continue
instance.__dict__[name]=mixin_class.__dict__[name].__get__(instance)
Continue reading Dynamically Mix in Methods into An Instance in Python
Django tests auto-discover
Django framework provides integrated tests runner, which can be started by ./manage/py test (see docs for more details, key advantage of this runner is that it’ll create new empty database for tests, so they do not interfere with each other or your development instance). This tests runner runs unit tests from tests.py or models.py modules in active projects. However in larger projects we would like to have other organization of tests code – have for instance special test package within project that contains many testing modules, each focused on particular aspect of the application. Continue reading Django tests auto-discover
UbuntuOne client behind proxy
It can sound bit weird, but most problematic platform for UbuntuOne client is Ubuntu itself – especially when your PC is behind proxy – or even worst when you’re moving between several networks with your laptop, where some nets are using proxy. Continue reading UbuntuOne client behind proxy
Converting files in directory structure
Often I needed to convert a set of files (audio files to different format, text files to different encoding, …) in some directory structure and save results to a new destination while retaining directory structure. In order to walk through directory structure we can use find command, but if we are to create output in new place, subdirectories have to be created, which is where find command line gets bit complicated (especially if we have to consider spaces in files/directories names). So here is an example for converting text files encoding:
find . -name "*.txt" -exec bash -c 'mkdir -p "/dest-dir/`dirname "{}"`"; iconv -f utf-8 -t windows-1250 -o "/dest-dir/{}" "{}"' \;
Long Running Taks in Web App/Django
Some types of web applications require to start long running tasks – like import of file, compilation etc., but user still needs to have real time updates about progress of the task, eventually some error messages, warnings from the task (cannot import particular line, compilation error). There are existing robust solutions like Celery, but it is aways fun to reinvent the wheel 🙂 In this case we focus on simple solution, without need for request broker in middle, which enables immediate/ real time updates on running tasks to client browser.
For our solution we will use two cool technologies/libraries web sockets and zeromq library. Continue reading Long Running Taks in Web App/Django
Playing with maps (QGIS, PostGIS, OSM)
I do like maps. Recently I was looking at some digital maps and got into more details and found several nice open source tools about which I’d like to write in this article. As in any area open source provides interesting alternatives to work with digital maps and geographical data and what is also very interesting there are now free sources of good quality geographical data, which can be used freely by everybody to create their own maps. In this article I’m explaining how use data from Open Street Maps (OSM) project for creating maps in QGIS and how to use PostGIS to store geographic informations and have fun playing around with their different features of map data and tools. This tutorial is focused on linux (debian based – ubuntu 12.04 resp. mint in my case) desktop and assumes some basic knowledge of your linux desktop administration. Continue reading Playing with maps (QGIS, PostGIS, OSM)
AppIndicator3 – how to use custom icons
Recently I’ve updated TheTool to support also AppIndicator3 interface so it can show icon in Unity panel. Although the documentation is not saying it, you can use absolute path to PNG image as icon-name ( apart of stock icon name). I was trying to add application specific stock icons, but is somehow did not work well (only possibility is to use xdg-icon-resource install --novendor --size 32 picture.png icon-name, but python code for creating application specific icons with Gtk.IconFactory was not working for me – see this post on stackoverflow). Continue reading AppIndicator3 – how to use custom icons
