Why vim?

October 18th, 2007 by exhuma.twn
  • Misconception #1: modal editing
  • Misconception #2: it’s not all about regular expressions
  • Misconception #3: you gotta be nuts and/or a genius to use it
  • Misconception #4: hjkl to move around?
  • Misconception #5: since you are thinking 90% of the time, and editing 10%, the productivity gain might be there, but it’s useless anyway
  • Misconception #6: it’s just sticking to a disappearing past
  • Correct-conception #1: steep learning curve

Tickled your interest? Looky there!

Posted in Coding Voodoo | No Comments »

Calculate the distance between two GPS-Coordinates (ctd.)

September 17th, 2007 by exhuma.twn

And here’s the same thing as plpgsql function for Postgres:

CREATE OR REPLACE FUNCTION lldistance( a point, b point)
RETURNS float AS $$
DECLARE    x FLOAT;
        dlat FLOAT;
        dlon FLOAT;
BEGIN
   dlat = radians(a[0]-b[0]);
   dlon = radians(a[1]-b[1]);
   x := sin(dlat/2)^2 +
        cos(radians(a[0])) * cos(radians(b[0])) *
        sin(dlon/2)^2;
   RETURN 6367442.5 * (2*atan2(sqrt(x), sqrt(1-x)));
END;
$$ LANGUAGE plpgsql

This results in more accurate distances than simply using

SELECT point1 <-> point2 FROM sometable;

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 »

Calculate the distance between two GPS-Coordinates

September 17th, 2007 by exhuma.twn

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.

from math import sin, cos, radians, sqrt, atan2

def lldistance(a, b):
   """
   Calculates the distance between two GPS points (decimal)
   @param a: 2-tuple of point A
   @param b: 2-tuple of point B
   @return: distance in m
   """

   r = 6367442.5             # average earth radius in m
   dLat = radians(a[0]-b[0])
   dLon = radians(a[1]-b[1])
   x = sin(dLat/2) ** 2 + \
       cos(radians(a[0])) * cos(radians(b[0])) *\
       sin(dLon/2) ** 2
   y = 2 * atan2(sqrt(x), sqrt(1-x))
   d = r * y

   return d

Posted in Python | 1 Comment »

Centering a window on the screen with Qt

September 10th, 2007 by exhuma.twn

Yet another thing that’s not automagic in Qt.
Here’s a python solution:

if __name__ == "__main__":

   app = QtGui.QApplication(sys.argv)

   dw = app.desktop().width()
   dh = app.desktop().height()

   myapp = MainWindow()
   myapp.setGeometry(
         int((dw - (dw - (dw / 2)) * 1.5) / 2),
         int((dh - (dh - (dh / 2)) * 1.5) / 2),
         int((dw - (dw / 2)) * 1.5),
         int((dh - (dh / 2)) * 1.5))
   myapp.show()
   sys.exit(app.exec_())

This will also resize the window, adapting to the desktop size.
Found and adapted from the Qt interest archive.

Posted in Python | No Comments »

Adding Scrollbars to a QFrame in Qt

September 10th, 2007 by exhuma.twn

Many things are very easy to accomplish in Qt. Qt’s designer is a great help with that. But the is no option to simply “enable” scrollbars for a frame. Also, the QScrollArea can nowhere be found in the designer. The solution is actually quite simple:

  1. Add the component you want to be scrollable (QFrame, QLabel, …) in the designer as usual
  2. In the application code:
    1. Create a new QScrollArea
    2. Set the parent of the widget you created in the designer to “None”
    3. Set the widget of the QScrollArea to the widget from step 1
    4. Insert the QScrollArea to you ui

And here’s some example code (boiled down to the essentials):

sa = QtGui.QScrollArea()
self.ui.myWidget.setParent(None)
sa.setWidget(self.ui.myWidget)
self.ui.vboxlayout1.insertWidget(0, sa)

You would probably write this somewhere in you application-constructor right after you call setupUi.

This will insert the scroll area at the top of vboxlayout1 (see the doc for insertWidget). You can of course also use addWidget.

It’s a shame that there’s no direct support for QScrollArea in designer. Maybe we will see it in some future release.

An example for C++ can be found in the Qt Forums.

Posted in Python | 1 Comment »

VIM rc-file

August 10th, 2007 by exhuma.twn

Due to inane network restrictions I am maintaining several copies of my vimrc file. I would syncronize it though other means. Alas, the restrictions not only cover the network. So I have to resort to simply posting it here.

This is not meant to be an explanation of vim configuration file. However, it contains lots of comments, and might prove a good primer/starting-point. Eventually I will also include other modifications I made in my vim-home-folder as they are either used in the vimrc or just plain useful ;)

Read the rest of this entry »

Posted in Babble, Coding Voodoo | 2 Comments »

Ohloh Open Source Statistics

July 26th, 2007 by exhuma.twn

ohlo language statsOholoh is a site that keeps code statistics of open-source projetcs. It’s very interesting to browse though the different projects and look at their metrics.

It can also be a nice incentive to get people do commit on a regular basis, as it adds a sort of healthy competition to the development cycle.

Anyhow…. Great idea, and it already keeps track of quite a number of projects.

Posted in Coding Voodoo | No Comments »

Visual Basic Sucks!

July 19th, 2007 by exhuma.twn

That’s all I have to say!

Posted in Coding Voodoo | No Comments »

Deploying PyQt applications on Windows

July 12th, 2007 by exhuma.twn

My preferred way to deploy python applications on Windows is to use py2exe.

py2exe is a Python Distutils extension which converts Python scripts into executable Windows programs, able to run without requiring a Python installation.

If you run in trouble with sip, read on…
Read the rest of this entry »

Posted in Python | 1 Comment »

OverkillFlickr: a Flickr API interface for PHP5

July 9th, 2007 by wickeddoc

I create a small Flickr API interface for PHP5 which takes advantage of the Overloading feature of PHP5.

Using the __call method we can dynamically create an interface to all the Flickr API functions using only a very small script.

The name of the class is purely ironic as it is a very simple and easy-to-use class and far from Overkill.

Read the rest of this entry »

Posted in PHP | 7 Comments »

« Previous Entries Next Entries »

Pages

Recent Posts

Categories

Links


Archives

Meta