Sublime Text: Purchased!

Previously I talked about how I was going to experiment with moving all of my text editing to Sublime Text; this has been completed. While I still have TextMate installed I only use it to keep a “pristine” copy opened when checking changes/versions, or copy-pasting information. The ease of having one editing platform on every major OS platform that I’m programing in has been amazing, far more than I previously thought.

Whilst I didn’t think of coding as a visual medium previously I’m starting to understand that side of things a bit more. When every screen has the same look and feel it actually makes transitioning easier. I still have to go between Command and Alt for a lot of things; but that’s more on the keyboard setups than on any given application. In tracking the time I spent converting from OSX to Windows, OSX to Linux, and Windows to Linux they all went from around 15 minutes to about 3 minutes over the course of the month; the only real change being the text editors.

Since the “bundles” in Sublime Text are based on TextMate bundles I was able to get some old ones up and running very quickly. Additionally there’s a package manager that’s maintained by the community that makes installing a lot of extensions far easier to use. Getting a python lint utility and Django syntax highlighting was a breeze and has made using Django that much easier.

All in all, a worth while investment for anyone looking for a new, light-weight, flexible text editor that can pretty much do it all.

TextMate (and several others) to Sublime

Working on seeing if I can switch to Sublime Text on all platforms to make my life a little easier. So far on Linux and Windows is has held up well; OSX is a bit tricker as I still like TextMate and I’m just used to it visually for everything, which is more important than I thought before starting this experiment again.

For my test today and this next week I’m going to be loading three projects in to Dropbox and leaving the files open in three settings to go back and forth and see if it works well and if there’s less “transition” time when going between platforms/locations.

Criteria being evaluated for a successful transition:

  • Regular Expressions as seamless as TextMate
    • My frustrations with some editors and regular expressions would take weeks to type out; suffice to say I’m picky. Since it’s something I use a lot in data analysis (a large chunk of my jobs) it’s a feature that is very near and dear to me.
  • Loading project files uniformly across all platforms
  • Running commands
  • Syntax highlighting
    • Since Sublime can use TextMate bundles this should end up as a draw in a good way
  • Speed of file manipulation
  • UI Cleanliness
  • General Usability (purposely left vague for the “X” factor of all programs)
I would be remiss to not mention what the past setup had been, and it’s pretty convoluted. Keep in mind these are what I used on other systems as in OSX I use TextMate for all code development; it’s even the default editor when I use XCode.
PHP: NetBeans
Ruby: Aptana
Python: IDLE (Windows), gedit (Linux)
Java: Eclipse
At some point before the end of the month I’ll update things, or write some other articles, on my progress and transition.

Django – Insensitive Case

When using Django in Python there’s these awesome things called QuerySets that are a full blown ORM to make it so I don’t have to think in SQL to get things in and out of a database! One of the things I didn’t find documented very well was case sensitivity vs insensitivity.

If you’re using the MySQL backend the case-sensitive is implied, i.e. using BINARY LIKE instead of just LIKE

series = Series.objects.filter(name__contains=srch_str)

To make sure that you’re searching for some that’s case insensitive you can do the following:

series = Series.objects.filter(name__icontains=srch_str)

If you want it to work case insensitive no matter the backend, collation, or collection type just use icontain, istartswith, iendswith, iregex, iexact.

Django: Basic Template Tags

One of things I had the hardest time finding was a good example of Template Tags in Django; so here is my basic template tags file I add to every new project (GPLv2). A lot of people have their own, and I’m sure in the future I’ll add on to my basics; but for now these get me by. One of the things I’ve been wanting to do is write a good small primer for beginning Django, consider this my first foray in to making that a reality.

from django import template
from django.template import Variable, VariableDoesNotExist
register = template.Library()
def gVal(object, attr):
    """Check the array, dict, etc for a value"""
    quasai = { 'object' : object }
    #print "gVal :: " + str(attr) +" - "+ str(quasai)
        value = Variable('object.%s' % attr).resolve(quasai)
    except VariableDoesNotExist:
        value = None
    return value
def xVal(a,b):
    """Since Python resolves left to right in template tags: pass value and then the dick to check; returns value or 0"""
    #print "xVal",a,b
    if b.has_key(a):
        value = b[a]
        value = "0"
    return value
def hexVert(value):
    """Removes all values of # from the given string and replaces with %23"""
    if value != None:
        value = value.replace("#", '%23')
        value = value.replace("!", '%21')
        value = value.replace("&", '%26')
    return value