A Django site.
May 21, 2008

Scott Paul Robertson
spr
Spr: The Ramblings
» Yet More Blog Upgrades

Well I've added a few more improvements to the blog software.

  1. Drafts can now be viewed on a login restricted url.
  2. The README file now has details of template tags, an example blog.html, and the CSS used.
  3. Improved doc strings so you can read template tag info in the admin.

There are other things I'd like to see, but this works well for now.

May 20, 2008

Scott Paul Robertson
spr
Spr: The Ramblings
» Updates to the Blog Code

I've made some updates to the software that runs this blog. A few changes that make for good reasons to update:

  1. The subtitle block no long adds the <h2> tag. You'll need to adjust your blog.html to put tags around the subtitle block.
  2. Fixed the way it references your settings. I'm now doing it correctly by writing from django.conf import settings.
  3. Some minor other cleanup.

Share and Enjoy.

May 19, 2008

Kevin Kubasik
nonic
For Once I Oneder
» Bazaar and its Rockage

So, I think most of the open source world has agreed that the DRCS model fits our working style better than the traditional model pushed by SVN and CVS etc. And in this DRCS world we have rallied around 3 main tools: Bzr, hg, and git. And in an even greater display of complacency we have given those 3 tools quick and general classifications that became obsolete almost a year ago. Bzr is user friendly but slow and technologically inferior, hg is the champion of the middle but with slow development and a lackluster community, git is wicked fast and ‘The Right Way’TM but a pain to use.

Really? Come on guys, those molds were cast almost a year and a half ago, isn’t it time we looked at things again? Git has an entirely new interface, hg has a slew of plugins/extensions, and bzr has a completely new repo format, and network protocol, resulting in a massive speedup. Now I’m not claiming to be some unbiased source, and comparing 3 incredibly robust tools is not my job, but given the amount of support that Git receives from its very vocal supporters makes me feel a need to give props to my favorite DRCS system: Bazaar.

That’s right, Bazaar (or bzr) is awesome. Sure, git is awesome too, and so is mercurial, but I have found myself loving bzr. I’m not going to attack other DRCS tools, I just want to extol the awesomeness that is bzr.

1) Bzr is Python-Tastic! - As a python hacker, being able to utilize a robust API and plugin system is a cool plus, this also generates lots of powerful and complete plugins, which leads me to the next point.
2) Bzr has a ton of plugins! - Plugins like bzr-avahi (allows the discovery of branches on a local network, great for sprints/hackfests), bzr-svn (makes working with upstream repositories easy as pie!), quilt and gtk tools.
3) Bzr works on Windows - Yeah, I’m not a huge fan of accommodating Windows users, but it makes collaboration easier, I don’t have to make my roommate boot into Ubuntu to lend a hand with some CSS bugs.
4) Bzr is easy to share - The ability to push branches to some central repo is a big component of distributed development. While patches work in some cases, most of the time, having access to a branch makes the whole system work better. Both Git and Hg require a bit of work to set up a new repo and push a branch, bzr supports a ton of protocols and can create the target directory/repo with one command. Sharing is easy!
5) Bzr is fast - Maybe others are faster, maybe it could be a million times faster, I dunno. What I do know is the only thing I seem to wait on is my net connection… I realize that many people need more than that. So here you go. http://bazaar-vcs.org/Benchmarks
6) Bzr is small - In my development model (a shared repo with branches inside of it) bzr is compact and aware of disk space, without repositories it might be huge, I dunno.
7) Bzr is clear about whats happening - I can follow what Bzr is trying to do with my code. A branch is a new directory, and I can always see my code. Not only is this comforting/reassuring, but I often utilize IDE’s like Wing, Eclipse, or Monodevelop when working on code, and while they can handle other systems, directories for branches translates to every editor and works well.
8) Bzr is reliable - A massive suite of unit-tests and a commitment to their excellence offers some comfort that I won’t be left holding half of my code in one hand and an ugly binary blob in the other.
9) Most of all, its a feeling. Its hard to explain, but I don’t notice bzr. Its just there, and I just have my code. I rarely take notice of it, and don’t focus on it. I spend 99% of my time coding and every 30 min I enter a terminal for a few seconds to do all my DRCS stuff. Maybe its why people who use Bzr aren’t very vocal about it. Its not a revolution in revision control, and I don’t do a million cool things in it. I just write code, and bzr is there, doing whatever it does.

May 17, 2008

Seth House
nonic
Esoteric Rubbish
» Pimping out your .pythonrc.py

I don’t wanna be hatin’ on IPython, but I don’t use it. I often favor fairly extreme minimalism in computing. Why install something if you can accomplish the same (or good enough) with what you have available? IPython has quite a lot of features and syntactic-sugar, but it is overkill for my needs. Instead I’ve been slowly crafting my ~/.pythonrc.py [...]

May 11, 2008

John Anderson
sontek
sontek ( John M. Anderson )
» Python with a modular IDE (Vim)

On Thursday, May 9th, 2008 the Utah Python User Group decided to settle the debate that has plagued us developers since the beginning of time: If you were a programming language, what editor would you use?

I was tasked with showing Eclipse with the PyDev plugin in all its glory–but we all know–real men / developers don’t use IDE’s, so we are going to talk about using Python and Vim together, reaching a state of Zen that the Dalai LLama would be jealous of and establishing more Feng Shui than Martha Stewart’s Kitchen.

Freely jump between your code and python class libraries

There are 2 ways to add your ability to jump between python class libraries, the first is to setup vim to know where the Python libs are so you can use ‘gf’ to get to them (gf is goto file). You can do this by adding this snippet to your .vimrc:

