I decided to increase my perspective in programming and this time to look at some functional language. Functional languages are here for quite some time, but never got into mainstream, however recently they are getting more popular. And some features from functional programming made their way into other languages (first class functions, closures, higher order functions, … ), so I was curious to learn a bit more of functional programming. For my exercise I decided to try OCAML.
Continue reading Learning OCAML
Category Archives: Programming
Eclipse Help Browser And Proxy
It’s quite pathetic, that HTTP proxies settings are causing problems again and again in various applications – like UbuntuOne, pip … Maybe it is just problem for Ubuntu/Linux platforms where proxy settings are in separate places (dconf keys for desktop, http_proxy
, HTTP_PROXY
, no_proxy
environment variables).
This time it was Eclipse IDE. Problem here is like this – Eclipse has proxy settings in Preferences/ General / Network connections – however these settings are not applied to Help Browser (started via Help/Help Contents) – this browser is using system settings (I believe from dconf key system.proxy in my case), but not in consistent way – while browser is fine with subnet entry in system.proxy.ignore-hosts like 127.0.0.1/8, Eclipse help browser is not, it just requires server part of url – e.g. just 127.0.0.1).
Also Native option for proxy settings in Eclipse (which are used for updates, plugins install) seems not to work on Linux.
I spent some time to fix this, another victim to inconsistent proxy handling.
Hiding Secret Message in Unicode Text
An art of hiding secret message into another innocent looking message is called steganography and it is an old discipline, where techniques like invisible ink, micro dots have been used. With rise of digital technologies new possibilities for stenography appeared and attracted interest of computer scientists and fans. Common approach is to hide secret information into multimedia files – pictures, music, videos …. Main advantages here are omnipresence of media today, significant size of media file, so there is enough space for additional information and the nature of the media format, which often enables to hide information in very clever way( if you change last bit of color information for a pixel in an image it is unidentifiable by human eye). But we can also hide secret messages in regular text, especially if we are using Unicode text encoding (which is now very common).
Protecting Django Application Against Brute Force Password Guessing
When you bring your web application live, you can expected various types of attacks – one could be a brute force scanning of possible logins. As a standard mean of prevention against such types of attacks login should be temporarily disabled after some number of unsuccessful attempts. For Django nice package called django-lockout exists.
Main advantage of this package is that it keeps history of unsuccessful login attempts in memory (using Django cache system), so checks are very quick. django-lockout is fairly easy to implement, however I’ve found one issue, when it is used together with django admin site.
Continue reading Protecting Django Application Against Brute Force Password Guessing
Python packages distribution
Currently python options for code distribution are bit messy as described here. I spent some time to find right way how to create setup script, which will install external dependencies, so here is the recipe for python3: Continue reading Python packages distribution
MyPlaces are live!
I put MyPlaces live on Internet for a pilot run – it’s a new project of mine, I’ve been playing with it in spare time for last few months. Live site is at http://myplaces.zderadicka.eu. Continue reading MyPlaces are live!
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