/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

Managing Vim Buffers

July 13, 2011 at 08:21 PM | categories: Vim | View Comments

Buffers are Vim's underlying way of managing text and perhaps a little confusing to work with at first. Most GUI text editors have a direct "one window to one file" correlation. You can open multiple documents and until they are saved as disk files, they just exist on screen. Most times when I'm using Vim, there is only one window open, but I am working on multiple files and switching between them quickly, which is where buffers come in.

In Vim, a buffer represents a chunk of text you are working on. A buffer can be a file or it can be an unsaved chunk of text. When you do a :split on a single window, you have two views of the same buffer, or you can open up another file and have two buffers visible. If you open up a third file and buffer, your previous buffer will become a hidden buffer, which is where I think most confusion comes from. Every file you open becomes a new buffer. If you make changes on a file and switch to a new buffer, you have changes on a hidden buffer, which could become lost if you close Vim before you save that buffer. It's very easy and useful to have multiple buffers and split windows open, but keeping track of those buffers is important.

Managing Your Buffers

:buffers or :ls is the main command to see all buffers. :bn or :bp is buffer next/previous to switch between them. Every buffer has a number, so :buffer 1 will switch to buffer #1. But once you move to having a dozen buffers open, it becomes harder to manage. There are scripts to help with this. Several plugins offer an onscreen view of all open buffers, bufexplorer and minibufexplorer and add shortcut keys to make switching buffers easier, but I have never found that on screen display necessary.

minibufexplorer

My Old: FuzzyFinder

I've grown used to switching buffers by partial name search or most recently used (MRU) order. Simplifying that has process has been my goal in searching for a buffer plugin. FuzzyFinder solved both of those problems well.

FuzzyFinder Buffer mode

FuzzyFinder is a big plugin, offering fuzzy text searching capabilities for pretty much everything you can search for in Vim, but its buffer mode is quite useful. It's a drop down list, with last accessed time displayed and sorted by MRU. You can use CTRL+N or CTRL+P and a cursor to select the top few items easily. You can type any partial buffer name to filter the list. I've used FF for many years, but have found it slow at times and a bit quirky when closing/deleting the windows it creates. Therefore, I've moved onto Lusty.

My New: LustyJuggler

My current choice is the LustyExplorer plugin and its compliment, LustyJuggler. LustyExplorer offers a few other file opening capabilities which I will explore in another post, but its buffer mode is top notch. Display of all open buffers, order by MRU, with fuzzy text filtering capabilities and Tab to select. Simple and quick.

LustyBuffer

Vim is all about saving key strokes, so why even type out a partial filename? LustyJuggler allows you to "juggle" between open buffers, showing the last 9 used buffers with simple select using the 1-9 number keys or the asdfghjkl row of keys, for qwerty keyboard users.

LustyJuggler

Finally, one of the new features I'm still learning to use is BufferGrep: very quick grep of all open buffers.

LustyBufferGrep

I plan to cover LustyExplorer more in the future, but for now, it has been a quite useful and clean plugin. Once you have begun to get a better grasp over your buffers, you can move to tabs and vertical split windows and having access to your source code in many different ways. Feel free to share how you use buffers in the comments.

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

Vim Plugin: Tagbar

June 06, 2011 at 10:26 PM | categories: Vim | View Comments

Continuing with upgrading and explaining my Vim setup, I'm going to cover Tagbar and TagList today. Both are plugins that provide high-level views of your source code at a class and function level, similar to Eclipse, Visual Studio, or other IDEs. The view is available in a quick toggle sidebar, which you can sort and use to jump around in your source file. Both plugins make use of Ctags, which parses the source code for most popular languages.

Having a high level view is great for understanding new code, getting a quick layout of a file, and simplifying your interaction with a source file; working with classes and functions, not line numbers and searching.

The Old: TagList

TagList has been around 2002 apparently, but I've only been using it for a few years. TagList was great, but flawed in its feature. It has only ever offered a separate Class, Function, and Variable list on your source file.

TagList

It was great to place to start, but not optimal. TagList was also last updated in 2007.

The New: Tagbar

Tagbar is still a new plugin as of 2011, but offers a major improvement over TagList by displaying tags order by scope; Class first, then all its Members, then the next Class. It maintains the same keybindings as TagList: p to jump around in your file, Ctrl + N or Ctrl + P to jump between definitions. Also support for Constants and color!

Tagbar

Tagbar has been updated several times in the last few months and I haven't run into any bugs. Tagbar is definitely worth upgrading to today! Keep following me for more new Vim plugins.

Read and Post Comments

« Previous Page -- Next Page »