python << EOF
import os
import sys
import vim
for p in sys.path:
    if os.path.isdir(p):
        vim.command(r"set path+=%s" % (p.replace(" ", r"\ ")))
EOF

With that snippet you will be able to go to your import statements and hit ‘gf’ on one of them and it’ll jump you to that file.

Continuing accessibility of the Python class libraries we are going to want to use ctags to generate an index of all the code for vim to reference:

$ ctags -R -f ~/.vim/tags/python.ctags /usr/lib/python2.5/

and then in your .vimrc

set tags+=$HOME/.vim/tags/python.ctags

This will give you the ability to use CTRL+] to jump to the method/property under your cursor in the system libraries and CTRL+T to jump back to your source code.

I also have 2 tweaks in my .vimrc so you can use CTRL+LeftArrow and CTRL+RightArrow to move between the files with more natural key bindings.

map <silent><C-Left> <C-T>
map <silent><C-Right> <C-]>

You can also see all the tags you’ve been to with “:tags”

Code Completion

To enable code completion support for Python in Vim you should be able to add the following line to your .vimrc:

autocmd FileType python set omnifunc=pythoncomplete#Complete

but this relies on the fact that your distro compiled python support into vim (which they should!).

Then all you have to do to use your code completion is hit the unnatural, wrist breaking, keystrokes CTRL+X, CTRL+O. I’ve re-bound the code completion to CTRL+Space since we are making vim an IDE! Add this command to your .vimrc to get the better keybinding:

inoremap <Nul> <C-x><C-o>

Along with code completion, you will also have call tip support. Here is a screenshot:

Vim with Code Completion
Documentation

No IDE is complete without the ability to access the class libraries documentation! You’ll need to grab this vim plugin. This gives you the ability to type :Pydoc os.path or use the keystrokes <Leader>pw and <Leader>pW to search for the item under the cursor. (Vim’s default <Leader> is “\”). Here is a screenshot:

Vim with PyDoc integration

Syntax Checking

Vim already has built in syntax highlighting for python but I have a small tweak to vim to give you notifications of small syntax errors like forgetting a colon after a for loop. Create a file called ~/.vim/syntax/python.vim and add the following into it:

syn match pythonError "^\s*def\s\+\w\+(.*)\s*$" display
syn match pythonError "^\s*class\s\+\w\+(.*)\s*$" display
syn match pythonError "^\s*for\s.*[^:]$” display
syn match pythonError “^\s*except\s*$” display
syn match pythonError “^\s*finally\s*$” display
syn match pythonError “^\s*try\s*$” display
syn match pythonError “^\s*else\s*$” display
syn match pythonError “^\s*else\s*[^:].*” display
syn match pythonError “^\s*if\s.*[^\:]$” display
syn match pythonError “^\s*except\s.*[^\:]$” display
syn match pythonError “[;]$” display
syn keyword pythonError         do

Now that you have the basics covered, lets get more complicated checking added. Add these 2 lines to your .vimrc so you can type :make and get a list of syntax errors:

autocmd BufRead *.py set makeprg=python\ -c\ \"import\ py_compile,sys;\ sys.stderr=sys.stdout;\ py_compile.compile(r'%')\"
autocmd BufRead *.py set efm=%C\ %.%#,%A\ \ File\ \"%f\"\\,\ line\ %l%.%#,%Z%[%^\ ]%\\@=%m

You will have the ability to to type :cn and :cp to move around the error list. You can also type :clist to see all the errors, and finally, sometimes you will want to check the syntax of small chunks of code, so we’ll add the ability to execute visually selected lines of code, add this snippet to your .vimrc:

python << EOL
import vim
def EvaluateCurrentRange():
eval(compile('\n'.join(vim.current.range),'','exec'),globals())
EOL
map <C-h> :py EvaluateCurrentRange()

Now you will be able to visually select a method/class and execute it by hitting “Ctrl+h”.

Browsing the source

Moving around the source code is an important feature in most IDE’s with their project explorers, so to get that type of functionality in vim we grab the Tag List plugin. This will give you the ability to view all opened buffers easily and jump to certain method calls in those buffers. Here is a screenshot of it in action:

Vim TagList Plugin

The other must-have feature of an IDE when browsing code is being able to open up multiple files in tabs. To do this you type :tabnew to open up a file in a new tab and than :tabn and :tabp to move around the tabs. Add these to lines to your .vimrc to be able to move between the tabs with ALT+LeftArrow and ALT+RightArrow:


map <silent><A-Right> :tabnext<CR>
map <silent><A-Left> :tabprevious<CR>

Debugging

To add debugging support into vim, we use the pdb module. Add this to your ~/.vim/ftplugin/python.vim to have the ability to quickly add break points and clear them out when you are done debugging:

python << EOF
def SetBreakpoint():
    import re
    nLine = int( vim.eval( 'line(".")'))

    strLine = vim.current.line
    strWhite = re.search( '^(\s*)', strLine).group(1)

    vim.current.buffer.append(
       "%(space)spdb.set_trace() %(mark)s Breakpoint %(mark)s" %
         {'space':strWhite, 'mark': '#' * 30}, nLine - 1)

    for strLine in vim.current.buffer:
        if strLine == "import pdb":
            break
    else:
        vim.current.buffer.append( 'import pdb', 0)
        vim.command( 'normal j1')

vim.command( 'map <f7> :py SetBreakpoint()<cr>')

