Wednesday, December 17, 2008

VIM syntax highlighting for Perl6

Just want to take note on what I did to enable syntax highlighting in VIM for Perl6. I followed this excellent procedure. Thanks Ovid.

Then if you are using NERD_commenter.vim plugin like I do. This is the best commenter for me by the way. You need to add another file type for perl6, as follows:

elseif a:filetype == "perl6"
    call s:MapDelimiters('#', '')

Want to try Perl6? Here's how to get started in Windows.

02/19/2009: UPDATED for Parrot-0.9.1

I have my eyes on the next version of Perl. Perl6. I always wanted to somehow try it but never get the chance. Now that I'm preparing for a long holiday due to company shutdown, I want to play with it. I choose Rakudo Perl, which is an implementation of Perl6 targetting the Parrot virtual machine. As you already know, Perl6 is a set of specifications on this language. One of it's implementations is Rakudo.

Anyway, here's a procedure on how to install Perl6 on Windows XP. Rakudo Perl (Perl6 on Parrot), that is...
1. Download latest Windows build of Parrot and parrot-rakudo addon from here. Total of 2 executables.
2. Install and take all defaults.
3. Now do a smoke testing of the install:

C:\parrot-0.9.1>perl smoke_languages.pl

If returns ok, then congratulations, your rakudo install is successful. If not, then proceed with the rest of this procedure.

4. Go to C:\parrot-0.9.1\bin, create a file and call it perl6.cmd. Have it contain the following:

@echo off
rem adjust the path below to suit your environment
set PARROT_ROOTDIR=c:\parrot-0.9.1
%PARROT_ROOTDIR%\bin\parrot.exe %PARROT_ROOTDIR%\lib\parrot\languages\rakudo\perl6.pbc %*

5. Rename C:\parrot-0.9.1\bin\perl6.exe to perl6.ex_. Just to prevent .exe from running.

Update 02/19/2009, I'm still using the workaround above because when I attempted to use the perl6.exe that came with the rakudo addon, I got this error message:

C:\dev\perl6>perl6 hello.pl
"load_bytecode" couldn't find file 'PCT.pbc'
current instr.: '' pc 405 (src\classes\Object.pir:20)
called from Sub 'parrot;Perl6;Compiler;main' pc -1 ((unknown file):-1)

Since this is a work in progress, I assume that these will all be fixed in the next release.

Now the moment of truth...

C:\dev\perl6>perl6 hello.pl
Hello World!

Hurray! Success. Now I can play with perl6. I plan on looking and writing some test that I can probably contribute back. Thank you so much to you all perl6 team.

By the way, just so you know, this is just a workaround. In the procedure that I found, perl6.exe can be built using a utility called pbc_to_exe, but it didn't work for me. So instead I followed this.

In the future, my wish is to have a one-click-installer for Windows of everything Rakudo. Meaning, an installer that will install Parrot, then perl6.exe or create perl6.cmd and set the environment variable. Which also can handle upgrading to latest build. That would make it easier for people to install and use it. Thanks.

Update 02/19/2009, in parrot-0.9.1, path environment variable is automatically set during install. Then about the issue above, I logged a new ticket in parrot regarding this.

Update 02/20/2009, speedy answer from the parrot team, ticket resolved. So for V.0.9.1, you don't need the workaround outlined above. Thanks a lot parrot guys!

Tuesday, December 09, 2008

Free book: Higher Order Perl

This is one book I always wanted to have. Now, the author, Mark-Jason Dominus is giving it for free. Fantastic. Here's where you can download: http://hop.perl.plover.com/book/

Thank you very much, Mark-Jason.

Wednesday, November 26, 2008

Install sqlite3-ruby for Rails on Windows XP

A little bit of trouble when installing sqlite3-ruby on Windows. I get this error message:

C:\ruby\bin>gem install sqlite3-ruby
Building native extensions.  This could take a while...
ERROR:  Error installing sqlite3-ruby:
        ERROR: Failed to build gem native extension.

C:/ruby/bin/ruby.exe extconf.rb install sqlite3-ruby
checking for fdatasync() in rt.lib... no
checking for sqlite3.h... no

nmake

Microsoft (R) Program Maintenance Utility   Version 1.50
Copyright (c) Microsoft Corp 1988-94. All rights reserved.

NMAKE : fatal error U1073: don't know how to make 'ruby.h'
Stop.


Gem files will remain installed in C:/ruby/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.4 for inspection.

Results logged to C:/ruby/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.4/ext/sqlite3_api/gem_make.out

