Tuesday, February 16, 2010

Developer's Inspiration

I have read a lot of blogs of web designers who have a post about "Sources of Inspiration" and I just wanted to through one out there for the developers.

Outdoors

The outdoors is a great way to relief stress and concentrate on a single problem. In other words, "It gives you a chance to clear away all the daily bull shit and focus on the problem at hand." When I am talking about "The Outdoors" I am not talking about having your window open while you play video games. I am referring to remote areas usually where vehicles can't go. Examples of outdoor places would be the woods, a cliff, or a lake/river. I personally find the woods to be the most beneficial because of the silence and random things that can keep your eyes busy and your mind relaxed, yet turning.

We as developers don't care that much about the looks of that app or naming things in it...even though we should. I have had many walks in the woods where I have came up with a solution for a navigation issue by just looking at how the trees where aligned, just as an example of how the outdoors have inspired me.

A few things that can create inspiration:
• Hiking/walking in the woods
• Mountain biking
• Hunting/Archery
• Golfing for pleasure.
• Lawn mowing...because you get in the zone, at least I do, and nothing else matters. Until you mow over the flowers.

Constructing Things

One word...Lego’s. Lego’s, in case you don't know, are small little bricks that fit together and you can build things out of them. Kind of like pieces of code that form an app in nerd speak. While the outdoors in the section above focus more on freedom, constructing things focuses on constraints. When you construct something you are usually limited by the resources you have available. Example you are building a bed and you only have steel, well how do you make the most out your steel to maximize the outcome of the bed. The constraints force you to be creative to solve a solution and often require you think in a different way. My uncle told me a quote once that helps describe this better than I am right now. He said, "Poverty is the fuel of innovation". Poverty is the problem and the constraint and it requires you to maximize the outcome. We as developers can relate to this easily by having very little time or resources as our constraint and a business requirement as our problem.

A few of things that can create inspiration:
• Lego’s
• Carpentry
• Chingling a roof
• Arts and crafts...if you are in to that stuff.

Kids

Kids are great for inspiration because they see things in a simple way and don't care about the complexities. Often times we only see things in a overly complex way because we are trying to account for all the bullshit one-off requirements that we are trying to satisfy. Sometimes if we break these complexities into simple pieces it helps you see the hidden path through the labyrinth of craziness. A thing that web designers do that I am going to steal because developers don't do it enough is "The drawing board." This is the concept of writing all your complexities on a white board and moving them around and fine tuning them until you can see the path. Granted sometimes you need a really big white board but it does help to break things down.

Another thing that kids do well is trying hard at something they suck at. An example of this would include watching 4th graders play basketball. The hoop is clearly too high but they don't care because they are focused at getting a basket. I was able to figure out how I could refactor an old spaghetti code app by watching some kids play basketball. Watching them help me separate the old code into modules with which I could slowing fix while keeping the old code working. How does this apply to the kids playing basketball you might ask?

The kids all crowded around the bottom of the hoop = the spaghetti code.

Pulling one kid aside and explaining to him that if you stand by the free throw line you will be open for a pass by teammate = separating the spaghetti code into modules.

Video games and movies

...nothing really to say here, we all know.

Other blogs

There is a ton of developers and designers blogging inspiration. Read them and take what you need

Monday, February 1, 2010

value-of-select inside an xslt tag's attribute

I've been work with xslt lately and ran into an issue the other day while trying to put the value of a node inside a tag's attribute while in xslt. If you know a little about xslt...this will error out because you can't have a < or > inside the attribute. So what do you do? Well in the past I have been escaping the quotes in xslt and writing a ton of code to something so little...until now. Check it out:

Here is my xml that I want to loop over.

<cfsavecontent variable="xml">


<boarders>
<boarder>
<id>1</id>
<name>Joe</name>
<board>Forum</board>
</boarder>
</boarders>


</cfsavecontent>

<!---Here I am putting the value of the id node in the href attribute of an a tag by escaping quotes. Pretty gross huh?--->
<cfsavecontent variable="xslt">
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:xdt="http://www.w3.org/2005/xpath-datatypes" xmlns:xs="http://www.w3.org/2001/XMLSchema" >
<xsl:variable name="XML" select="/"/>
<xsl:template match="/">
<html>
<head></head>
<body>
<xsl:for-each select="$XML">
<xsl:text disable-output-escaping="yes"><</xsl:text>a
href='test.cfm?id=
<xsl:value-of select="boarders/boarder/id"/>
'<xsl:text disable-output-escaping="yes">></xsl:text>
<xsl:value-of select="boarders/boarder/name"/>
<xsl:text disable-output-escaping="yes"></a</xsl:text>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
</cfsavecontent>

<cfoutput>
#xmltransform(xml,xslt)#
</cfoutput>


Now check this out. The same xslt with {} to access the node. Alot cleaner.


<cfsavecontent variable="xslt">
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:xdt="http://www.w3.org/2005/xpath-datatypes" xmlns:xs="http://www.w3.org/2001/XMLSchema" >
<xsl:variable name="XML" select="/"/>
<xsl:template match="/">
<html>
<head></head>
<body>
<xsl:for-each select="$XML">

<a href="test.cfm?id={boarders/boarder/id}"><xsl:value-of select="boarders/boarder/name"/></a>

</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
</cfsavecontent>
<a href="http://www.w3.org/TR/xslt#dt-attribute-value-template">http://www.w3.org/TR/xslt#dt-attribute-value-template</a><br/>
<cfoutput>
#xmltransform(xml,xslt)#
</cfoutput>


It, the {}, also supports xslt variables as well.


<cfsavecontent variable="xslt">
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:xdt="http://www.w3.org/2005/xpath-datatypes" xmlns:xs="http://www.w3.org/2001/XMLSchema" >
<xsl:variable name="XML" select="/"/>
<xsl:template match="/">
<html>
<head></head>
<body>
<xsl:for-each select="$XML">

<xsl:variable name="boarder_Var">
<xsl:value-of select="boarders/boarder/id"/>
</xsl:variable>
a href="test.cfm?id={$boarder_Var}"><xsl:value-of select="boarders/boarder/name"/></a>

</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
</cfsavecontent>

<cfoutput>
#xmltransform(xml,xslt)#
</cfoutput>


Use Case:
I wanted to merge some data into a set of links that the user clicks on that returns the value to an FCKeditor.

Playing with cfloop's file attribute

I was playing around with cfloop's file attribute and how it only grabs the rows you want to loop over...not the entire file. So cool. I am amazed at how well and easy it is to use. Here's what I got:

<!---data.csv--->
ID,Name,Board,Gender
1,Joe,Forum,M
2,Jamie,Nitro,F
3,Jake,Forum,M
4,Ben,Burton,M
5,Ken,Elan,M


<cfset columns = "ID,Name,Board,Gender"/>

<cfset boarders = arrayNew(1)/>

<cfloop from="2" to="6" file="C:/workspace/examples/file_looping/data.csv" index="row">

<cfset boarder = structNew()/>

<!---loop through the columns and create a struct of the row's data--->
<cfloop from="1" to="#listLen(columns)#" index="column">
<cfset boarder[listGetAt(columns,column)] = listGetAt(row,column)/>
</cfloop>

<!---append the boarder struct to the boarders array--->
<cfset arrayAppend(boarders,boarder)/>

</cfloop>

<cfdump var="#boarders#">


I put the rows in an array of structs to work with it more easily.

Use case:
It works great for imports where you want to throttle the amount of data you process at a time. Example you only want to pull records 1-99 process them, then 100-199 and so on.