def RemoveBreakpoints():
    import re

    nCurrentLine = int( vim.eval( 'line(".")'))

    nLines = []
    nLine = 1
    for strLine in vim.current.buffer:
        if strLine == ‘import pdb’ or strLine.lstrip()[:15] == ‘pdb.set_trace()’:
            nLines.append( nLine)
        nLine += 1

    nLines.reverse()

    for nLine in nLines:
        vim.command( ‘normal %dG’ % nLine)
        vim.command( ‘normal dd’)
        if nLine < nCurrentLine:
            nCurrentLine -= 1

    vim.command( ‘normal %dG’ % nCurrentLine)

vim.command( ‘map <s-f7> :py RemoveBreakpoints()<cr>’)
EOF

With that code you can now hit F7 and Shift-F7 to add/remove breakpoints. Then you just launch your application with !python % (percent being the current file, you can declare your main file here if its different).

Another tweak I use is to have my vim inside screen with a horizontal split, that way I can see the python interpreter and debug while still having vim there so I can easily fix my code. Here is a screenshot of that in action:

Vim with Screen

Snippets

A great time saver with stanard IDE’s is code snippets, so you can type a few key strokes and get a lot of code out of it. An example of this would be a django model, instead of typing out the complete declaration you could type ‘mmo<tab><tab>’ and have a skeleton of your model done for you. To do this in vim we grab the Snippets EMU plugin.

Check out a great screencast of snippetsEmu in action here

You can get my full setup here

Emacs

Here is a great post on how to do the same with Emacs.

May 9, 2008

Kevin Kubasik
nonic
For Once I Oneder
» Utah Python Users Group

If your in the greater Salt Lake area and love python swing by the meeting this evening! We’re doing a python editor head-to-head, should be fun!

April 28, 2008

Scott Paul Robertson
spr
Spr: The Ramblings
» Oggify 2.0 rc 2

Just a version bump of Oggify to RC 2 (tar). Re-encoding works again.

Also, if anyone has time, let me know in the comments if the standard python setup.py install worked for you with Oggify. Mention you distro, etc if you could.

April 27, 2008
» pyExcelerator (xlwt) cheatsheet (create native Excel from pure python)

If you are looking to generate/create/write (but not read) excel spreadsheets from native python (read on linux or macos or even Windows!), then xlwt (a fork of pyExcelerator) is your friend. This library, (and the ancestor) is somewhat unknown, but

April 25, 2008

Dennis Muhlestein
nonic
All My Brain
» Using Multiple Python Environments With Gentoo

It’s been some time since Python 2.5 became stable and released. Version 2.5 has plenty of new features that have helped me in deciding that it was time to go ahead and start using it for primary development of all my new projects. One of the reasons I was still using version [...]

» Lasers/Wiimotes/Python presentation at Utah Code Camp

For those in the Utah vicinity, and who want to see a cool presentation about python, wiimotes and lasers (or who really like MS products, since most sessions seem dedicated to that), my brother is presenting at Utah Code Camp. It should be a little

» [Pycon 2008] Lasers, Webcams, Wiimotes and Python Video up

