Thursday, November 17, 2016

Mobile App Development

What's been happening?

For the last couple of months, I have continued looking for work. Meanwhile, I have been expanding my skill set and adding my new skills to my resume. I've also taken on a few contracts as a freelance web developer. I just released my first project for Bliss Carpet Cleaning. This project uses PHP, a language I'd only dabbled in before. I've got another PHP project in the pipelines as well as a couple of projects built on Joomla.

What's next?

I've been playing in my mind with an idea for a mobile app and my wife suggested another one a few days ago. I haven't done mobile app development before, but I've been intrigued by it for quite a while. I've got Cordova and Android Studio set up on my computer and I'm going to figure out what it takes to make a mobile app run. There's going to be a lot of reading in my immediate future and I hope to share some of what I learn here.

Why Cordova?

I chose to go with Cordova because I felt that it would be the best way for me to get a mobile solution out. As an accomplished web developer, this incorporates an existing toolset. However, I don't want a pure web app because all of my ideas rely on native functionality of the mobile device and I would need a native app or a hybrid app to access that functionality.

Wednesday, August 17, 2016

Adventures in Three.js - Part 1


Ever since I completed my undergraduate degree, I've done very little development at home. I've never had a lot of motivation to do personal projects, even though I understand some of the benefits associated with that. While personal growth is possible in a work environment, it is often stunted by deadlines, conventions, and accepted technologies. Nowhere is this more limiting than a government environment.

As a result, much of my personal growth has stemmed from the creation and refinement of pattern libraries. At each job, I would introduce patterns that would automate or simplify various tasks. Developing such patterns encourages growth because you aren't writing code to meet a specific need once, you're writing code to meet a specific need in several places. It requires forethought, asking questions like: "When will this be used?" "How might someone need to change the visual appearance?" "Is there a faster way to do this without sacrificing flexibility?" "Does the flexibility unduly increase the complexity?"

Some of the patterns I've revisited have included:

Automated tabular data display
ColdFusion provides the <cfgrid> tag to quickly dump the contents of a dataset. Unfortunately, it's a very old tag that has received few updates; it doesn't meet accessibility guidelines and doesn't allow much customization. I've often felt the need to automate this, so it is a pattern I've visited several times. The latest iteration made it easy to start with a basic dump and tweak the code until you got what you wanted. It automated pagination, creation of sort links, grouping of data, and calculating and displaying subtotals.
Form validation
This is a pattern I visited in Delphi and in ColdFusion, addressing many of the same requirements. The latest iteration of this made it easy to: ensure that required fields were not empty; ensure that values matched an accepted pattern; ensure that numeric values fell within a certain range; and ensure that values that should be unique were unique.
Database interaction
This was a pattern I attempted before exposure to CFWheels. The Model implementation by CFWheels is certainly a lot more robust, but I've had a certain amount of luck creating this pattern for myself. My own experience attempting this sort of automation has certainly taught me a lot. My latest iteration of this automatically retrieved the metadata for each field in a specified table and used that metadata to validate any data provided to those fields. It prevented the user from assigning values to calculated fields and automatically retrieved the values for calculated fields and auto-increment fields when a record was inserted or updated. It greatly simplified some of the work I was doing maintaining existing code to manipulate tables with more than 200 fields. Did it add overhead? Yes. Did it reduce development time? Significantly! Did it increase readability? Most assuredly it did.

I subscribe to a couple of newsletters that help me keep up with the web development community. You might understand how exciting it is to see how things are progressing. You might also understand how frustrating it can be if you can't use the technology or play with it much. I often couldn't utilize these technologies because they had usability issues, compatibility problems, or accessibility deficiencies. Nonetheless, I won't be able to keep up if I take the chance to play with the new technology.

What to do?

Developers tend to face some of the same problems that other creators face—writer's block—especially when starting something completely new. The more effort it takes to create a simple application that says, "Hello, world!" the harder it can be to get started. I need a project that motivates me and I need a goal. What challenge will keep me moving forward? Is there a community I can serve?

Of course, for me to get started, I need a simple goal to start with and, for me to keep going, I need to have long-term goals to strive for. My initial goal must be significant enough to overcome the initial writer's block and the long-term goals motivating enough to bring me back to the drawing board.

Dungeon Generator

I was talking with a friend about a project he was working on. He has played Dungeons & Dragons for decades and was working on a dungeon generator to learn PHP and become more familiar with AJAX. His generator works a lot like a text adventure: each room is described, but there is no overall map of the dungeon. I had toyed with this idea for a long time, having played text adventures as a kid and drawing out dungeons for my siblings to crawl, so I wanted to try a different take. Many of the dungeon generators I saw online were two-dimensional, either creating a pure two-dimensional maze and building out rooms with it or generating rooms and opening up passages between them. The deficiency, obviously, was the third dimension.

"This is the perfect opportunity for me to play with a JavaScript 3D library." I'd played with Phaser some in the past, but it doesn't do much in three dimensions. I decided to try out Three.js to see if I could get it to work. Within a week, I had a simple page that would ask for the dimensions of the dungeon, generate a pure three-dimensional maze, display that maze with Three.js, and allow you to fly around the outside of it. You can find the code on Github.

