Skip to main content

Posts

Showing posts from 2012

How To Create a PyCharm Launcher on Ubuntu 12.10

I'm absolutely loving using PyCharm for my Python and Django development, but one of the lingering things I've been meaning to nail down once and for all is creating a launcher for PyCharm in Ubuntu 12.10. Despite the automated way you can attempt to do this from within PyCharm itself and all the other recommendations I've read I was unable to get it working.
In the mean time I also bought of copy of IntelliJ IDEA when they had some crazy back to school sale a couple of months ago (I still dabble in Groovy and Grails a bit). I was having the same issues with creating a launcher for IDEA and the typical tricks I use for Eclipse weren't working, but luckily I came across this post that explains how to do it. The only change I made is pointing to idea64.vmoptions instead of just idea.vmoptions -- other than that it works great.
That got me thinking -- since PyCharm and IDEA are both made by JetBrains, and both run on Java, chances are how they work is pretty darn similar.…

Using Python to Compare Document IDs in Two CouchDB Databases

I'm doing a bit of research into what may or may not be an issue with a specific database in our BigCouch cluster, but regardless of the outcome of that side of things I thought I'd share how I used Python and couchdb-python to dig into the problem.

In our six-server BigCouch cluster we noticed that on the database for one of our most heavily trafficked applications the document counts displayed in Futon for each of the cluster members don't match. As I said above this may or may not be a problem (I'm waiting on further information on that particular point), but I was curious which documents were missing from the cluster member that has the lowest document count. (The interesting thing is the missing documents aren't truly inaccessible from the server with the lower document count, but we'll get to that in a moment.)

BigCouch is based on Apache CouchDB but adds true clustering as well as some other very cool features, but for those of you not familiar with Couc…

CouchDB Tip: When You Can't Stop the Admin Party

I was setting up a new CouchDB 1.2 server today on Ubuntu Server, specifically following this excellent guide since sudo apt-get install couchdb still gets you CouchDB 0.10. Serious WTF on the fact that the apt installation method is years out of date -- maybe I should figure out who to talk to about it and volunteer to maintain the packages if it's just a matter of people not having time.

The installation went fine until I attempted to turn off the admin party, at which point after I submitted the form containing the initial admin user's name and password things just spun indefinitely. And apparently adding the admin user info manually to the [admin] section of the local.ini file no longer works, since it doesn't automatically encrypt the password you type into the file on a server restart like it used to.

Long and short of it is if you see this happening, chances are there's a permission problem with your config files, which are stored (if you compile from source) in…

Three Approaches to Handling Static Files in Django

I had a really great (and lengthy) pair programming session today with a coworker during which we spent a bit of time going over a couple of different approaches for dealing with static files in Django, so I thought I'd document and share this information while it's fresh in my mind.

First, a little background. If you're not familiar with Django it was originally created for a newspaper web site, specifically the Lawrence Journal-World, so the approach to handling what in the Django world are called "static files" -- meaning things like images, JavaScript, CSS, etc. -- is based on the notion that you might be using a CDN so you should have maximum flexibility as to where these files are located.

While the flexibility is indeed nice, if you're used to a more self-contained approach it takes a little getting used to, and there are a few different ways to configure your Django app to handle static files. I'm going to outline three approaches, but using diffe…

Installing python-ldap in virtualenv on Ubuntu

We're authenticating against Active Directory in our current Python/Django project and though we've had excellent luck with python-ldap in general, I ran into issues when trying to install python-ldap in a virtualenv this afternoon. As always a lot of DuckDuckGoing and a minimal amount of headbanging led to a solution.
The error I was getting after activating the virtualenv and running pip install python-ldap was related to gcc missing, which was misleading since that wasn't actually the issue:
error: Setup script exited with error: command 'gcc' failed with exit status 1
To add to the weirdness, when I installed python-ldap outside the context of a virtualenv, everything worked fine.
I'll save you the blow-by-blow and just tell you that on my machine at least, other than the required OpenLDAP installation and some other libraries, I also had to install libsasl2-dev:
sudo apt-get install libsasl2-dev Once I had that installed, I could activate my virtualenv, run …