My brother gave a talk about using python to detect lasers with webcams and also demo'd a prototype of a 3d game with wiimote headtracking. For those who missed the preso, there's now a video up. .flickr-photo { border: solid 2px #000000; } .fl


Kevin Kubasik
nonic
For Once I Oneder
» Speaking at UT Code Camp

So, if you live in the greater Salt Lake City area, there’s a pretty cool low key (and free!) conference coming up, the Utah Code Camp. I’ll be doing a little talk on getting data out of HTML with Python (utilizing lxml and twill). If your interested, you can register here.

April 24, 2008

Scott Paul Robertson
spr
Spr: The Ramblings
» Oggify 2.0 rc 1

I'm announcing the release of Oggify version 2.0 release canidate 1 (tar). New features: 0. I have added a small number of unit tests, which should provide more stability with updates. Additionally I've done a huge refactor of the design, which will make things much easier for me. One feature remains: re-tagging. I'm think that'll be rc 2.

April 23, 2008

Lonnie Olson
fungus
Kittypee
» Updated Rhythmbox iPod sync plugin

Due to the comments I recrived on the last post on this topic, I decided to make a few changes.

First I want to say thank you to everyone that showed interest. Apparently this type of plugin is desperately needed. My initial version was just a quick hack to transfer meta data to and from my iPod. Note the extremely hackish nature of the link between iPod and rhythmbox tracks (filename only).

Now for the changes:
  1. The most common complaint was the rhythmbox crashing bug (Segmentation Fault). This is caused by the gpod module when it attempts to locate and read the itunes database on the iPod. My fix was to just check if gpod found the itunes directory, print an error to the console, and skip any processing at all. This will prevent killing rhythmbox, but doesn’t actually fix anything.
  2. More intelligent rating updates. I used mockenh’s idea to compare last played dates to determine which rating to use in case of a conflict.

I don’t really have the desire to implement playlist, or podcast synchronization since I have very little time, and I am only a mediocre programmer at best. If someone wants to swipe my code to build on, they are more than welcome to.

Some notes about my implementation.
  1. I just use a periodic rsync to copy music from my iPod to my PC. rsync -av /media/BFUNGUS/iPod_Control/Music/ ~/Music/ Change any paths as necessary.
  2. Since I don’t copy songs to the iPod using Linux, I didn’t write that support into it
  3. The detection of the iPod mount location is dependant upon the GnomeVFS module. It must correctly recognize your iPod as a Music Player
  4. The python gpod module must be installed. Debian users can apt-get install python-gpod

ipodsync v0.2

April 17, 2008

Phil Windley
pjw
Phil Windley's Technometria
» Google App Engine at the CTO Breakfast

Not Getting Things Done
Not Getting Things Done
(click to enlarge)

There was a pretty big crowd at this morning's CTO Breakfast. Sam Curran had spent some time building an application on Google App Engine, so we had him demo his app and show us the code.

Overall, Google Apps looks like a very nice piece of infrastructure for building Web applications. The database integration with Big Table and Google's authentication platform add some good tools for quickly building applications.

We got into a pretty large discussion of the pros and cons of Google Apps, Amazon Web services, dedicated hosting, and so on. None of these services are directly competitive. They're complimentary in many respects. You could imagine many applications that would make use of all of them.

Speaking of Sam's application: a few days ago, I mentioned to Sam, Bryant and Devlin, that I liked putting things on lists because then I could get them out of my mind and if I lost the list, I never had to do them. A guilt-free way of not getting things done. The problem with online todo lists is they don't forget. I hate that! Sam picked up on that for his app and created a task list for people consumed with the guilt of unfinished tasks: Not Getting Things Done. Just put your tasks on the list and forget about them!

Tags: cto breakfast utah events web+services google python

September 6, 2007

Seth House
nonic
Esoteric Rubbish
» Freebase

I’m working on a project that required a database of video games (name, release date, box-art, etc.). Too much information to input manually, so we began looking for commercial offerings. There are two players in the field: Muze and AMG. It’s quite obvious they realize they have this market cornered, their sales representatives are the most [...]

April 11, 2007

Seth House
nonic
Esoteric Rubbish
» ReST for Markdown and Textile Users

ReStructuredText is freaking huge so users of lighter-weight markup languages can be easily put off. This is an absolute basics quickref to ReST for those kinds of users. Eye-ball the Closing at the bottom for a bit more perspective. Headers Just use non-alphanumeric characters to underline (or under-and-overline) your heading. It doesn’t matter what you use, just be consistent with the character [...]

January 28, 2007

Seth House
nonic
Esoteric Rubbish
» Learning Django with IPython

IPython is invaluable for learning Django if you don't know much about Python or anything about object-oriented prgramming.

April 2, 2008
» GSOC Project for Branch Coverage reporting for Python

As there appears to be some interest in branch coverage and the cool testing/metrics/quality tools that can be built upon it, I've proposed a GSOC project to start the ball rolling. (I assume it will start rolling either way, but allowing someone to

March 31, 2008

Kevin Kubasik
nonic
For Once I Oneder
» Back From PyCon, Break

So I just returned from my massive onslaught of travel that started with PyCon, took me from one US coast to the other, a Carribean island, and then back home to Washington D.C. I’m on Spring Break for the rest of the week, and hope to  get some good blog posts in reguarding the awesomness that was PyCon 2008!

March 25, 2008
» iSight? We don't need no stinking iSight

My brother and I have put up a blog discussing our messings with lasers, webcams, wiimotes and python. If you saw his talk at Pycon, and want to play with the code, you can find it there. I recently made the laser stuff work in Linux (hence the tit

March 21, 2008
» [Pycon 2008] Linky linky

Here's my notes on Pycon this year. I'm going to throw out a collection of links that may or may not be useful to you. If you weren't able to make the conference, hopefully this list contains a link or two that are new or interesting to you. elast

March 6, 2008
» Ask Matt: Java, PHP or Python for beginning web development?

I recently received the email below. At the risk of starting a flame war, I'm posting my response here. Hi Matthew, Sorry to bug you, but I was reading your blog and was hoping you could help me with some advice. I am new to programming and can't q

March 5, 2008

Kevin Kubasik
nonic
For Once I Oneder
» Can Someone Get Us A Real Django IDE?

So the more I work with Django the more I long for a solid development environment to work in. I use Wingware for much of my python development, with its rockin debugger and code completion, its more than I could ask for. Until the curse of the Java class. This quarter I’m taking a Java projects course, most of the class uses Eclipse but a few use Netbeans. My problem is, I got spoiled so fast by the incredible templates support, content suggestions, quick fixes and always dead on code completion. Going back to Wing feels like a halfway-there IDE. I know that pythons interpreted nature makes source completion much more difficult, now I would argue that with an interpreter, you could actually step through the code to some extent. However, I respect that dynamic objects are never gonna be easy to support. My beef is with the lack of support for super-popular frameworks (this goes for everybody!) Ruby on Rails has literally dozens of solid IDEs and a few that are just spectacular (see Aptana, or Netbeans). Why can’t I get even basic highlighting support for my Django templates? Why can’t I get any completion options on Models except my own?

Its just frustrating, Django is still a pleasure to develop in, even with just Gedit and a terminal, but is it really out of the question to consider providing a big pretty environment for those of us that like that?

I did dig up this and this. I guess its a step in the right direction, but its almost embarrassing next to the Rails environments.

February 28, 2008

Kevin Kubasik
nonic
For Once I Oneder
» PyCon 2008

So I just finalized my registration for PyCon and booked my flight! I can’t even begin to express my excitement! If anyone else plans on attending, I made a wiki page for you to add your name to!

See you there!

February 13, 2008
» Slides for Feb 2008 Utah Python Meeting

My brother is presenting tonight about his experiences with Lasers, Webcams and Python. Here's the slides (OOo format).

February 6, 2008

Kevin Kubasik
nonic
For Once I Oneder
» Gnome Twitter Applet

Gnome-Twitter LogoSo I've started following and using twitter far more than I was before. Its really a quite awesome and addictive service, and while I have noticed dozens of slick ways to update twitter, there aren't many easy ways to track your personal Timeline. I decided I wanted a more notification oriented system, so I started to hack apart the gnome-blog applet, and make a little twitter daemon who checks for new updates and uses libnotify to show some lovely notifications. Now it really only monitors feeds now, but I'm planning on hacking up some basic posting abilities in the near future. Anyways, an obligatory screenshot is below:
Gnome-Twitter Screenshot

Anyways, I'd like to vent about 3 problems I see with the state of things at Gnome.

1) Autotools! Blah! NO ONE LIKES THEM! I honestly spent about 50% of my time getting the build to work right, it was painful and a major hurdle to getting started. I know we haven''t really found something that offers the same functionality, but seriously, can't we just beef up waf or something? Not saying I have a solution, just saying we need one if we are going to continue to attract new developers.

2) Bonobo/Gnome-Panel/Applets API: Overly complicated, a pain to test/setup. What are we doing? When KDE4 just dropped the most intuitive widgeting system around on us (and Google Gadgets is popular on other platforms) why can't we take some hints from them? Don't get me wrong, some applets are best written in C and bound to a factory process. But really, for everyday hacks and widgets, we NEED a simple and powerful system, and soon. Webkit provides the perfect engine for us to work from, but we don't have to go with XHTML/CSS/JS. One of the new open Flash platforms is fine, or Moonlight could be awesome. Really, there are tons of options, the pyro desktop could be a start, I'm open to ideas.