As I'm writing this, the current iteration of this code is creating 5x5x5 cubes and connecting them with corridors. The next thing I want to do is clean up the code. I want to create a Space class that encapsulates some of the code specific to a 5x5x5 space, such as displaying the space, checking for existing connections to the space, and checking to see if any nearby spaces are not connected. After I do that, I want to start building rooms out of these spaces. The easy path would dictate creating rectangular prisms, but an underground dungeon built out of a natural cavern wouldn't reflect this building technique, so I've come up with another algorithm that might simulate that better.

My aim is not only to come up with a working dungeon generator (there's a lot more to it than generating rooms and passages), but also to talk about the process. What challenges have I met? How did I overcome them or work around them? (In Dungeons & Dragons, finding a way around the challenge can also count as defeating it.)

Friday, February 26, 2016

ColdFusion Val function limitations

I was recently working with some really small numbers in ColdFusion and found that one of my typical shortcuts was actually causing me problems. Since I would retrieve information from the database and the database would return an empty string when the value was NULL, I would use ColdFusion's Val function to quickly make sure that any blank strings would become zeroes before I did arithmetic with them.

As mentioned above, the problem arose when I started working with really small numbers. As I'm sure most ColdFusion developers know, the language is loosely typed. If you want to display the value of a variable, ColdFusion transparently casts the variable as a string. If you want to perform arithmetic on a variable, ColdFusion transparently casts the variable as a number. If you want to perform date manipulation on a variable, ColdFusion transparently casts the variable as a date.

What I found regarding the Val function was that, when I was working with numbers small enough that they would be displayed in "exponent format" (a significand, followed by E, followed by the exponent), Val would only return the significand. Val was taking the string representation of the number and stopping at "E" because that is a non-numeric character. This isn't terribly unexpected, but has reduced the usefulness of the function for me.

Wednesday, December 16, 2015

Undocumented Google Calendar URL Parameter #2

While looking up information about the sprop parameter for Google Calendars, I found a Japanese page with information about adding events to Google Calendar that included the add parameter. The add parameter allows you to define additional attendees. I've tried this with email addresses. You can specify multiple email addresses by separating them with commas. Here is an example:,

I'm still looking for a parameter that allows you to specify notification times.

Undocumented Google Calendar URL Parameter #1

While doing some looking into ColdFusion components and research into RFC 5545, Google Calendars, and Yahoo! Calendars, I did some experimenting to see how much I can specify for a calendar event via URL in Google Calendars. I quickly found the action, text, desc, dates, and location parameters. Some additional looking found the sprop and trp parameters.

I opened up a new calendar event and tried to find ways to specify other portions of the form through URL parameters. I eventually found that I could use the recur parameter and specify a full RDATE or RRULE property and value string in URL-encoded format. For instance, if you wanted to create an event that repeated monthly on the second Sunday, you could add:

to the URL. That's a URL-encoded form of the following.

I didn't find this documentation anywhere else, so I'm posting it here for someone else to find.

I'm still looking for ways to specify reminders and attendees. If you know how to do either of these, let me know.

Tuesday, February 3, 2015

Discoveries in Familiar Languages #1

I love it when I'm working in a familiar programming language and find something new, particularly if that something new gives me more power or simplifies a pattern I've been using for a while. Such a discovery happened today.

Many-to-many relationship maintenance

I am constantly setting up and maintaining many-to-many relationships. I often set up the junction table to prevent duplication of relationships by adding a unique index on the appropriate key columns. Here's an example of such a junction table in MS SQL Server.

 CREATE TABLE [dbo].[ContactsGroups](  
  [keyContactGroup] [int] IDENTITY(1,1) NOT NULL,  
  [keyContact] [int] NOT NULL,  
  [keyGroup] [int] NOT NULL,  

This is a pretty typical, very simple junction table. When I need to maintain this many-to-many relationship, I've typically taken a two-step process: DELETE and INSERT. Here is an example of those two queries as they would appear in ColdFusion.

 <cfquery datasource="..." result="qry_updateContact_groups">  
 DELETE FROM [ContactsGroups]  
 WHERE ([keyContact] = <cfqueryparam cfsqltype="cf_sql_integer" value="#Form.keyContact#" />)  
 <cfif ListLen(Form.keysGroups) GT 0>  
  AND ([keyGroup] NOT IN (<cfqueryparam cfsqltype="cf_sql_integer" value="#Form.keysGroups#" list="true" />))  
 <cfif ListLen(Form.keysGroups) GT 0>  
   <cfquery datasource="..." result="qry_updateContact_groups">  
   INSERT INTO [ContactsGroups] ([keyContact], [keyGroup])  
   SELECT <cfqueryparam cfsqltype="cf_sql_integer" value="#Form.keyContact#" />, [Groups].[keyGroup]  
   FROM [Groups]  
   LEFT JOIN (  
    SELECT [keyGroup]  
    FROM [ContactsGroups]  
    WHERE ([keyContact] = <cfqueryparam cfsqltype="cf_sql_integer" value="#Form.keyContact#" />)  
   ) [ContactsGroups]  
    ON ([ContactsGroups].[keyGroup] = [Groups].[keyGroup])  
   WHERE (  
    [Groups].[keyGroup] IN (  
     <cfqueryparam cfsqltype="cf_sql_integer" value="#Form.keysGroups#" list="true" />  
   ) AND (COALESCE([ContactsGroups].[keyGroup], 0) = 0)  
   <cfcatch><!--- An exception is thrown when nothing is inserted. ---></cfcatch>  

As you can see, this involved performing a LEFT JOIN to exclude items that already exist in the table. Today, while looking up a related issue (see the comments in the <cfcatch> block), I found a much easier way to write the same INSERT query.

   <cfquery datasource="" result="qry_updateContact_groups">  
   INSERT INTO [ContactsGroups] ([keyContact], [keyGroup])  
   SELECT <cfqueryparam cfsqltype="cf_sql_integer" value="#Form.keyContact#" />, [keyGroup]  
   FROM [Groups]  
   WHERE ([keyGroup] IN (<cfqueryparam cfsqltype="cf_sql_integer" value="#Form.keysGroups#" list="true" />))  
   SELECT [keyContact], [keyGroup]  
   FROM [ContactsGroups]  
   WHERE ([keyContact] = <cfqueryparam cfsqltype="cf_sql_integer" value="#Form.keyContact#" />)  
   <cfcatch><!--- An exception is thrown when nothing is inserted. ---></cfcatch>  

Note the use of the EXCEPT keyword. This operates very similarly to the UNION keyword, but performs practically the opposite operation. Instead of creating a result set with the results of the first query followed by the results of the second query, it creates a result set with the results of the first query excluding results matching those of the second query. It performs the same task I was doing before, but it's more concise and (bonus!) more readable.

Sunday, May 25, 2014

Confessions of a Type 2 Developer

I recently read an article that divided workers into two types and illustrated the second type with a story about a child building a sand castle. I can't remember if this was a blog post or a Facebook post. I'll try to outline the gist of what I remember about the two types of workers.

Two Types of Workers

We visit a small, undeveloped village built about a mile away from a small river. Every day, the men of the village go down to the river and retrieve water, filling cisterns with what they bring back. These cisterns are used to draw water for the people to drink or water their crops. Most of the men (we will call them Type 1 Workers) carry back enough water to fill one cistern each. However, there is one man (we call him a Type 2 Worker) who only brings back for his family to drink and they have to rely on water others retrieve to water their crops.

The Type 1 Workers scoff at the Type 2 Worker because his contribution is so much smaller. However, one day, we see that the Type 2 Worker has completed a project that completely upsets the balance. He's built a wooden channel that diverts water from the river directly to the village. There is no more need for people to walk a mile to the river and back to get water.

The tables have turned now. The Type 1 Workers feel short-changed because they have been performing so much more work for so long, but now the Type 2 Worker is getting the attention because of his project. The Type 1 Workers have been working a lot longer and a lot harder, but the Type 2 Worker has invalidated the need to do that anymore and is getting more attention for his time-saving project.

The illustration that accompanied this story was about a child who had built a sand castle some ways up from the high tide mark. However, he wanted to have a moat and realized that, whenever he brought water up from the sea, the water was quickly absorbed by the sand. In an effort to keep water in his moat, he started digging a channel from the level of the sea to his castle. It wasn't long before more people joined in and helped him build his channel to keep water in the moat around his castle.

Two Types of Developers

As in the story above, there are also two types of developers. Most developers are Type 1 Developers who, familiar with an existing set of tools and overwhelmed by deadlines, stick with the techniques they know and write their code using those techniques. A few developers are Type 2 Developers who, frustrated with copying, pasting, and tweaking code over and over again, search for ways to simplify the process. These Type 2 Developers are meeting some of the same deadlines, but they are willing to risk missing the deadline in order to divert a little time here and there to build automation and write templates that they see as time-savers in the future. "If I can get this right, this process will be a lot easier."

I am a Type 2 Developer. I love to build tools. I was building tools from the time I was asked to build a menu-driven console application with no functions longer than ten lines (including whitespace). Where most of my classmates built switch-case statements that ran hundreds of columns wide in order to fit within the line count limitation, I built a template object that allowed me to simply write menuObject.AddCommand(funcToRun, keyTrigger) and the object handled the rest once I wrote menuObject.GetCommand(). One of my first development jobs was in a shop that used C/C++. When I was confronted with functions over 3,000 lines long, I started finding ways to reduce the line count. Since then, I have consistently looked for opportunities to build tools that reduce development time.

The trade-off is that I sometimes spend so much time working on the time-saving device that I start running into problems with my deadlines. Of course, one such as myself is never quite happy with the time-saving device. "I wonder if I can get it to do this." "I wish it could do that faster." "Let me see if I can use this technique I just read about."

There is a great sense of joy when you develop a time-saving device and other developers discover it and like what you've done. If you find yourself writing the same code over and over again and tweaking it only slightly, try finding a way to automate it and experience the euphoria that results when you use your automation time and time again.