Archive for the ‘python’ Category

Today’s little snippet: Filtering a loosely coupled many-to-many relationship.  As revealed earlier,  I don’t really “get” the difficulty with many-to-many relationships.  I don’t even get the difficulty with signals; if you define the many-to-many manually, handling signals on it is trivial compared to trying to do it manually in one of the referring classes. Today, [...]

14Sep

Arrrgh. Now, repeat after me:

Posted by Elf Sternberg as django, python, web development

Repeat after me: Registration is not Authentication is not Authorization is not Utilization. Registration is not Authentication is not Authorization is not Utilization. Registration is not Authentication is not Authorization is not Utilization. I’ll keep reminding myself of that until I figure out how to disentangle the four from this damned Facebook app.  Registering to [...]

The correct call for posting to a user’s facebook wall with Python and pyfacebook, after you’ve established both user authentication via FacebookConnect and gotten stream_publish permission, is: request.facebook.stream.publish( message = render_to_string(template_path, fb_context), action_links = simplejson.dumps( [{'text': "Check Us Out!", 'href': "http://someurl.com"}]), target_id = ‘nf’) See that ‘nf’ down there in target_id?  It’s not on any [...]

I’m prepping for an interview this afternoon at what is primarily a Perl shop, and so I’m mainlining the O’Reilly Perl in a Nutshell book as a way of reminding myself about the little details of the language. I can write Perl just fine– I just made some major hacks to dailystrips for example, and [...]

06Jul

Python: What the Hell is a Slot?

Posted by Elf Sternberg as programming, python

So, while working my way through my current project, I came across the notion of a ‘slot’ as discussed here. And I wondered, what the Hell is a slot? A slot is nothing more than a memory management nicety: when you define __slots__ on a class, you’re telling the Python interpreter that the list of [...]

One thing I see a lot of in professional Django is the importation of ugettext, Django’s internationalization library that leverages the GNU gettext project’s toolkit for generating translation catalogs. Laying the groundwork for translation is important to larger projects intended for universal appeal. Because the underscore is a valid leading character in a function name [...]

At del.icio.us (and some other sites, but I’ll use del.icio.us as my example), one of the most interesting features is that your username is one of the first-level “commands” you can send to the application: “http://del.icio.us/elfsternberg” is a valid URL, and points to my collection of bookmarks. At the same, there are other first-level commands [...]

Most people encountering the Ajax components of Django for the first time usually encounter this pairing: from django.utils import simplejson … return HttpResponse(simplejson.dumps(some_python_obj)) For most applications, this is enough.  But I’m especially fond of iterators, generators, functors and closures, dense components that express one thought well: the structure of a tree, or the rows of [...]

This was probably just about the gnarliest little problem I’ve ever wrocked my brains over in a long time.  I was using the Treebeard library for a materialized path tree, and the problem came down to how to render it.  The obvious solution was lists of lists, but… how? I’m not going to explain Treebeard [...]

14May

Python can be just as ugly as PHP…

Posted by Elf Sternberg as PHP, python

I was reading through the WordPress source code, trying to figure out a problem for a contractor, when I saw the function compact().  When I saw it I boggled, read the description, and shook my head. Compact() takes a list of variable names as strings, and returns a hash of those variable names and their [...]