3) Project Space: This will probably never be an official Gnome desktop project, but its kinda cool and fun, and I had to host it at Google Code (My only other real option was launchpad) we should really set something up like what fdo has with some personal Git or Hg space to store relevant, but not-yet-ready projects. The wiki is enough for pages on theme, but we need some hosting.


January 16, 2008

Dennis Muhlestein
nonic
All My Brain
» Virtual Hosting TurboGears Applications on Mac OS X Leopard

For a couple years now, I’ve been learning and applying various tricks for developing and hosting multiple Python web sites on my development machines. During that time, I made a migration to Mac OS X. Most setup files for python applications and libraries work out of the box on the Linux distributions I’ve [...]

January 10, 2008

Kevin Kubasik
nonic
For Once I Oneder
» Scripted Web Frameworks, and why Django Got it Right

So, I've been working on a few small web projects for an assortment of businesses, pretty standard fair stuff, so I've seized the opportunity to finally do something of a personal analysis of the enormous mass of web frameworks out there (Rails, TG, Django etc). Before anyone gets the wrong idea, this is _NOT_ a comparison, its an opinion. I've just been working with Django for the past several days, and I feel like I owe it a little bit of word-of-mouth.

Let me first explain, Django is really a completely different beast than either Rails or TurboGears. In my experiance, it seems that the real goal of those systems is to make sure we have to code as little as often, so massive slews of differently formatted configuration files, naming conventions and templates are really to be expected. Here's the problem, I'm a developer. I _like_ coding. Now, sometimes it is nice to design a SQL schema, and find your objects already waiting for you. Its also nice to have an authentication framework, templates are fine too, as long as its not a whole new language. The problem I started to run into fairly early on was I didn't know the 'Ruby on Rails' way to do it, but knew perfectly well how I might have done it in a chitzy CGI.

