/code - a blog


PyOhio2011

August 09, 2011 at 10:22 AM | categories: Life | View Comments

I attended PyOhio this past weekend, a great Python conference which I was pleasantly surprised existed! After moving to Pittsburgh last year, I've been looking around for meetups and ways to meet other developers. I found Ruby, Javascript, and Python user groups but this was the first major conference I've seen in the area. I attended with a friend I met from my local Pittsburgh Python usergroup and had a blast. I would definitely recommend attending!

Several highlights for me included:

  • The talk about cmd2, an interactive command line. Expanding the command line and making things easier for myself and others has always interested me. It had some interesting ideas on how I would almost want Fabric to work. View the talk here.

  • Speaking of Fabric, there was a talk given on that also. Fabric seems to be popping up everywhere, I've even given a talk myself, viewable here! It was great to be able to compare to my talk: it seems best to give a quick rundown of Fabric and then dive into examples. Fabric's power seems hard to explain and easier to show.

  • The talk on switching from PHP to Python from Emma was great, I love high level "lessons learned" style talks. View it here.

  • One talk which I missed in person, but am glad for the great recorded videos, is the talk SQLAlchemy. It's a useful tool but seems to have such a steep learning curve. More help climbing that curve is great. View it here.

  • I won a book on algorithms in Python! Algorithms are something I've been meaning to brush up on and I love Python, so must be serendipity? This is the book, it's been great reading so far.

I'm still flipping through some of the talks I missed, definitely some good material produced from this talk and definitely worth attending next year!

Read and Post Comments

Fabric for Python Automation

June 22, 2011 at 10:33 PM | categories: Life | View Comments

I gave a talk earlier tonight at the local Python usergroup on Fabric, a Python library for "application deployment." I've mentioned Fabric before on here, documenting how to create dynamic Fabric commands.The presentation went well, but I was most interested in the reception of the talk and how I targeted the talk.

Here is my presentation.

From the Fabric docs, Fabric targets itself as a sys-admin and deployment tool. Many in the crowd had that impression as well, trying to compare it to Chef, Puppet, or Capistrano. My comparison has always been to Rake or Make, although not so much Make, in terms of working with local file dependancies and source code compilation. It's easier to start out with than Chef/Puppet, but doesn't get as complex as either program.

I view Fabric as a great automation library, for local and remote tasks. For not just automating deployment, but automating doc generation, running tests, or any Python or Bash command that you find yourself running repeatedly, remote or locally. It's applicable to any project with repeatable tasks, not just for Python projects. I will try to improve on this presentation and hopefully be able to better sell Fabric next time.

Read and Post Comments

Weekend Python Hacking

June 19, 2011 at 10:59 PM | categories: Life | View Comments

I've been able to get some time and focus this weekend to hack on a few Python side projects. In the sense of learning and self documentation, here are some things I learned:

  • Know the difference between __str__ and __unicode__ (and __repr__). Don't put Unicode in your str unless you want random unicode exceptions. An interesting snippet to get the best of both worlds:
def __str__(self):
    return unicode(self).encode('utf-8')
  • I wish Python packaging and "building a module" best practices was simply laid out somewhere. I found this guide for Ruby gems early last week and was very satisfied. One page, simple code and directory listings, best practice suggestions, from step one to published including a recommendation for testing. The closest thing I've found for Python recently has been this guide.

  • I know enough to use virtualenv + pip + a REQUIREMENTS file to build a clean environment. But damn, I'm still figuring out setuptools, distribute, distutils and distutils2. Actually, continuation of my comment above, this chapter on Python Packaging has been one of the best recent guides I've found. The whole "The Architecture of Open source Applications" book is fantastic, a great high level and detailed view into so many projects. But back to setup.py: what's required, what's not? It's a flexible wrapper that everyone does different. I'm still learning new commands for setup.py all the time. It's been frustrating.

  • Best new command setup.py command: python setup.py develop It installs a link in your site-packages to your development module, so you can use it locally. Great idea!

  • I found this skeleton repo for a suggested package layout. I like it and wish I could find more skeletons.

  • Inline class documentation: I've seen enough evidence to suggest that reStructuredText (reST acronym?) is the preferred way, for readability and generated docs. I like Javadoc syntax for Java and PHP, but haven't seen much support in Python. Kenneth Reitz's Requests HTTP library is a great, well documented, example. Related: ReadTheDocs is a fantastic site and I really love who ever launched it. Great for whenever the Django website goes down, or for viewing a specific version of docs. Viewing Django's "dev" version of the docs and finding new methods that you can't use is always annoying.

  • Reminder for personal projects: start small. I get so wrapped up in these details, that I sometimes never finish anything useful. Someone has to worry about the details, but start small and finish something useful before you go trying to fix everything you think is broken.