A Week at a Conference with the Dell Sputnik

I attended DjangoCon a couple of weeks ago (which was awesome!) so that was my first opportunity to spend some concentrated quality time with the Dell Sputnik and put it through its paces.

As you've probably guessed from my previousposts I'm pretty enamored with the Sputnik, and using it full-time for a week straight didn't change my opinion. It's a particularly great machine to travel with since it's the ideal combination of light but still powerful enough to use for "real" work. In years past I've traveled with only a 10.1" netbook and that was a miserable experience, but the 13" screen and fantastic battery life of the Sputnik make it the ideal conference companion and I could still catch up on work in the evenings without feeling like I had one hand tied behind my back.

Battery Life Day one of DjangoCon was a full day of extended tutorials so I used the Sputnik all day to take notes in Zim. There was no wi-fi available so I ran the Sputn…

Dell Sputnik: Battery Life Test

After I got the Sputnik set up the way I wanted I figured it was time to test the battery life, so yesterday afternoon I unplugged the power cord and did normal "work stuff" to see how much time I'd get out of the battery under normal working conditions.
Note that I'm not a professional hardware tester or benchmarker, so this was not a scientific experiment resulting in reams of data that can be sliced and diced 100 different ways. To me those charts and graphs always seem artificial anyway (though I suspect it's quite efficient to do things that way if you test hardware for a living), so my methodology was, quite simply, to use the laptop unplugged until the battery ran out.
Applications Running During Testing As far as specifically what I was doing and what applications I had running, I was doing Python/Django development yesterday, so here's what I had running: EmacsSublime Text 2MySQLChrome with 6-10 tabs openTerminal with 3-4 tabs openPidgin IM clientWiFi…

Dell Sputnik Ultrabook: Initial Impressions