Turbo Gears wasn't much better, again, the goals of the project seems to be as little code as possible, but code is a wonderful common denominator, chances are if I'm using a python web framework, I already know python, why do I need a slew of other random file formats and templating systems? While Turbo Gears did offer an interesting GUI API (all AJAX'ed up of course) its still fairly new, and as a result, wasn't really featureful enough for my needs, and I was stuck with it, so I ventured onward.

Now, I had passed over Django initially because some reading left me with the impression that it wasn't nearly as much of a 'Magical Framework' as the other 2. It turnes out, thats what makes it rock. While Django doesn't have a flashy "Build ____ in 10 min screencast', and doesn't try to make decisions for you, its basically a nice pythonic wrapper around all the nasty bits of working with the web. Django only has 1 real config file, and its just python declarations, to handle url mapping, you get regular expressions. I know it doesn't sound glamorus, but after only an hour or so with Django, its abundantly obvious it was designed by real web developers. Theres an incredibly powerful and sleek caching system, a down right dirt easy templating system (its basically python, 20 minutes and you have it down).

I think perhaps the single most defining design decision (and one that does a great job embedding the usefulness of Django) is the lack of 'toolkit' like elements in the API. Instead, JSON and XML serialization are made fast and easy to use. Django doesn't shove a website on you, its really just a set of libraries and tools but with a little more polish and glue. Not to short what Django offers, on the contrary,  I think it brilliant. I know python, so why shouldn't I define my models in SQLObject?

<offtopic> I wanted to apologize for the blog bumps I've been having, I think a post or 2 got reposted to some Planets, I hope it wasn't too irritating! </offtopic>


January 4, 2008

Dennis Muhlestein
nonic
All My Brain
» Keeping a process running

Have you ever had a process that dies on occasion? For me, I hate that situation and prefer to fix the software as opposed to have a monitor that restarts the process when it dies. I’ve run into a case lately however, that has defied me for a solution to my dying process. [...]

January 1, 2008

Scott Paul Robertson
spr
Spr: The Ramblings
» My Blog Code

Well, I've cleaned up the Django app that runs this blog. If you look at it, you need to read the README file first. Trust me.

Highlights:

  1. Comments system that uses akismet to filter spam. After-the-fact comment filtering.
  2. RSS feeds on a per-tag basis and one of recent entries.
  3. Uses only the Django admin.
  4. Uses django-svn revision 5994. Probably broken with current versions.
  5. Shamelessly used calendar snippet.
  6. Provided templates that assume all sorts of CSS you probably aren't using! Luckily you only really need to override templates/blog/entry_abbr.html, templates/blog/entry.html, and templates/blog/calendar.html.

Available at hg.scottr.org via Mercurial: hg clone http://hg.scottr.org/blog

December 27, 2007

Scott Paul Robertson
spr
Spr: The Ramblings
» Oggify 2.0 In Progress

So it happened. I got a new album ripped and went to run Oggify on my Mac Mini. It didn't work. Audio::TagLib was no longer installed due to the OS X upgrade, and I really didn't feel like making a new, sub-par, patch. That and install TagLib again. So Oggify 2.0 is in progress. Here's an idea of the big changes to deserve a major version number bump:

  1. It's written in Python.

This change and being able to start fresh has provided a number of excellent benefits. These are also worth noting.

  1. Plugin architecture. Oggify provides a parent class, oggify.plugins.Codec, which if implemented provides everything for Oggify to use an input or output format. Currently I've got plugins done for flac as a source. Ogg and MP3 (vbr, cbr, abr) as output formats. So someone writes a file (flac.py), puts it in oggify.plugins, and then runs oggify with oggify -s flac to use it.

  2. subprocess. This is a great module for handling processes, and makes the plugin architecture easy to do. It should also make doing the GUI easy too. No more threads!

  3. 383 lines of code in the backend. This includes the plugins and all the core functions.

  4. 135 lines of code in the frontend. This is mainly just optparse code and simple task running.

  5. Complete tag copying. Audio::TagLib, as I used it, only copied the common tags. Now thanks to mutagen and my own wrapper library we have complete tag copying from format to format.

  6. Pure python. No hard to install dependencies. If you can run python, you can run oggify.

Oggify 2.0 is close to an beta release. I'd expect it by the end of the week. I'll get Mercurial repositories of Oggify and my mutagen tag_wrapper up soon as well. After this is done I'll probably start working on a python based tag management program.

December 15, 2007

Hans Fugal
no nic
The Fugue :
» Tailor, Mercurial, Leopard

I was getting this error when trying to use Tailor with Mercurial on Leopard:

Common base for tailor exceptions: 'hg' is not a known VCS kind: No module named mercurial

Mercurial was installed, so the error mystified me. Turns out to be a problem with python versions in use. Leopard's python is version 2.5.1, but mercurial from MacPorts depends on python 2.4, and so MacPorts installs python24. So when running tailor with python 2.5 and trying to load the mercurial module which is installed for 2.4, not 2.5, it naturally fails. The workaround is to run tailor with python 2.4 instead, which works fine.

#! /bin/sh
# Save as ~/bin/tailor and chmod +x
tailor=$HOME/src/tailor/tailor
exec python2.4 $tailor

November 29, 2007
» Memory profiling of python apps

A much as some gnomers don't like python ;), there's some good stuff coming from those that do. Andy Wingo writes of his work to reduce the memory footprint of the Flumotion Media Server. It is linux specific (and somewhat gnome/gtk specific), but

November 20, 2007
» MonetDB and SQLAlchemy

I've spent the past days starting a MonetDB backend for SQLAlchemy. My code is currently attached to ticket 874. We're already using SA to pull data from a proprietary db and are hoping that we can streamline some queries using MonetDB. MonetDB is

November 16, 2007

Lonnie Olson
fungus
Kittypee
» Rhythmbox iPod sync plugin

Since Rhythmbox doesn’t handle smart playlists on my iPod, my days of listening to music directly from my iPod are over.

While I do use iTunes at home to do my normal master sync, I need to have my music on my computer at work. So I simply rsync my iPod’s Music to my computer.
rsync -av --delete /media/BFUNGUS/iPod_Control/Music/ ~/Music/
Change the location of your iPod if named and/or mounted differently.

This works great. Rhythmbox found and read the tags of my music, and I have a fully functional music player. Except for one thing. I regularly use ratings and time of last play to make smart playlists. I need this data synchronized to and from my iPod.

Enter the iPodsync plugin for rhythmbox to synchronize ratings, time of last play and play count to and from the iPod. It will autodetect the iPod via GnomeVFS calls. It connects the rhythmbox API to the libgpod API to make the mesh. After installing and enabling the plugin, it will add a Tools -> Sync iPod menu item to initiate the sync. There is no other GUI yet to give you an indication of progress, but it is pretty darn quick. Any Rhythmbox GUI experts want to help out?? :)

Anyway, here it is.
Just extract this archive to your rhythmbox plugins directory (/usr/lib/rhythmbox/plugins). Restart rhythmbox, and you should be good to go.
Rhythmbox iPod Sync plugin

November 15, 2007

Adam Olsen
synic
Vimtips Lates Articles
» Django template autoescaping

Vimtips.org is running the SVN version of Django. This morning I ran an svn update, and I ran into my first API change. While looking at my site later on in the day, I noticed that both of my template filters were being HTML escaped, IE, things like < were showing up as &lt;.

My two filters are the pygments highlighting filter (you can see that in action in this article) and the filter that creates the category list at the end of every article (Under this article, it says "Filed Under: Programming, Python, Django").

Looking through the svn changelog, I noticed that they implemented a new feature, called autoescape, which will make every template variable and custom filters autoescape for safety. Using:

1
2
3
{% autoescape off %}
<a href='{{ link.url }}'>{{ link.name }}</a>
{% endautoescape %}

