Project Plumbing with Plumbum (Part II)

Leave a reply.
image via

image via

So if you read my previous article, you’ve hopefully found that Plumbum is a fantastic tool for running and managing shell tools from Python. But stay tuned, dear readers, because we’ve only scratched the surface of the fantastic facilities that plumbum provides.

Continue reading

Hidden Options: A Workaround

Leave a reply.
Via JMack on StackOverflow

Via JMack on StackOverflow

Here’s the situation:

You’ve got a select. Maybe a whole bunch of selects, with a ton of options each (metric ton – let’s keep our imaginary hyperbolic units straight here); and these are meant to be complex interactive elements, with options made visible or not as some programmatic condition dictates.

Traditionally, if you wanted to selectively display options, you had to do it the hard way – remove the non-visible option nodes entirely. What, did you want to filter on some state information stored on the node? Too bad – you’ll have to keep track of the full structure outside of the DOM and filter on that, inserting or removing elements as needed.

This is sub-optimal. It’s much tidier if we can just set display:none on our options elements, and have them hidden like any other DOM element:


and in most modern browsers (Firefox, IE9+, Safari), this works just fine. We can then filter in place on the elements, and selectively display them.

Have you noticed the glaring omission yet? Yes, Chrome isn’t among the browsers this works ‘just fine’ in.

You can set display:none on your disabled options to hide them, and that will work – but as stackoverflow user JMack discovered, and per this long-standing chromium bug (open since Jul 30 2012, with the most recent activity on it a downgrade in priority), when you have hidden options in your select, the select dropdown will fail to resize itself appropriately – to the point that the dropdown may not show anything beyond the initial visible option, with the rest of the visible options hidden beneath. They’re still selectable, and can be scrolled to, but the dropdown list will be tiny and scrolling won’t work quite right, often leaving you with the top and bottom of the next two options visible.

We’re not here to complain, though – we’re here to get things done. Let’s whip up a workaround, and then discuss how to use it, how and why it works. Continue reading

Tutorial: Posting to Facebook from a Django App

Leave a reply.

This tutorial is the first part of a series of tutorials that build a complete Django application, codenamed “procrastination automation”. The tutorial on Python Social Authentication can be considered a preface to this series – if you would like an introduction into using social authentication with Python or Django, check it out.


Some time ago, I saw a diagram that showed how content originates from 4chan (or was it 9gag?), then gets reused by Reddit, then gets reposted on Digg, and ends up on Facebook. Don’t google it, it is using a very ugly image for the metaphor. But the idea is that thousands of people are viewing things on one subset of social resources and reposting on another subset, where this content becomes the source of entertainment and news for more viewers.

Literally millions of man-hours are spent daily to transfer images of cat-based memes from Reddit to Facebook. This is a perfect opportunity for automation.

Let’s build an app that will allow a person who would ordinarily browse Reddit a few hours a day and repost pretty much every link from a favourite subreddit to Facebook, set a personal re-poster that will automatically forward those updates from Reddit to his Facebook wall for him, impressing his friends with his immense social presence, and saving his precious time. Continue reading

Tutorial: Adding Facebook/Twitter/Google Authentication to a Django Application

5 Replies.
Image via

Image via

I needed to add Facebook authentication to a Django app today, and instead of writing it directly against the Facebook API (or re-implementing the OAuth2 dance again), I decided to look around and see if there’s a pre-packaged solution for this common task. Turns out, there’s an excellent project called Python Social Auth, and it covers pretty much any social website with an authentication API.

As it often happens with amazing open-source projects, the documentation is somewhat minimalistic. One key piece that I could not find was a tutorial. This post is aiming to fill that gap. In this tutorial, we will use Facebook, Twitter and Google, as the most common social APIs, but we could easily substitute them with LinkedIn, Yahoo, Forsquare, or a bunch of other providers supported by Python Social Auth library. Continue reading

SXSW Wrap-up

Leave a reply.

Now that I’ve been home for a month, I’m ready to write up my thoughts on my first time attending the South by Southwest Interactive festival in Austin, TX.


A view from the green room

