Friday, October 31, 2008

My List of VIM Commands And Shortcuts

I would like to start compiling a list of common commands and shortcuts I'm using for VIM. Sometimes I forget what I have specified in my _vimrc file. This list is going to remind me and will build up in time.

Shortcut/Command Meaning
:TOhtml Convert code to html
<F3> for :TlistToggle Open up tag list (code browser plugin)
<F4> for :NERDTreeToggle Open up NERD Tree Explorer (file and directory explorer plugin)
<F5> Run programs
,pt Perl Tidy
Alt + C Block comment/uncomment using EnhancedCommentify
,cl Block comment using NERD Commenter
,cu Block uncomment using NERD Commenter
,c<spacebar> Toggle comment/uncomment using NERD Commenter
zfm Create fold of movement m
zo, zc, zd open, close, delete fold
:PrettyXML XML nice formatting

PIVOT Is Elegant Solution In Summarizing Data

Project I'm working on has to do with counting how many machines are being used in our environment. In our database, I'm able to list data like the following:

LocationCode MachineType MachineStatus
SJO Desktop Production
SJO Notebook Production
FSK Desktop Factory
TMP Desktop Production
AUS Notebook Production
TMP Desktop Factory
FSK Notebook Production
SJO Desktop Production
FSK Desktop Production

Now I need to provide a summary like as follows:

Category San Jose Fishkill Tempe Austin
Qualified Desktop 2 1 1 0
Qualified Notebook 1 1 0 1
Factory Desktop 0 1 1 0

Here's the solution using PIVOT:

SELECT
    Category AS [Category],
    [AUS] AS [Austin],
    [FSK] AS [Fishkill],
    [SJO] AS [San Jose],
    [TMP] AS [Tempe],
    [AUS]+[FSK]+[SJO]+[TMP] AS [Total]
FROM
    ( SELECT
    LocationCode,
    (CASE
        WHEN MachineStatus = 'Production' AND MachineType = 'Desktop' THEN 'Qualified Desktop'
        WHEN MachineStatus = 'Production' AND MachineType = 'Notebook' THEN 'Qualified Notebook'
        WHEN MachineStatus = 'Factory' THEN 'Factory Desktop'
    END) AS [Category]
    FROM V_PcCount_Hardware) AS SourceTable
PIVOT
(
    COUNT(LocationCode)
    FOR LocationCode IN([AUS], [FSK], [SJO], [TMP])
) AS PivotTable

Tuesday, October 21, 2008

Lesson on Multiplicity

One concept in relationships is what is called Multiplicity. It shows the number of objects that can participate in a relationship.

To illustrate, here are some examples:

Relationship Example
One To One One class occupies one classroom
One To Many One teacher teaches many classes
Many To Many One teacher teaches many students. One student learns from many teacher. So in short, it's 2 One To Many relationships combined.

Tuesday, October 14, 2008

Practical Django Projects - TinyMCE Integration Issue

Following James Bennett's book, I got stalled in Chapter 3 (Customizing The Simple CMS) when I tried to integrate TinyMCE. The solution is rather simple, just move the tiny_mce entry in the urlpatterns one line up.

Here's my urls.py:
from django.conf.urls.defaults import *

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    # Example:
    # (r'^cms/', include('cms.foo.urls')),

    # Uncomment the admin/doc line below and add 'django.contrib.admindocs'
    # to INSTALLED_APPS to enable admin documentation:
    # (r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
    (r'^admin/(.*)', admin.site.root),
    (r'^tiny_mce/(?P<path>.*)$', 'django.views.static.serve',
        { 'document_root':'C:\\dev\\python\\django\\media\\tinymce\\jscripts\\tiny_mce' },),
    (r'', include('django.contrib.flatpages.urls')),
  
)

By the way, this, this and this are excellent in outlining the code changes from Django 0.96 to 1.0, which should coincide with the book.