jQuery DOM Elements…

Here’s the second dose of jQuery bits, with more to come in the near future.  I’ve got a few primary things I am going to point out with today’s code.  With jQuery getting a particular element, type of element, or the whole lot of a particular element is very easy.  Single line of code easy.

    <p>
        This is a sample page to show some basic jQuery operations with the DOM.
    </p>
    <p>
        The unordered list below has two list items within. When the jQuery below executes
        however the number of list items is higher because the master page includes some
        list items also.
    </p>
    <ul>
        <li><a href="http://compositecode.com">Loosely Coupled Human Code Factory Blog</a>
        <li><a href="https://partner.microsoft.com/">Microsoft Partner Network</a>
    </li></ul>
    <p>
        First set of input controls in nested between the form elements.</p>
    <form>
    <input type="checkbox" name="" />
    <input type="radio" name="" />
    <input name="" />
    <input type="button" name="" />
    </form>
    <p>
        Second set of input controls in nested between the form elements.</p>
    <form>
    <input type="checkbox" name="" />
    <input type="radio" name="" />
    <input name="" />
    <input type="button" name="" />
    </form>
    <p>
        Third set of input controls that are within the body elements but not surrounded
        by anything else.</p>
    <input type="checkbox" name="" />
    <input type="radio" name="" />
    <input name="" />
    <input type="button" name="" />
    <p>
        This last snippet of HTML I setup to show how the filter method works.</p>
    <a class="lookingFor" href="#">link</a>
    <a class="lookingFor" href="#">link</a>
    <a href="#">
        link</a>
    <a class="lookingFor" href="#">link</a> <a class="lookingFor" href="#">link</a>
    <a href="#">_</a>
    <a href="#">link</a>
    <a href="#">link</a>
    <a href="#">link</a>

    <script type="text/javascript">

        var alertMessages;

        // alerts there are X elements of type <a> and X elements of type <li>.
        alertMessages = 'Page contains ' + jQuery('a').length + ' <a> elements and ' + jQuery('li').length + ' <li> elements.';

        // searches within all form elements using a wrapper for context.
        alertMessages += '\nselected ' + jQuery('input', $('form')).length + ' inputs';

        // searches the first form element using DOM reference as the context.
        alertMessages += '\nselected ' + jQuery('input', document.forms[0]).length + ' inputs';

        // search within the body element for all input elements using an expression.
        alertMessages += '\nselected ' + jQuery('input', 'body').length + ' inputs';

        // This finds the 4 links marked with the class lookingFor out of all the <a> elements in the page.
        alertMessages += '\n' + jQuery('a').filter('.lookingFor').length + ' lookingFor links'

        // This finds the 4 links marked with the class lookingFor out of all the <a> elements in the page,
        // however it does so with a function instead.
        alertMessages += '\n' + jQuery('a').filter(function (index) { return $(this).hasClass('lookingFor'); }).length + ' lookingFor links';

        alert(alertMessages);
    </script>

