See also: Heapify

Pages: 1 2 3 4 5 6 7 8 9 10 11

Dynamically importing Python modules by filename

After looking for a way to import Python modules when given a valid filepath I came across a description of a technique to do so here.

What I did not like about this approach was the use of null_module. In his approach you needed to have a module called null_module somewhere in your PYTHONPATH. This was then cloned and the information about the actual module you wish to report overwrites this module. In short, he was using null_module as a skeleton module for the import. This is unnecessary.

To do the entire import in a much nicer way you can simply do:

...

Read more

There are 2 comments on this post.

JavaScript tip: How to find the document elements that intersect at a certain coordinate

This is going to be mostly a code post.

First thing we need is a method of getting the coordinate of elements in the document. Here is a function I created to do that.

/**
 * Get the offset coordinates of the element.
 * @param {Object} element The element.
 * @return {Object} An object with four properties named x1, x2, y1 and y2 containing the elements left, right, top and bottom edges respectively.
 */
function getElementPosition(element) {
    var elementX = 0;
    var elementY = 0;
    var elementW = element.offsetWidth;
    var elementH = element.offsetHeight;
 
    while (element.offsetParent) {
        elementX += element.offsetLeft;
        elementY += element.offsetTop;
        element = element.offsetParent;
    }
 
    elementX += element.offsetLeft;
    elementY += element.offsetTop;
    elementW += elementX;
    elementH += elementY;
 
    return {x1: elementX, y1: elementY, x2: elementW, y2: elementH};
}

...

Read more

There are no comments on this post.

An easy technique for ellipsis drawing on JavaScript canvas objects

During my recent struggle with the JavaScript canvas object I was looking for a method to draw ellipses. Originally I was trying to use the arcTo() and even got desperate enough to have a quick play around with the bezierCurveTo() and quadraticCurveTo( ) functions before the obvious solution dawned on me.

In the event anybody else wastes their times looking for a way to do this try the following:

var e = document.createElement("canvas");
document.body.appendChild(e);

...

Read more

There are no comments on this post.

Running Python unittest.main() verbosely

I want to run the unittests verbosely, so you can see which test is running (the function name, or if you have a one-line docstring, it displays that), instead of the usual "..E..F." output.

There are two ways, the first is to construct a test-suite using TestLoader, pass it to TestTextLoader(verbosity=2):

suite = unittest.TestSuite([
        unittest.TestLoader().loadTestsFromTestCase(test_tvnamer.test_name_parser),
        unittest.TestLoader().loadTestsFromTestCase(test_tvdb_api.test_tvdb)
    ])
# for one test, you can do:
# suite = unittest.TestLoader().loadTestsFromTestCase(test_name_parser)

...

Read more

There are no comments on this post.

Forced software upgrades in the land of web-apps

Whenever someone complains about a new version of a bit of software, my general response is "you don't have to upgrade".

For example, complaints about Vista can generally be countered with "Well, Windows XP still works fine.."

Where this argument entirely falls down is when an upgrade is forced, but there is pretty uncommon (online portions of video-games, instant messaging applications)..

...

Read more

There are no comments on this post.

Relaunch of the nullnetwork imagepaste

After taking significant time to be lazy & forgotful I have reconfigured the apache to run the nullnetwork image paste tool again (available at http://imagepaste.nullnetwork.net/). All are free to contribute to the gallery.

There are no comments on this post.

Installing the link layer topology discovery (LLTD) protocol responder on Debian Linux

This post on how to install the LLTD is largely ripped off from http://www.howtoforge.com/installing-the-lltd-protocol-responder-for-linux-on-debian-lenny and made a bit more direct for those that just want to make it work and not pay attention to what you're doing! Like me!

So let's dive right in.

mkdir lltd
cd lltd
wget http://download.microsoft.com/download/b/8/e/b8eee444-f8d5-4b8b-aa3d-2f19bf19ac72/Rally-LLTD-PortingKit.exe
unzip Rally-LLTD-PortingKit.exe
sudo apt-get install linux-headers-`uname -r` build-essential

...

Read more

There are 4 comments on this post.

irssi, figlet, greatness

/alias figlet /exec - -o echo $0-| figlet -w 60 | awk -F% 'function randint(n){return int(33+n * rand())} {printf("x03%s%sn",randint(12),$1)}'

Combining the joys of shell scripting, figlet, irssi colour escape codes and two different kind of escape sequences, you can achieve the following...

Awe Inspiring Figletification

...

Read more

There are 3 comments on this post.

Save the plastic trees

There was a post on Lifehacker entitled "Five Best Sites to Stream TV". Useful. I'm always looking for a "legal" alternative to torrenting TV shows. DVD's are okay, but considering you can fit thousands of episodes on a harddrive about the size of a single DVD, it seems like there should be a better solution, one that doesn't involve quite so many slices of plastic sitting on a shelve..

Oh. Importantly, I live in a country that isn't America (currently Australia).. Lets see how "best" these are for us damned Foreigners..

Hulu.

...

Read more

There are 2 comments on this post.

You, sir, have crossed the line.

I didn't really mind when The Escapist added the adverts at the end of the Zero Punctuation videos. It was pretty unobtrusive, and advertised their own content. Fine.

Then "Yahtzee" changed the intro away from using appropriate, fair-use, copyrighted music, to a flashy-random-ZP-graphic title sequence. That annoyed me because I really liked the intro/outro songs (I can't think of Bioshock without thinking of The Beatles - Octopuses Garden..), and the new music/graphics are completely unfitting, and kind of boring..

Then there was adverts for Zero Punctuation at the end of Zero Punctuation. That was just stupid.

...

Read more

There are no comments on this post.

Pages: 1 2 3 4 5 6 7 8 9 10 11

RSS
Powered by Debian, Guinness, and excessive quantities of caffeine and sugar.