Here are the steps I followed to install it:
1. Download sqlite-3 and sqlitedll-3 from sqlite download.
2. Unzip the files to c:\ruby\bin. Total of 3 files, sqlite3.exe, sqlite3.dll, sqlite3.def.
3. In command line: gem install --version 1.2.3 sqlite3-ruby

C:\ruby\bin>gem install --version 1.2.3 sqlite3-ruby
Successfully installed sqlite3-ruby-1.2.3-x86-mswin32
1 gem installed
Installing ri documentation for sqlite3-ruby-1.2.3-x86-mswin32...
Installing RDoc documentation for sqlite3-ruby-1.2.3-x86-mswin32...
Enjoy...

Nice Introduction to REST

I'd like to take note of this link to a video by Joe Gregorio. It's a nice introduction to REST architectural style.

jQuery notes

Looking into jQuery. Some of my notes as I go...

It is interesting to note that for the $() function, it removes the need to do a for loop to access a group of elements since whatever put inside the parentheses will be looped through automatically and stored as a jQuery object.

Common examples on using the $() factory function:

Element Sample jQuery Meaning
tag name $('p') gets all paragraphs in the document.
id $('#some-id') gets the single element in the document that has the corresponding some-id ID.
class $('.some-class') gets all elements in the document that have a class of some-class.

Thursday, November 20, 2008

In search of... Latin Phrases

We use common phrases that are really not english but are well understood. Where do those come from really? And what do they actually mean? Next time if you encounter "et al.", "e.g.", "carpe diem", "alter ego", "alma mater", "de facto", "pro bono", they are what's called 'Latin Phrases'. Some of them are really very interesting. I listed some phrases that are very common.

If you want to access more, look at wikipedia.

