Martian Headsets
One link, lot’s of text
Posted in Babble, Links | 1 Comment »
One link, lot’s of text
Posted in Babble, Links | 1 Comment »
As you may know, polygons are sensitive to the ordering in which vertices are put in. What is more, the normals of a polygon face depend on the direction of the face.
This usually is not a problem when the polygon is constructed by a graphics-savvy person. If, however (as in my case), the polygons are edited in a user frontend, and if the target audience for that UI may not be aware of the problem, you might run into trouble.
I strongly believe, that details like this should be hidden from the less technically-inclined people, so they can get thei job done without swearing at the UI. And therefore be more productive. This piece of javascript allows you to “simplify”an array of 2D-Points by sorting it accordingly. The resulting array will construct a simple polygon with always outward-facing normals.
This uses the well-known paradigm of taking a reference point and then “swiping” counter-clockwise over the available points. Depending on the reference point (and the available vertices), the end-results may vary. So it may not really result in what the user expected. Having an undo ready at hand should prove useful. However, this algorithm assumes the most likely case, in which the reference point is set to the centroid of the polygon.
The entry-point function is this algorithm is “simplify_polygon”. Feel free to play around with it. Documentation is sparse, but if you know your trig you should figure it out by yourself. It’s fairly straightforward.
Note: The 4-way branch in the “angle” function could be simplified. It is as it is because my mind was locked in the 4 quadrants when writing it. Didn’t feel like changing it yet
Posted in Coding Voodoo | 1 Comment »
Somethin that I need quite often is to create custom accessors and mutators for class-attributes. For example convert this:
into this:
This particular example allows an easy tracking if a class contains changes. Without the need of calling myclass.get_some_attribute() or myclass.set_some_attribute(foo). You can simply do myclass.some_attribute = foo and the has_changes attribut will change accordingly.
If your class has many attributes, writing custom accessors and mutators can be tedious. So here’s a small Vim-mapping that get’s you started. Sure, you may still need to fine-tune some generated code, but the bulk is there.
Put this into your vimrc, or (like I do) into the ~/.vim/ftplugin/python.vim file so it get’s only loaded for python files. Then you only need to write the attribute name of the class, put your cursor on that line, be sure to be in normal mode (hit a few time <esc>)
and hit F6
If you want to change the shortcut, simply change the first parameter to this mapping line.
Posted in Python | No Comments »
NEVER forget these simple rules. Every computer application with a user interface will benefit from them.
It’s really worth it. People will love you for it. Trust me
I personally find that using an ordered list is somewhat misleading. Every point should be considered with equal importance. That’s why I will change to “ol” tag to an “ul” tag now
See page 74-75 Scheiderman: Designing the User Interface, 3rd
Posted in Coding Voodoo | No Comments »
Tickled your interest? Looky there!
Posted in Coding Voodoo | No Comments »
About these homes and at the intersections of the roads in this nomadic ‘city’ are the gardens. Each is unique. One may centre around an unusually-shaped stump or an arrangement of stones or a graceful bit of wood. They may contain fragrant herbs or bright flowers or any combination of plants. One notable one has at its heart a bubbling spring of steaming water. Here grow plants with fleshy leaves and exotically-scented flowers, denizens of some warmer clime brought here to delight the mountain-dwellers with their mystery. Often visitors leave gifts in the gardens when they depart, a wooden carving or a graceful pot or perhaps merely an arrangement of bright pebbles. The gardens belong to no one, and all tend them.
Robin Hobb, Assassins Quest.
Great Britain: Harper Voyager, 1998
When rading this passage of this book (which is part of the Farseer Trilogy) I could not help but think about Open Source projects. If you did not had the same thought when reading the text, go read it again. It is a beautiful analogy.
Note: If any directly involved party feels that any copyright claims have been violated by posting this, please leave a comment. I will take this text down if so requested.
Posted in Babble | No Comments »
I can sympathize that GPG (a free and toolset to encrypt and sign digital data) has not been used by the wide public in the past. It was complex to set up, the concept of private/public keys was a bit flaky to most people, PGP (not GPG!) costs precious money, and integration with mail clients was not trivial.
With the spreading of Mozilla Thunderbird this has changed drastically however. With enigmail (a mozilla-addon to use GPG with the mail client), things are becoming much easier and accessible. It offers most of the functionalities you wish to see in such a tool. It allows you to create a new private/public key pair, has a simple management tool for keys, and lets you very transparently sign and/or encrypt e-mails.
In my opinion, the main reason why GPG is still a thing for “geeks” or “professionals” is the ignorance (or naiveté) of people about how easy mails can be intercepted. Yesterday I demonstrated somebody this exact fact. And him still being quite computer-literate, he was still baffled that I could show him the text of a mail he sent with his password along the lines (All done with his consent of course). And I do not consider myself a hacker. Just a few minutes of googling, downloading and installing the right tool did it for me. And if I can do this, so can many other people as well. With a little bit more effort, it’s even possible to alter the text of a mail in transit. Needless to say, the emails are stored on somebody else’s server. An this in plain text! Even if the server does support SSL, TLS or whatnot. This only means that the transmission between mail-client and mail-server is secured. Not the storage. And you never know who sit’s behind the screen of that server.
Granted, most of the time, people managing servers like this are most likely geeks themselves, which usually share the concern about security, and thus keep things safe.
Considering this, it can become easy to demonstrate the advantages of mail encryption/signing. And usability is increasing steadily. With the mozilla suit (and thunderbird) now having a user-friendly tool at the ready, people are not yet easily convinced to keep security in mind. Other mail-clients offer easy user-interfaces as well. The KDE-Suite (with KMail and KGPG) had brilliant supoprt for this already a long time ago. And there are more free tools available to make it a user-friendly experience. The Swiss-Army-Knife for a Windows environment would probably be GPGShell. It still resorts to the GPG-Cli application from time-to-time, but it keeps it to a minimum. It also offers easy file-encryption via Windows Explorer shell entries. Another alternative is Evolution, which has built-in supoprt for GPG.
Suffice it to say, there is widespread support for GPG (and PGP) in mail-application across all OS’es. To become more widespread in use, people should be made aware of the risks that are posed by e-mails and how easy it can be made to keep personal information really personal.
Posted in Babble | No Comments »
And here’s the same thing as plpgsql function for Postgres:
This results in more accurate distances than simply using
You could also use plpython as function language and copy/paste the earlier post, but plpgsql is more portable.
Posted in Coding Voodoo | 1 Comment »
This function uses the Haversine formula to calculate the distance which takes into account the spherical nature of the earth.
As the earth is not a perfect sphere, this function approximates this by using the average radius.
Posted in Python | 2 Comments »
Yet another thing that’s not automagic in Qt.
Here’s a python solution:
This will also resize the window, adapting to the desktop size.
Found and adapted from the Qt interest archive.
Posted in Python | No Comments »