Read and Post Comments

Simple Sidebar Navigation with Sausage.js

May 29, 2011 at 11:41 AM | categories: Life | View Comments

Several weeks ago, a friend linked me to Sausage.js, "a jQuery UI widget for contextual pagination." I would call it more of a sidebar navigation widget. The example page was intriguing and prompted me to add it to this blog.

Requirements

My inital goal was based off the CouchDB example linked on the Sausage homepage. I was slowed down by trying to figure out the exact JS and CSS requirements, which aren't specifically listed out, and some conflicts with my local CSS for this blog, the main Sausage div requires height 100% and I had something else set to 100% height which didn't work well...

The main requirements:

Here is the main code to setup Sausage for my blog:

$(window).sausage({
    page: '.post',
    content: function (i, $page) {
        return '<span class="sausage-span">' + $page.find('h2').first().text() + '</span>';
    }
});

Bugfixing

The main thing Sausage.js provides is a sidebar that updates as you scroll, showing your current position among the main elements of the page. Great for blogs or documentation and no need to modify your current docs, since it's dynamically created on the client.

I wanted to add the ability to jump between elements, which when I looked, was broken in Sausage and I re-implemented poorly.

$.each($('.sausage'), function (i, e) {
    $(e).bind('click', function () {
        var curTop = $('h2').eq(i).offset().top;
        $(window).scrollTop(curTop - 20);
    });
});

Thanks to GitHub, I was able to easily fix the broken scrolling code, offer a fix, and get some simple navigation on the blog.

Read and Post Comments

Air Speakers For Everyone

April 11, 2011 at 09:44 PM | categories: Life | View Comments

Earlier today, the private key from Apple's Airport Express was found and released, along with some Perl code, finally allowing for anyone to create their own "Air Speaker" without using the Airport Express. With this code, any OSX or Linux computer can now be turned into an AirSpeaker, that any iPhone or iPod Touch, or iTunes, can now stream music to seamlessly. This really is fantastic because it allows a great deal of flexibility with how you play music, which has been limited for years now.

I found the hack via HackerNews and combined with some code improvments from GitHub, managed to get it working on both OSX 10.6 and Ubuntu 9.10. Here are the steps I followed:

OSX 10.6

Although the Perl code was originally designed for Linux, the Internet managed to get things running on OSX quite quickly. I found this fork of the Linux code to be easiest to install on OSX: https://github.com/albertz/shairport @ 2aace590d2099fcf83d8b94b350bcc67d8d58788

Assuming you already have XCode and Homebrew installed, the only steps you should need are:

  • brew install pkg-config libao
  • perl -MCPAN -e 'install Crypt::OpenSSL::RSA'
  • git clone https://github.com/albertz/shairport
  • cd shairport
  • make
  • perl shairport.pl should have you running!

Ubuntu 9.10

For my Ubuntu Boxee system, there were more packages to install. I used the original Linux code version, which the OSX version is forked from, at https://github.com/bbhoss/shairport @ 6e1f784b41629e88ab441f500538d45ec807e2e2. You might not need all these steps if you already have Perl installed.

  • sudo apt-get install libcrypt-openssl-rsa-perl libao2 libao-dev (Program dependencies)
  • sudo apt-get install avahi-daemon avahi-discover avahi-utils libnss-mdns service-discovery-applet mdns-scan (Avahi dependancies)
  • sudo service avahi-daemon start (you need Avahi running)
  • perl -MCPAN -e 'install Crypt::OpenSSL::RSA'
  • perl -MCPAN -e 'install HTTP::Message'
  • perl -MCPAN -e 'install IO::Socket::INET6'
  • git clone https://github.com/bbhoss/shairport
  • cd shairport
  • make
  • perl shairport.pl should have you running!

Assuming everything is working, the Air Speaker is running, and both iPhone and computer are on the same network, you should be able to select the Air Speaker like below. For me atleast, this is great because I have all my podcasts on my iPhone and really love the iPhone app Podcaster for listening and organizing my podcasts. Now I don't have to sync anything on my computer, I can keep it all on the iPhone and just play my podcasts to what ever computer I want wirelessly!

AirSpeakers

Read and Post Comments

« Previous Page -- Next Page »