... you can turn off autoescaping. You can also use the Django template filter safe. As for custom filters, to make it so your returned string isn't autoescaped, you have to mark it as safe. Here I'm showing my category list filter with the new safestring.mark_safe() function:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
from django.utils import safestring

@register.filter(name='category_list')
def category_list(categories):
    """
        Shows all categories as a list of links separated by commas
    """
    c = []
    for category in categories:
        c.append("<a href='/category/%d'>%s</a>" % (category.id,
            category.name))

    return safestring.mark_safe(", ".join(c))

November 12, 2007

Scott Paul Robertson
spr
Spr: The Ramblings
» Reinteract - Graphical Python Interpreter

(via) Okay, Reinteract is just cool. Not something I need now, but in college it would have been really handy working with graphs. That and being able to plot data to audio is just icing on the cake.

» Reinteract - nifty (editable) python shell

Just watched the screencast here about Owen Taylors improved shell. Nothing revolutionary per se, but it just looks more beginner friendly (ie you can go and edit existing expressions, rather than using shell history). Kinda reminds me of the only

November 7, 2007
» Intro to python testing talk (unittest, doctest, coverage)

I'm giving an introductory talk on testing tomorrow for Utah Python. I'm planning to cover unittest, doctest, coverage and interpreting coverage results. At the end will be a hands on session for applying what we've learned. We'll write a simple p

November 3, 2007

Adam Olsen
synic
Vimtips Lates Articles
» Poignant.

As stated on his blog, Josh Simpson came up with the idea of creating a Gallery/Gallery2 replacement in Django. He's rounded up me and a couple other of our good friends to tackle this project.

The idea is to fix the problems that we find in the Gallery software, to add features that Gallery doesn't have, and to better learn Django itself. Some of the ideas that we've come up with are:

  • Phonese.cx type integration - you'll be able to send a photo from your phone to an email address, and the photo will be added to the album of your choice.
  • Tagging support
  • Comment support
  • Extensive search functionality

These are just a few of the ideas that we've had. You can find them and others at our new project page, http://www.poignant-project.org

We're really excited about this project. If you want to help, please let me know!

November 2, 2007
» Laser guns, webcams, marshmellows, python and Halloween!