Art & Logic has had a presence at SXSW before (conveniently, we have a few account managers who live in Austin, so it was easy), but this was the first time that we’ve attended it aggressively. We had a booth on the trade show floor, and took part in a panel discussion on the topic of estimating software projects — Continue reading

JavaScript Isolation with Nodeenv

1 Reply.

I do a lot of Python work, and I’m a huge fan of virtualenv, which allows you to set up a completely isolated Python environment. This is hugely helpful to keep various dependencies from multiple projects from clobbering one another. It’s so helpful, that when I work in pretty much any other language, I miss having the ability to isolate things so nicely.

Since a lot of the Python work I do is also Web work, I frequently end up doing a lot of Javascript as well. The (relatively) recent appearance of node.js and various development tools based on it has been a great boon, but whenever I’ve had multiple projects using different versions of the same tool, I’ve craved a way to keep my Javascript environments as nicely separated as my Python environments. If only there was something like virtualenv, but for node.js…

In fact there are several ways such things, but my favorite by far is a project called nodeenv. It’s written in Python, which might seem a bit strange until you realize that it’s written specifically to integrate nicely with virtualenv.

Here’s how you use it. Or at least how I use it.

First create a virtualenv. Here I’m using virtualenvwrapper, but of course you can use vanilla virtualenv if you prefer:

$ mkproject nodeenv-test
New python executable in nodeenv-test/bin/python
Installing setuptools............done.
Installing pip...............done.
Creating /home/funsize/code/nodeenv-test
Setting project for nodeenv-test to /home/funsize/code/nodeenv-test

This will create a project directory, create a virtualenv, install pip into the virtualenv, activate it, and switch my current working directory to the project directory just created.

Now we install nodeenv into the virtualenv:

$ pip install nodeenv

This installs a command called, unsurprisingly, “nodeenv”, which we now run with the -p flag, which tells it to integrate with the current python virtualenv:

$ nodenv -p
 * Install node.js (0.10.26) ... done.
 * Appending nodeenv settings to /home/funsize/.virtualenvs/nodeenv-test/bin/activate

Everything will probably work fine at this point, but just to be safe, I like to reset the virtualenv by deactivating and reactivating it:

$ deactivate
$ workon nodeenv-test

(Again, I’m using virtualenvwrapper, which may or may not be to your taste).

At this point we are working in an isolated environment for both Python and Node.js. I can install libraries for Python using pip, or for Node using npm -g and they will not interact with my system Python libraries or Node libraries in any way. Some of you may recall that I’m a big fan of bower, so I can install it like so:

$ npm install -g bower

Bower has a bunch of dependencies, which npm takes care of for us, and all of those get installed into our isolated environment. They can’t interfere with any of our other projects in any way. Bliss!

Ok, so it’s not quite all sunshine and roses. nodeenv needs a bunch of dependencies to work, though nothing too outlandish (stuff like a C compiler, curl, etc.). This isn’t too onerous, and anyone who can install software packages on their machine should be able to get it working on pretty much any Unix flavor without too much trouble. I have not, much to my disappointment, been able to get it to work on Windows as of yet, even with all of the relevant dependencies installed. It appears to have something to do with the way Windows handles command parsing and/or escaping. If anyone out there has gotten it running on Windows, please let me know in the comments. With those caveats, though, nodeenv really is pretty fantastic.

Now this is the kind of thing that you may not really appreciate until you use it, so I encourage all of you out there to give this a shot. It really is worth your time. Enjoy!

Two Things I Missed Functional Testing with WebTest

Leave a reply.

Ian Bicking’s WebTest is a helpful module for running functional tests against a WSGI app. You may already be using it, it’s the suggested way to test Pyramid apps, TurboGears and Google App Engine, and (although I have no experience with this) you can use it with Django (apparently this is a good idea) and Flask. It’s not very complicated but in my haste to get things done I overlooked a couple of its nicest features.
Continue reading

Follow Art & Logic on Twitter

Follow Our Blog via RSS


Connect Socially

A&L on Facebook

A&L on Google+

Home   About   Blog   Careers   Contact