I got word a couple of days ago that I got into the Dell "Sputnik" beta program, which is Dell's incubation project to bring a GNU/Linux-based (specifically Ubuntu-based) XPS 13 Ultrabook to market as a product, specifically as a machine aimed at developers. (We developers, lone wolves though we tend to be, do like a little attention now and then!)
As a huge free software and Linux proponent I have been watching this project closely so I was really excited to get an invite to the beta, and I received the machine today. General Disclaimer: The machine was not free. Dell did offer a discount for beta program participants but is heavily encouraging everyone to be very transparent and honest with their impressions of the machine.
In another blog post I'll cover how I went about installing Ubuntu and the Sputnik-specific PPAs, but in this post I'll share my initial impressions of the machine. (tl;dr version: With one minor exception, this is an absolutely beautiful, e…

Installing MySQL Python Module on Ubuntu

After tearing through several other Django books and tutorials using sqlite3 as the database, I'm starting to go through the book Beginning Django E-Commerce and it uses MySQL as the database. I use MySQL quite a lot so that side of things isn't an issue, but I did run into a couple of wrinkles getting MySQL and Django playing nice so I thought I'd share.
Basically if after configuring your database in settings.py and running python manage.py dbshell you get a bunch of errors, you have a minor amount of installation work to do to get things rolling.
First thing I did was install pip, which is a better version of/replacement for easy_install: sudo easy_install pip
Next I ran pip upgrade for good measure (probably not necessary but can't hurt, and worth running if you already had pip installed): sudo pip install pip --upgrade
On my machine (Ubuntu 12.04 64-bit) I also had to build the dependencies for the python-mysqldb libraries: sudo apt-get build-dep python-mysqldb
And f…

Manually Installing the Django Plugin for Eric

If you install Eric (specifically Eric 4) from the Ubuntu software repos, the Eric plugin repository points to a location that's unavailable:
http://die-offenbachs.homelinux.org/eric/plugins/repository.xml

I'm sure there's a way to change it but I don't see how to do it in the app itself (haven't started poking around to see if there are config files somewhere yet), but luckily Eric plugins are just zip files so you can download them from a repository URL that works, and then add them to Eric.

The working plugin repository is here:
http://eric-ide.python-projects.org/plugins4/repository.xml

From there just do a ctrl-F to find the plugin you're looking for, then copy/paste the URL for the plugin's zip file into your browser (or use wget or whatever floats your boat) to download the plugin.

With the zip file downloaded, in Eric go to Plugins -> Install Plugins, click Add, and then point to the zip file you downloaded.

If someone knows how to change the plugi…

Connecting to SQL Server with pyodbc

At long last after my previous posts on this topic we get to the easy part: using pyodbc to run queries against SQL Server.

If you need to get caught up, the posts you'll want to go through before proceeding with this one are:

Installing pyodbc on UbuntuFreeTDS Quick StartCreating a Datasource with FreeTDS and unixODBC With a datasource created in unixODBC this last part is rather anti-climactic, but this is of course also where you can get some real work done in Python.
First, in a Python console ('python' from a terminal or whatever your favorite Python console tool is), import pyodbc: >>> import pyodbc
Next, create a connection to the datasource using the datasource name, which in this case we'll assume is foo: >>> conn = pyodbc.connect('DSN=foo;UID=username;PWD=password')
If you don't get any errors, the connection was successful. Next, create a cursor on that connection: >>> cursor = conn.cursor()
Now we can execute a query again…

Creating a Datasource with FreeTDS and unixODBC

In a couple of previousposts I've been working up to using Python to talk to SQL Server from Linux. There are a few moving parts involved so I'm documenting as I go.

Thus far I've done the following: Installed unixODBCInstalled FreeTDSInstalled pyodbcInstalled pymssql Note that pyodbc and pymssql accomplish the same thing in slightly different ways, and I'll document both as I get those set up.
To put the first two items above in perspective, unixODBC provides the underpinnings for the ODBC API on Unix/Linux platforms. unixODBC does not, however, provide what you need to talk to specific databases. For that you need ODBC drivers for each database with which you wish to communicate, which is where FreeTDS comes in.
FreeTDS is an implementation of the Tabular Data Stream protocol, which is the protocol used by SQL Server (and Sybase), and FreeTDS includes ODBC libraries that you can install in unixODBC. So when you put these two pieces together, you can talk to SQL Server…

FreeTDS Quick Start

This is the first of a couple of follow-ups to my last post which covered how to install pyodbc on Ubuntu. The ultimate goal here is to be able to use Python (my new development weapon of choice) to communicate with SQL Server from GNU/Linux (specifically Ubuntu).

Part of this equation is to install FreeTDS, which is a set of C libraries that facilitate talking to SQL Server from Linux. I'm still wading through both pyodbc and pymssql but from what I can tell thus far both these solutions use (or can use) FreeTDS. (Random aside: if you're familiar with jTDS that's a Java implementation of FreeTDS. And another fun fact, TDS stands for "Tabular Data Stream," which is the protocol used by the native SQL Server client from Microsoft.)

Installing and using FreeTDS is simple enough but I figured I'd take notes for my own reference and share in case they help anyone else wanting to set this up.
Installation If you're familiar with compiling and installing things…

Installing pyodbc on Ubuntu

If like me you have to begrudgingly talk to SQL Server on occasion, but you want to do so from Python on Ubuntu, you're in luck. As I'm finding is true with most things in the Python world there's a module to suit your needs.

Where SQL Server is concerned there are actually two modules available, pyodbc and pymssql, and I'm going to try both of these out to compare and contrast. In theory pymssql should be faster since it doesn't use ODBC, but pyodbc seemed as good a place as any to start.

Installation is simple enough in theory -- download the source zip and run:
python setup.py build install

On Ubuntu, however, you may run into an error or two due to missing libraries. Thankfully this is also quite easy to fix.

The specific error I ran into was:
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for Ada/C/ObjC but not for C++ [enabled by default]

The fix is to install the unixodbc libraries as well as the python-dev libraries:
sudo apt-get install …

Pidgin, SIPE, and Read Error on Ubutnu 12.04

I think I may have posted about this before but I couldn't find it, so since I was doing a clean install of Ubuntu 12.04 on one of my laptops this weekend I figured I'd write it up again.

If you're on Ubuntu 12.04, you use Pidgin (which you should -- Empathy sucks), and you need to connect to MS Lync (formerly known as Office Communicator), thankfully you can simply install the SIPE plugin for Pidgin:
sudo apt-get install pidgin-sipe

In my case I also had to specify this as the User Agent to get it to connect:
UCCAPI/4.0.7577.314 OC/4.0.7577.314 (Microsoft Lync 2010)

There's one additional wrinkle on Ubuntu 12.04, because even after installing the SIPE plugin and setting the user agent, you may see "Read error" when you try to connect.

You're never alone on the Internet -- other people have run into this too, and the solution is simple enough, but since I didn't want to have to do that every time I launched Pidgin I put that in a bash script and changed…

Notes on Practical Django Projects (Part 1)

I'm currently making my way through Practical Django Projects by James Bennett and thought I'd share some notes and errata as I go along. (Side note: If you want a paper copy of this book, it's dirt cheap at abebooks.com; just make sure to get the second edition which was published in 2008).

I've done a small amount with Python here and there in the past (writing some scripts to handle very specific tasks or that used libraries available in Python that were better than what's available in Java) and always really liked the language, but I haven't ever looked into building webapps with Python until now.

So far I'm quite impressed. Having worked with Grails a little in the not-too-distant past I'm finding Django to be similar conceptually but a little simpler, and it seems to be extremely well thought-out and strike an excellent balance between forcing a convention on the developer and requiring just enough to configuration to maintain a lot of flexibility…

The ColdFusion/CFML Discussion: We're Finally Getting Somewhere

I'm sure by now you've seen Joe Rinehart's "Dear John" video to ColdFusion, and Mike Henke has a funny and I think (as I'll explain in detail below) very pertinent response video.