My brother is the archetype of a hacker. We wasted many hours learning basic on the c64 back in the day. He used to hook up old monochrome apple monitors to stereo output and achieve some really cool visualizations. (Ben Harper's Opression is pro


Scott Paul Robertson
spr
Spr: The Ramblings
» Month of Django Tips

James Bennett is going to try to blog everyday for the month of November with a new Django tip each day. Let me just say that the first post is quite good, and I can only hope the rest of the month is filled with such useful information. His blog archives will quickly become an excellent reference.

October 31, 2007
» Gnome devs too lazy for python?

Some interesting thoughts about testing and python found among gnome developers. Joe Shaw was explaining how most new gnome apps these days are written in either python or C#. They choose C# for their app (a href="http://www.beagle-project.org/"

December 21, 2007

Dennis Muhlestein
nonic
All My Brain
» YUI Image Uploader Example with TurboGears

After completing the YUI Image Uploader, I received a lot of requests for a working example. I didn’t originally create a working example, because that requires server functionality that this server didn’t have. I’ve remedied the situation and have completed an example with TurboGears. Of course, any server side language or framework [...]

December 12, 2007

Dennis Muhlestein
nonic
All My Brain
» Similarity of texts: The Vector Space Model with Python

I’m working on a little task that compares the similarity of text documents. One of the most common methods of doing this is called the Vector Space Model. In short, you map words from the documents you want to compare onto a vector that is based on the words found in all documents. [...]

October 11, 2007
» of OpenOffice, Symphony, KOffice, rst and python

Just a few (rambling) thoughts on OpenOffice I've been having as of late. My daughter just started Kindergarten and my wife is now caught up in the PTA. So unlike the tech world, which tends to revolve around excel spreadsheets, the PTA revolves ar

September 28, 2007
» Slicing web pages with inkscape (and python)

Using the plugin Was watching this video describing how to "slice" web page designs two days ago and it inspired me. After a tiny bit of digging I found that one can easily script inkscape using python. Here's the process I've used for slicing web

September 15, 2007

Aaron Toponce
atoponce
Aaron Toponce
» Largest Palindromic Number In Python

I found the absolute best way to learn the Python programming language, while at the same time, increasing deductive logic capacity and learning mathematics. The way is through Project Euler. Of course, you don’t have to use the Python language to complete the problems. You can use any language you like, or use pencil and paper if that suits your needs best.

At any event, I’m going through the problems one by one, and have completed the first 4. The fourth problem took a great deal of thinking to get right, but I nailed it out slowly, and actually came up with a pretty fast solution. The problem is this:

A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 99.

Find the largest palindrome made from the product of two 3-digit numbers.

After hacking a bit, I realized that the only way I knew how to solve this problem, was to brute force it. Some things came to mind almost immediately:

  • I should start with 999 * 999 and count down, rather than 100 * 100 and count up, seeing as though I’m looking for the largest palindromic number.
  • 999 * 999 = 998001 iterations through every number, but I will be testing each one at least twice, so I only need to test half (999 * 999, 999 * 998, 999 * 997, … 999*100, 998 * 998, 998 * 997, … 998 * 100, 997 * 997, 997 * 996, …, etc)
  • There should a pattern with palindromic numbers to further increase my algorithm.

Point 3 was the hardest for me to find, but I found it. There is in fact a pattern with 6-digit palindromic numbers (technically speaking, any even-digit palindrome (I know that my result will be 6-digits, or at least I’m fairly confident)). Consider the palindrome “abccba”:

Let's look at the numeric column of each letter:

a(100,000) + b(10,000) + c(1,000) + c(100) + b(10) + a(1)

Adding similar variables (in algebraic notation):

100001a + 10010b + 1100c

The common denominator is 11:

11(9091a + 910b + 100c)

This means that each palindrome will be a multiple of 11.

This means that I can start with 999 * 990 for my first test, 999 * 979 for my second, 999 * 968 for my third, and so on. This will greatly reduce the number of iterations that I need to step through when finding this palindromic number. It wasn’t long, however, that I realized this problem will need to be separated into two functions. One to determine if the number is in fact a palindrome, returning either True or False, and the second function to iterate through all the possible product combinations, filling an array with nothing but palindromic numbers. Here is my solution:

#!/usr/bin/env python
def is_palin(string):
    """Returns true if a string is a palindrome"""
    start, end = 0, len(string) - 1
    while end > start:
        if string[start] != string[end]:
            return False
        start += 1
        end -= 1
    return True
 
def palindrome():
    """Finds the largest palindrome that is the product of 2 3-digit numbers"""
    num1 = 999
    result_arr = []
    while num1 > 100:
        num2 = 990
        if num2 > num1:
            num2 = num1 - (num1 % 11)
        while num2 > 109:
            if is_palin(str(num1 * num2)):
                result_arr.append(num1 * num2)
            num2 -= 11
        num1 -= 1
    result_arr.sort()
    print result_arr[len(result_arr) - 1]
 
palindrome()

A couple comments about the code. First, I’m turning the number into a string, then determining if that string is in fact a palindrome. I look at the beginning and ending letter of the string. If they match, I increase the beginning letter by 1 and decrease the ending letter by one, and test again if they match. I continue to do this throughout the string until every letter was tested. If they all passed, return True, otherwise, return False. Second, to keep my algorithm only churning through half of the required iterations, I want to make sure that I start with the square, and work down from there. For example:

View with a monospace font, or this table won't make much sense (see the original post):

999*990    998*990    997*990    ...    990*990
999*979    998*979    997*979    ...    990*979    989*979    988*979    987*979    etc.
999*968    998*968    997*968    ...    990*968    989*968    988*968    987*968
  ...        ...        ...      ...      ...        ...        ...        ...
999*121    998*121    997*121    ...    990*121    989*121    988*121    987*121
999*110    998*110    997*110    ...    990*110    989*110    988*110    987*110

The only aspect about my algorithm, was that I am not breaking out when I find the largest palindromic number. The reason for this was simple- I got too caught up in churning through every 11 numbers, that I forgot to test when I found the largest. However, after looking at the code, I figured that I was curious about all the palindromes that I have found, so I stored them in an array then sorted it ascending. It is interesting to look through the array at each one, seeing the patterns throughout.

At any rate, on my machine, I benchmarked the code:

aaron@kratos:~$ time python palindrome.py
906609

real    0m0.067s
user    0m0.068s
sys     0m0.000s

Nice and lean. 0.067 seconds isn’t bad for a first attempt, I think. Thoughts? Comments?

September 14, 2007
» Learn python with my slides, a cheatsheet, me, or a simple game

I gave my abbreviated "Intro to Python Tutorial" class last night at Utah Python Users Group. There was also a nice intro to django by Seth House and a short discussion of "Python in the Industry" by Byron Clark. So since Duncan asked for some slide

September 5, 2007

Aaron Toponce
atoponce
Aaron Toponce
» Prime Numbers In Python

The following program returns True if a number is prime or False otherwise. I am proud of this code, as it implements dead code. Upon the first positive condition in the if statement nested in the while loop, the program terminates, ignoring any further code following. As far as I can tell, this is the most efficient way (not necessarily the fastest) to test if a number is prime or not. This means that this function has an order of O(n-2) (it doesn’t test against 1 and itself) as a worst case scenario, and O(n/m) where m is the first factor of n as a best case. As elementary as it is, I think it’s pretty slick. All handled in 9 very readable lines of code.

UPDATE: Thanks to some observant readers, I have come to the realization that I only need to loop to the square root of n, and not n, as the square root of n is the largest factor. This brings the order to O(sqrt(n)-2) at the worst case scenario, and O(1) as the best case.

def is_prime(n):
    import math
    n = abs(n)
    i = 2
    while i <= math.sqrt(n):
        if n % i == 0:
            return False
        i += 1
    return True

» Howto create a pygments backend

Pygments is a source code highlighter. I believe the main purpose is to format code/markup for webpages (forums, blogs, wikis, trac, etc). (I used it on my previous post). But it also has renderers for latex, rtf and bbcode. I happened to desire

» Boilerplate for maintainable, distributable, testable python code

#! /usr/bin/env python """ canonicalcat is an example of writing a python program that perhaps you want to distribute or will be maintained over time. As such one should add documentation and this is an example of module level documen

August 1, 2007
» Does Oracle really love Rails?

If one searched for Oracle and Rails they're bound to turn up a bunch of results that appear to indicate that Oracle is on the Rails bandwagon. How Web2.0 of them. (I'm trying to think of some funny snide remark about a rails acquisition, but can't

June 16, 2007
» Silly python is_nan implementation

So apparently equality for NaN doesn't make sense. (NaN or Not a Number is division by zero, and other other operations that return non numbers, which is different than infinity or negative infinity). That makes sense, but sometimes you want to kno