See also: Heapify

Pages: 1 2 3 4

OS X Screen capture from Python/PyObjC

Looking through the unanswered Python questions on StackOverflow, I found one that seemed interesting.. "Python Get Screen Pixel Value in OS X" - how to access screen pixel values, without the overhead of calling the screencapture command, then loading the resulting image.

After a bit of searching, the best supported way of grabbing a screenshot is provided by the CoreGraphics API, part of Quartz, specifically CGWindowListCreateImage.

Since CoreGraphics is a C-based API, the code map almost directly to Python function calls. It's also simplified a bit, because PyObjC handles most of the memory-management (when the wrapping Python object goes out of scope, the underlying object is freed)

...

Read more

There are no comments on this post.

Investigating memory leaks in Python

Memory leaks are difficult to trace down. A nice description of finding one is "A server memory leak", a story about tracing a memory leak in a Django application.

I'm trying to work out why a server process is slowly using more and more memory. The server parses a stream of text, and shoves stuff into a database. It's written in Python, and about the only external code it uses is SQLAlchemy

I found a combination of Meliae and objgraph useful. Pympler also seems useful (the tracker class particularly). Dowser also looks useful, and might have made things a bit easier..

...

Read more

There are 3 comments on this post.

tvnamer v2 development

I've been working on a new version of tvnamer, the utility I discussed in "Automatically rename your torrent'd TV episodes"

It's a pretty much complete rewrite. Some of the new features include:

  • Configuration files. In tvnamer v1 you could only customise things like the output filename format by modifying the Python code directly. Now you can create a JSON file at ~/.tvnamer.json which changes any of the default options.
  • Support for multi-episode files, such as scrubs.s01e23e24.avi
  • Support for anime filenames, such as [Shinsen-Subs] Beet - 19 [24DAB497].mkv
  • Much better UTF-8 filename handling
  • Ability to move files to specific location after renaming (/media/tv/{series name}/season {seasonnumber}/ for example)

...

Read more

There are 2 comments on this post.

My Regex Guide as a PDF

Part two of my regex guide was released as a shiney PDF. At the time I never created a PDF for part one. Sometime between then and now I created an updated PDF version of both, and they have been gathering metaphorical dust.

So, here is a PDF version of part 1, along with an updated version of part 2 (incorporating feedback form the comment section):

Remember: The guide isn't a guide on regex best practises; the examples used are purely to explain the regex syntax. I use examples like escaping MySQL parameters because this is something most programmers are familiar with - you should never use regex for this purpose outside a regex tutorial..

...

Read more

There are 2 comments on this post.

Setting up an OpenID delegate for Verisign

OpenID, the "decentralized standard for user authentication and access control" has a nice feature whereby you can use your own domain as your OpenID login.

Basically you put a few lines of HTML in your <head> tag, and any OpenID supporting basically treats it as a redirect.

I have a Verisign PIP OpenID account, to login to various sites (such as the Stackoverflow "family" of sites), but I can use my own domain (dbrweb.co.uk) as a login.. I could run my own OpenID "endpoint", but this is much simpler, and more secure (as Versign will do a better job than I could)

...

Read more

There is 1 comment on this post.

Woods Don't Go [video]

Another short film my brother an I created last weekend (previous one is here)

Stuart announced his retirement from sundayleague.com. This is my attempt to make him reconsider

...

Read more

There are no comments on this post.

All the video-DSLR's are broken

Discussing the current state of video-capable DSLR cameras

Note: There's a summary for the impatient!

In August 2008 Nikon released the D90, the video DSLR that shot HD video.

The concept was apparently aimed at news-gathering, where reporters who would usually have to carry both a DSLR for photos and a separate video camera, could instead carry a single device capable of both shooting stills and, at the press of a button, shoot HD video.

For completely different reasons, these VDSLRs also appealed to film makers - a wide range of changeable, affordable lenses and large sensors capable of creating "filmic" shallow depth of field.. but, film-makers and news-gatherers have very different needs, and all VDSLR's thus far have been, in various ways, broken..

...

Read more

There are no comments on this post.

Hiding OS X system directories

After restoring a backup, the various OS X system folders became visible again (such as /bin /mach_kernel etc)

The following command (adapted from this post by Wowzera) will hide them again:

# Hide sym-links
SETFILECMD="/Developer/Tools/SetFile"
for cdir in /etc /tmp /var;
    do sudo $SETFILECMD -P -a V $cdir;
done
 
# Hide directories
for cdir in /bin /cores /mach_kernel /private /sbin /usr /Volumes; do
    sudo $SETFILECMD -a V $cdir;
done

Launch Terminal (in Applications, then Utilities), and paste the above script.

...

Read more

There are no comments on this post.

Simpletons guide to git

Simpletons guide to git

This is simply a "click these buttons" guide to git. See the last section of the article for more advanced/better guides and resources.

Installing

...

Read more

There are 2 comments on this post.

A neater way to print something every x iterations in Python

To print some information every 10 loop iterations can be a bit messy. Given the following, simple loop:

for x in lots_of_stuff:
    process(x)

The "dumbest" way would be:

i = 0
for x in lots_of_stuff:
    process(x)
    if i % 10 == 0:
        print "Some progress info"
    i += 1

A more elegant solution would be to use the enumerate built-in:

for i, x in enumerate(lots_of_stuff):
    process(x)
    if i % 20 == 0:
        print "Some progress info"

Much nicer, but this doesn't work with while loops

...

Read more

There are 4 comments on this post.

Pages: 1 2 3 4

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