The first line that is parsed together for the alertMessages variable shows a simple usage of the jQuery Selector Engine.  The jQuery uses the Sizzle (http://www.sizzlejs.com) Engine for this.  There are other options for selector style functionality, but this is the famous jQuery way.

The second, third, and fourth lines assigning to alertMessages are a simple usage of the jQuery Selector to retrieve elements within a particular context.  Review the comments in the code above for the specifics of what is being selected.

The fifth line are selecting elements with a particular class property.  In this case I’ve called the class lookingFor.  The jQuery call is using a filter function to trace the DOM and find the particular elements by the criteria.

The sixth line applies another filter method using a function.  This is kind of like using a in line delegate in C#.  As with C#, use with caution as you’ll end up with snippets of code copied and pasted everwhere if you use the in line function ability too much.

Shout it kick it on DotNetKicks.com

jQuery Starter Bits

I’m going to be doing some jQuery work over the next few months so I thought to myself, “why don’t I put my notes and such up on the blog”.  I decided that was a good idea so this is the start of those notes & other such how-to write ups.

The first thing anyone needs to do when starting to use jQuery is to reference the library.  There area  couple different ways to do this, depending on which version you want to use.

Reference Method #1

One of the most common reference methods for jQuery is to reference the latest, greatest, always updated library located at Google hosted or Microsoft hosted CDN.  With this method you just reference the particular version you are using as shown below.

<link rel="stylesheet" type="text/css" href="../../Content/Site.css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js">
</script>

The Microsoft jQuery CDN can be found here:

<link rel="stylesheet" type="text/css" href="../../Content/Site.css" />
<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jQuery/jquery-1.3.2.min.js">
</script>

Reference Method #2

The second method is to download the library from the jQuery.com Website.  Then of course reference it locally to the server you host it on.

<head runat="server">

<link rel="stylesheet" type="text/css" href="../../Content/Site.css" />
<script type="text/javascript" src="../../Scripts/jquery-1.4.1.js">
</script>

Some ASP.NET and ASP.NET MVC specific notes.

ASP.NET and ASP.NET MVC comes with version 1.4.1 included in the Scripts Directory of any ASP.NET or ASP.NET MVC Project Application Template you create/start.  This backs the new Microsoft support of the jQuery Library.

Shout it

Seattle Area Cloud Training

I’ve been pondering getting into some after hours training, maybe some weekend training sessions, or something along those lines.  My main focus that I’d like to aim for, but I’m unsure of the demand, is training for cloud computing.  I would like to offer specific sessions on Amazon Web Services or Azure and how to setup projects, use the various storage mechanisms, and good architecture practice.

My questions are:

  1. Is there demand for this?
  2. Is the demand for short 1-2 hr sessions, day long sessions, or even multi-day sessions that are all encompassing?
  3. Is there a demand for advanced level (lots of hands on coding & architectural practices – ala suggested patterns and practices)?

Please leave a comment or two in regards to this, I’d love to get a feel for this possibility and would absolutely get something started (maybe for free even).

Focus, New Focus, More Focus

Every few months I like to sit down and just figure out what technology I’m going to learn.  Since I’ve just wrapped up a project and helped wrap up another project related to Windows Azure it seemed a good time for a review of my technology path.

Projects

There were two primary projects I just wrapped up.  One was a Windows Azure Cloud based application.  This one I came in on the tail end to help with some coding and fixes.  We’ve officially rolled out the application and deployed it for use within Windows Azure.

The Project That Involved Writing Code

The application was a fairly straight forward WPF (Windows Presentation Foundation) Application that deploys via ClickOnce Technology and is stored in the Windows Azure BLOB Storage.  The cloud aspect of the application also uses SQL Azure, Dynamic Data Services and Templates with ASP.NET for management.  This application provides the administration of the core data elements while a command line tool provides administration for certain data element generation.  The command line tool actually works against REST style services provided by the ASP.NET Application with WCF (Windows Communication Foundation) hosted REST Web Services.  The web services and the ASP.NET Application are hosted within a Windows Azure Web Role.  That’s basically the overall architectural pieces without giving away any proprietary parts of what we worked on.  🙂

Overall the application uses a great slice of Microsoft technology and has been a great experience to help out with.  I really enjoy digging into the latest technology and also really like building applications for the cloud.  I see fewer and fewer reasons for Enterprise or web application to be built outside of a cloud environment.  The reasons really are dwindling.

The Project That Involved a Lot of Reading and Writing

I’m glad I have decent writing and comprehension skills because this other project that I’m wrapping up has made extensive use of these skills.  Being able to work on white papers, research, or documents that require heavy research is always fun.  It gives me a chance to sit down and really dive into some of the reasons why things work the way they do.  This adds to my grasp beyond the “just write this code because it works” syndrome.  I’ve actually had time to sit down and discuss the inner workings of the technology.

So far on the project I’ve assisted with writing 3 white papers, and multiple other documents and snippets of code samples, technical parts, and more.  It’s been a lot of learning.  When they’re released I’ll be sure to link them here for anyone interested in the material.

The Next Project

The next project starts today, which Sound Transit #545 has me headed for as I finish this entry.  This project is out at Microsoft also.  I’m looking forward to finally getting a v-Dash on campus.

The only thing I can really mention so far is that the project includes parts of the following technology;  ASP.NET, JavaScript, jQuery, and will be web based.  There may be some chance to use ASP.NET MVC, which I’d be really stoked to do.  However, ASP.NET or ASP.NET MVC will be fine by me.  In addition there will be multiple databases and some custom framework engines to work with.

The soft skills side of this project should also be exciting.  It has been about a year plus since I’ve led others directly.  On this project I’ll be doing just that, leading and mentoring some great developers.  I really look forward to stepping back into this type of role again.

Windows Azure and Sketchflow are two things I may not get to use on this gig, but I hope that maybe I can bring their use in at various phases of the project.  I’ll see as time goes forward.

Addendum

What I intend to ramp up on a lot more are the noSQL options and also Java.  I’ve got to become at least familiar with building and deploying a basic project.  It is kind of funny that I say Java, when I really should state that I need to become familiar with Eclipse, or InelliJ for Java Development.  I’m familiar with the language, have even written some snippets and work toward SOLID, which is pretty much the same for Java as C# as what OOP Language.  However I am just not familiar with the IDEs, general stack tools, and libraries that are available for Java.

In addition to noSQL and Java, one of the other bits that I intend to familiarize myself with in these technology platforms is REST based web services.  I really dig REST (literally, figuratively, and technologically), and generally prefer it over SOAP for many things.  Yes, it has its disadvantages but there are more than a few work-arounds.

Last but not least, I hope to at least create a project or two over the next few months to gain some basic familiarity with Erlang and F#.  I want some familiarity with these primarily to figure out easier ways to develop parallel processing applications.  Writing those in C# or Java seem to be an excessive foray of work by comparison, and I’d really like to be able to code up a parallel processing application in short order, versus a long order.  😉

The last bit, and more important to me than the other tidbits here are two projects that I intend to kick off and get running.  One is using the OneBusAway services and the other is a website startup style project that I’m not saying a word about yet.  These two projects will include a number of cool technologies and more project entries.  I’m sure I’ll have a goldmine of information derived from these two projects.

So that’s my personal update on projects and such, I’m off to stick my nose back in the proverbial books and start coding.

Those People That We’re Always Looking For…

I’ve been rereading Joel Spolsky’s “Smart and Gets Things Done”.  His writing style is entertaining.  I’m not always in 100% agreement with the guy, but who ever agrees 100% with anyone right?  However, Joel has a ton of things that are smart, well thought out, and when one pays heed can really help out during the course of a software project.  Since I’ve been writing on this topic lately, I figured it would be a great idea to give this a read and maybe even add my two cents to a few of his passages.

I didn’t get very far and I had already found one bit that I wanted to elaborate on.  This part was in remark to hiring college interns and the fact that the best college students are often already good programmers.

“The good news about our field is that the really great programmers often started programming when they were ten years old.  And while everyone else their age was running around playing “soccer” (this is a game many kids who can’t program computers play that involves kicking a spherical object called a “ball” with their feet (I know, it sounds weird)), they were in their dad’s home office trying to get the Linux Kernal to compile.  Instead of chasing girls in the playground, they were getting into flamewards on Usenet about the utter depravity of programming languages that don’t implement Haskell-style stype inference.  Instead of starting a band in their garage, they were implementing a cool hack so that when their neighbor stole bandwidth over their open-access Wi-Fi point, all the images on the web appeared upside-down.  BWA HA HA HA HA!”

This got me thinking.  I’d like to find programmers who have started a band, chased the girls, played soccer, flipped the images, argued the Haskell points, compiled a Linux Kernal (or two or three), and more.  I don’t want the all exclusive nerd only programmer, because today they’re often not that useful on software projects.

When I’m looking for other developers to hire and work with I want a number of things.  The technical bits are of course important, very much so, but I want to work with developers who know about all sorts of things.  I want programmers that know why financial application development pays well and non-profit work doesn’t, I want them to know about the successes and losses of business endeavors within the software industry.  Most importantly, I want them to be personable, approachable, and interested in life beyond just hacking lines of code 24/7.  Nothing wrong with the later, but that is only helpful for about 20-40% of the time on a project.

Warren Buffet looks for the criteria of “integrity, intelligence, and energy”.  I’m curious, readers out there in reader land, when you’re looking to work with a team or hire a team member what do you look for?  What are some key indicators besides the white board coding questions and technical bits?