I won't rehash everything that's been said there as well as in the various discussion outlets the past few days, but I did want to comment on the situation by saying this: after years of tiptoeing around I think we're finally getting somewhere.

For me, I saw the writing on the wall for Adobe ColdFusion about 5 years ago, and I was already planning to jump ship at that point for numerous reasons. Many of my reasons were technical ones (and sadly haven't changed in ColdFusion in 5 years), but another major reason was due to my firm belief in using free software whenever possible. All that combined with me doing a lot of open source work for a closed, proprietary platform led to cognitive dissonance I could no longer ignore.

Then in 2008 OpenBD was announced as a GPLv3-…

The Big Migration: Moving From a Verizon Droid Bionic to a Galaxy Nexus on Straight Talk

Definitely a superlative title for what actually is a pretty simple process, but I thought I'd document what I'm doing to dump my Verizon Droid Bionic and move to an unlocked Galaxy Nexus phone. I'll spare you my complaints about Verizon and just summarize by saying they're beyond overpriced and I don't like all the evil crap they do.

What is relevant to this discussion is the fact that I am sick and tired of having my phone be controlled by a carrier. From not keeping up with new versions of Android to forcing applications on my phone that I don't want and can't delete, I'm done with it. "Famous last words" may apply here, but at this point I'll state that I will never buy another phone from a carrier.

It's worth it to pay the extra money for a phone (and in the case of the Nexus it's only about $100 more than I paid for my abandoned Droid Bionic) and have more control over the phone as well as choice of carrier. (Relevant Lifehac…