Latin Phrase Literal Translation Meaning
ad hoc to this Generally means "for this", in the sense of improvised on the spot or designed for only a specific, immediate purpose.
ad interim for the meantime As in the term "chargé d'affaires ad interim" for a diplomatic officer who acts in place of an ambassador.
affidavit he asserted A legal term from Medieval Latin referring to a sworn statement. From fides, "faith".
alma mater nourishing mother Term used for the university one attends or has attended. Another university term, matriculation, is also derived from mater. The term suggests that the students are "fed" knowledge and taken care of by the university. The term is also used for a university's traditional school anthem.
bona fide in good faith In other words, "well-intentioned", "fairly". In modern contexts, often has connotations of "genuinely" or "sincerely". Bona fides is not the plural (which would be bonis fidebus), but the nominative, and means simply "good faith". Opposite of mala fide.
carpe diem seize the day An exhortation to live for today. From Horace, Odes I, 11.8. By far the most common translation is "seize the day," though carpere normally means something more like "pluck," and the allusion here is to picking flowers. The phrase collige virgo rosas has a similar sense.
caveat emptor let the buyer beware The purchaser is responsible for checking whether the goods suit his need.
circa around In the sense of "approximately" or "about". Usually used of a date.
de facto in fact Said of something that is the actual state of affairs, in contrast to something's legal or official standing, which is described as de jure. De facto refers to the "way things really are" rather than what is "officially" presented as the fact.
e.g. 'for the sake of example' Abbreviation for exempli gratia, below.
et al. 'and others' Used similarly to et cetera ('and the rest'), to stand for a list of names. Alii is actually masculine, so it can be used for men, or groups of men and women; the feminine, et aliae (or et aliæ), is appropriate when the 'others' are all female. Et alia is neuter plural and thus properly used only for inanimate, genderless objects, but some use it as a gender-neutral alternative.[4] APA style uses et al. if the work cited was written by more than two authors; MLA style uses et al. for more than three authors.
habeas corpus having the body A legal term from the 14th century or earlier. Refers to a number of legal writs to bring a person before a court or judge, most commonly habeas corpus ad subjiciendum (you may have the body to bring up). Commonly used as the general term for a prisoner's legal right to challenge the legality of their detention.
in absentia in the absence Used in a number of situations, such as in a trial carried out in the absence of the accused.
modus operandi method of operating Usually used to describe a criminal's methods.
per annum "through a year" Thus, "yearly"—occurring every year.
per capita "through the heads" "Per head", i.e., "per person". The singular is per caput ("through a head").
per diem "through a day" Thus, "per day". A specific amount of money an organization allows an individual to spend per day, typically for travel expenses.
persona non grata "person not pleasing" An unwelcome, unwanted or undesirable person. In diplomatic contexts, a person rejected by the host government. The reverse, persona grata ("pleasing person"), is less common, and refers to a diplomat acceptable to the government of the country to which he is sent.
prima facie "at first sight" Used to designate evidence in a trial which is suggestive, but not conclusive, of something (e.g., a person's guilt).
pro bono "for the good" The full phrase is pro bono publico ("for the public good"). Said of work undertaken voluntarily at no expense, such as public services. Often used of a lawyer's work that is not charged for.
qui pro quo literally qui instead of quo Unused in English, but common in other modern languages (for instance Italian, Polish and French). Used as a noun, indicates a misunderstanding.
quorum "of whom" The number of members whose presence is required under the rules to make any given meeting constitutional.
re "[in] the matter of" More literally, "by the thing". From the ablative of res ("thing" or "circumstance"). Often used in e-mail replies. It is a common misconception that the "Re:" in correspondence is an abbreviation for regarding or reply; this is not the case. The use of Latin re, in the sense of "about, concerning", is English usage.
semper fidelis "always faithful" Motto of Exeter and several other cities; more recently has become the motto of United States Marine Corps and the Swiss Grenadiers. Also the motto of the Rot-Weiss Oberhausen and Plymouth Argyle football clubs. The US Marines often abbreviate it to Semper Fi.
sic "thus" Or "just so". States that the preceding quoted material appears exactly that way in the source, despite any errors of spelling, grammar, usage, or fact that may be present. Used only for previous quoted text; ita or similar must be used to mean "thus" when referring to something about to be stated.
status quo "the situation in which" The current condition or situation. Also status quo ante ("the situation in which [things were] before"), referring to the state of affairs prior to some upsetting event (cf. reset button technique).
sub poena "under penalty" Commonly rendered subpoena. Said of a request, usually by a court, that must be complied with on pain of punishment. Examples include subpoena duces tecum ("take with you under penalty"), a court summons to appear and produce tangible evidence, and subpoena ad testificandum ("under penalty to testify"), a summons to appear and give oral testimony.
verbatim "word for word" Refers to perfect transcription or quotation.
veto "I forbid" The right to unilaterally stop a certain piece of legislation. Derived from ancient Roman voting practices.

Wednesday, November 12, 2008

Lock request time out period exceeded

Got this error today from one of my databases I'm working on. Last night I added an index to one of my tables not realizing that it may result to slow inserts. Well, as my SSIS package ran early in the morning, it's taking time for it to finish. So I had to resort to brute force to stop it. Problem is when I did that, lock for that particular table wasn't automatically released, so how do I release it? Here's how...

-- list processes which are locked
exec sp_lock

-- find out dbid of database
-- try each of the dbids to find out
-- in this case '9' is the dbid of my database
select db_name(9)

-- look for the 'TAB' (table) type
-- then kill that process
-- to find the table, try ObjId's
USE <YourDb>
SELECT OBJECT_NAME(<ObjId>)

-- now kill
kill 57

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.

Tuesday, September 23, 2008

The right combination: SSIS, Oracle and Microsoft OLE DB Provider for Oracle

It's been a while since I posted anything. I have been busy with so many things in my life. Work and family.

I would like to take note of this issue with SSIS. It took me a long time to figure this out. Thanks to this post. It gave me a clue on what's going on. In SSIS, it's very typical that when you are working on your development box, everything works fine, but the moment you deploy it to another machine, it doesn't run. Adding to complexities is when you try to schedule it via SQL Server Agent. I will probably discuss this complexity on another post, but for now, I would like to take note of the right combination when dealing with Oracle.

When I configure a new OLE DB Connection Manager, there are 2 different providers that I can choose from:

1. "Oracle Provider for OLE DB"
2. "Microsoft OLE DB Provider for Oracle".

At least in my case, one could have been probably installed when I installed Oracle client, the other one is a MS default. I think what happened initially is I assumed that either one of them should work ok, and in fact it worked ok in my dev. But deploying to the staging server, causes this error:

"SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred "Microsoft OLE DB Service Components".

The reason is because I chose "Oracle Provider for OLE DB". So eventhough the Oracle installed in my dev box is exactly the same as in the staging server, it's still possible that there is a difference. But anyway, what solved my problem? I created another OLE DB Connection Manager using the other one, "Microsoft OLE DB Provider for Oracle", issue fixed!

What gives? Anybody has an idea what the difference between the two?

Sunday, June 22, 2008

Django notes

I'm learning Django framework. Here are notes that I want to remember as I go...

Create a project:
django-admin.py startproject projectname
Start development server:
python manage.py runserver
Invoke python shell:
python manage.py dbshell
Create or update database:
python manage.py syncdb
Create a new application within a project:
python manage.py startapp appname

Friday, May 23, 2008

When talking on the phone, how do you spell?

It's hard sometimes to convey your message over the phone, at times you want to spell what you mean. Most of the time, it's hard to remember what spelling words to say. I remember before that a friend of mine who was a telephone operator then had to memorize a list of spelling words, ok so searching thru the web, I came across a page in wikipedia entitled NATO phonetic alphabet. Hey that's what I need. Oh how I love wikipedia.

NATO Phonetic Alphabet:

Letter Code Word Letter Code Word
A Alpha N November
B Bravo O Oscar
C Charlie P Papa
D Delta Q Quebec
E Echo R Romeo
F Foxtrot S Sierra
G Golf T Tango
H Hotel U Uniform
I India V Victor
J Juliet W Whiskey
K Kilo X X-ray
L Lima Y Yankee
M Mike Z Zulu

Friday, April 18, 2008

Intranet Applications with Role-based Security using Windows Authentication and SQL Server

First of all, I would like to thank ScottGu, again for a job well done on this tutorial on how to implement Windows authentication for an INTRANET website that works against a sql server database.

I recently added authentication scheme for an intranet website that I developed. There are some reports and tools that are supposed to be accessed only by some priviledged people within the organization. No login is required since this is an intranet application. But I needed a way to restrict access to some pages. The easiest way to maintain such a website is by adding a role-based security that is tied-in to Active Directory user account. Anyways, following this recipe that Scott Gu concocted, I got up and running quickly. Thank you Scott!

Btw, I translated the Visual Basic code to C# below...

private void PopulateRoleList(string userName)

    {

        if (!String.IsNullOrEmpty(userName))

        {

            RoleList.Items.Clear();

            foreach (string roleName in Roles.GetAllRoles())

            {

                ListItem roleListItem = new ListItem();

                roleListItem.Text = roleName;

                roleListItem.Selected = Roles.IsUserInRole(userName, roleName);

                RoleList.Items.Add(roleListItem);

            }

        }

    }

 

    private void UpdateRolesFromList()

    {

        foreach (ListItem roleListItem in RoleList.Items)

        {

            string roleName = roleListItem.Value;

            string userName = TxtUserName.Text;

            bool enableRole = roleListItem.Selected;

 

            if (enableRole == true && Roles.IsUserInRole(userName, roleName) == false)

            {

                Roles.AddUsersToRole(new string[] { userName }, roleName);

            }

            else if (enableRole == true && Roles.IsUserInRole(userName, roleName) == true)

            {

                Roles.RemoveUserFromRole(userName, roleName);

            }

        }

    }

 

    protected void LookupBtn_Click(object sender, EventArgs e)

    {

        PopulateRoleList(TxtUserName.Text);

        UpdateBtn.Visible = true;

        LabelRoleMembership.Visible = true;

    }

 

    protected void UpdateBtn_Click(object sender, EventArgs e)

    {

        UpdateRolesFromList();

        PopulateRoleList(TxtUserName.Text);

        PopulateRoleList(TxtUserName.Text);

    }

Friday, April 04, 2008

Features in Hardy Heron Release of Ubuntu

I can't wait for the latest version of Ubuntu named "Hardy Heron". If you are interested to see what's new in this new version look here. I have been using Ubuntu since "Hoary HedgeHog". I have used a number of Linux distros, but the first time I looked at Ubuntu, I liked it right away and stayed with it. It's the best Linux distro for me. In case you're wondering what the past and future versions of Ubuntu were called, here's a list I compiled...

Version Code Name Release Date
4.10 Warty Warthog 2004-10-20
5.04 Hoary Hedgehog 2005-04-08
5.10 Breezy Badger 2005-10-13
6.06 Dapper Drake 2006-06-01
6.10 Edgy Eft 2006-10-26
7.04 Fiesty Fawn 2007-04-19
7.10 Gutsy Gibbon 2007-10-18
8.04 Hardy Heron 2008-04-24
8.10 Intrepid Ibex 2008-10-30

Interesting to note from this list is that if you look in the version number, the first number is the year it was released, the second number after the dot is the month it was released. Based on the dates, I have been using Ubuntu for 3 years now!

Friday, January 04, 2008

Do you want charts on your webpages? Use the Google Chart API

Wow! This is excellent. If you want to dynamically create charts for your webpages, you can make use of the Google Chart API. You don't know how much money we spent in the company where I work just to create embedded charts for our webpages. Google makes this simple like as follows:

http://chart.apis.google.com/chart?cht=p3&chd=s:hW&chs=250x100&chl=Hello|World

The above snippet produces this: