Thursday, April 29, 2010

Agile Web Development with Rails 3

When I started working with rails at UW-Eau Claire I began my journey by reading Agile Web Development with Rails so I figured the best way to grasp all the changes with Rails 3 would be to purchase the updated version from Pragmatic Programers and walk through the famous "Depot" example.

Since for the last year I have been primarily fixing both rails and .net websites and have only done a few new projects I really wanted to dive head first into Rails 3. I found the Agile Web Development book to be a great way to do that.

So if your looking for a way to ramp up on Rails 3 or just to learn Rails in general stop by http://pragprog.com/ and pick up a copy of the book.

Monday, March 02, 2009

Working with Legacy Databases in Rails

While working on a presentation for the upcoming Twin Cities Code Camp. I ran into an interesting situation. I am using the Northwind database provided from Microsoft as the basis of my presentation and demo. I have found a unique situation where they are using a 5 character string as the primary key. While this is not an ideal situation I'm sure it happens with older databases. Since the goal of this presentation is to develop a rails site around an existing database I took on this challenge and after consulting with Brian Hogan we came up with a solution to this problem.

First you want to set up your model to reflect the database structure


class Customer < ActiveRecord::Base
set_table_name "Customers"
set_primary_key "CustomerID"
validates_uniqueness_of :CompanyName ##This is to make sure we don't have duplicate keys
end


Next to create the primary key you have to do some hacking. Rails likes to use database incrementing primary keys and does not let you set the primary key id so you have to create a "before_create" method as seen below.


def before_create
## CustomerID needs to be a 5 char all upcase string, to match current DB layout
self.CustomerID = (self.CompanyName.gsub(" ", "")[0,5]).upcase
end


In this method I decided to use a pattern that I noticed the primary keys following. My observation was that they were using the first 5 alpha characters of the company name and uppercasing them. So this method reflects setting the primary key "CustomerID" to the company name minus out the whitespace and taking the first 5 characters.

The reason for using a before create is you should not have to update the primary key ever as many records may be linked to that, so using a "before_create" keeps our code safe and dry.

Below is a test case for the customer table of the Northwind database using the before create method.


def test_should_be_able_to_create_customer
@customer = Customer.new(
:CompanyName => "Inacom",
:ContactName => "Chris Johnson",
:ContactTitle => "Solutions Developer",
:Address => "123 My Street",
:City => "Madison",
:Country => "USA",
:Phone => "608.555.5555",
:Fax => "608.555.5555")
assert @customer.save

assert_equal(@customer.CustomerID, Customer.find_by_CompanyName("Inacom").CustomerID)
assert_equal("INACO", Customer.find_by_CompanyName("Inacom").CustomerID)
end

Friday, February 20, 2009

Rails and Legacy Databases

I finally started to work on the actual content for the upcoming Twin Cities Code Camp. I am really struggling with a good "bad" database to use. I am looking for real world examples where you would have to work with a bad database and could not re-write it or migrate to something better.

Unfortunately for me I have one really good example (the reason for this talk) however I can not divulge the customers name and the data is sensitive make this not the ideal situation. So if anyone has any good ideas shoot them my way by contacting me at [blog] at [johnsonch] dot [com].

Thanks for the help,
-CH

Sunday, December 07, 2008

How to improve the IS field, by improving yourself as an IS professional -- Topic Essay

Over the past five years as a collegiate student, and four plus years as a professional developer and consultant, I have had the pleasure of learning many things and developing some, professional opinions on the IS industry as a whole. These opinions deal with areas that I think everyone in IS, (including myself), can improve upon. By improving in the following areas, one would both directly and indirectly improve the entire IS field.

Contributing to Open Source

There is no doubt that open source technologies are powerful and useful for even the largest companies. However, they do have a weakness; the ability to guarantee the product.

Take a look at the community you live in. Would it function without volunteers and people servicing the community? Probably not, so why should the Internet community be any different than the communities we make our homes in.

Everyone who uses any open source project should contribute to it, which is the consensus among IS professionals. Saying and doing are two different things. The situation is similar to when you become part of a new community. You need time to plug yourself in and contribute to the community. When you first move to a community, it may not be apparent how you can help. So, you wait for someone to ask for your help, or you try to get involved at a lower level. This is similar to filing bug tickets and participating in message board discussions surrounding an open source project. Most people fail to realize that by offering suggestions and reporting bugs, they are contributing to the project.

You don’t need to be a developer to contribute to a Linux distribution, or a VoIP wizard to contribute to Asterisk. You just need to use the product and communicate with other people interested in the product.

Documentation
Writing documentation is something that everyone in IS struggles with. If you do not struggle with documentation, let me in on your secret. I have been struggling with this issue myself for many years, along with other IS professionals I spoken with.

One of the major issues with documentation is how fast it goes out of date. Think of how many projects IS professionals complete every year, and how many of those are additions or revisions of current systems. There are simply too many to count.

Another contributing factor to why documentation is out of date, and hard to maintain. There are many tools out there for generating documentation from the code of an application, but that only works for what is behind the scenes. As IS professionals, we need to account for the user documentation. Users do not care about the “geocode” method, or how it sends a zip code and returns latitude and longitude and parses the data then stores it in a database table. Users care about how they can use the system to complete their job.

Over the last year, I have been working with a tool for doing this called DocBook. It is a way of using xml markup to create documents that are modularized and easy to maintain. Using DocBook has made it easier to update documentation every time I update a system. This is a good goal for any IS professional. Humans are creatures of habit, so after awhile documentation becomes a habit. Good documentation makes your life that much easier next time you have to implement a new feature or train a new user.

Not only does documentation help you; it also helps others in your organization. Having good documentation means that people will be able to figure out things on their own, giving you more time to concentrate on your job.

Building on the open source idea, writing documentation for an open source will help the quality of your own documentation, and help others in the community.

Blogging
Blogging is a form of communication that lets every IS professional communicate with other IS professionals and non-IS professionals. Blogging has improved by leaps and bounds in the last few years. Blogging allows IS professionals two ways to make themselves better and make the community a better place. The two ways are reading blogs and writing your own.

Most IS professionals will tell you it is hard to find the time every day or every week to sit down and write. By taking the time and documenting theses discoveries, you win in two ways. First by journaling your own successes and failures, you can keep a record for personal reference. I have found my own blog to be a place I consult when I am working on projects. I try to find the time to document both successes and failures and explain why something worked or didn’t work. Second by letting others, seeking help with a topic, find what you did that worked or didn’t work. I’m not suggesting that you post information about your businesses core competencies, or other things that violate ethical information sharing.

By reading and commenting on peoples blog posts, you may help them solve a problem or help others indirectly that are looking at the particular article. There have been many times where I have solved a problem from someone’s blog post, and I try to take the time to comment, even with a simple thank you. If possible, I also state the problem I was having that their solution fixed. This will help other people looking to solve problems from that particular blog post.

User Groups / Professional Societies / Conferences
Professional events such as User Groups, Professional Societies, and Conferences have two major aspects, attending and presenting. I have had the opportunity to do both over the past few years and intend to continue the trend my entire career.

Attending professional events gives you the opportunity to learn new things and network with other IS professionals. While attending “Rails Conf” this past May, I was able to meet many Rails developers that I still keep in contact with. By networking with many people in the community, I boost my respect level in the community. The best part of networking is the amount of possible job opportunities. I know quite a few people in the IS industry that would be willing to employ me if I should ever want to seek a change.

Presenting at these types of events does more than you will ever know. I cannot fully state the benefits that I have received by speaking at professional events.

One example of an event I submitted a talk idea to is the Twin Cities Code Camp (http://www.twincitiescodecamp.com). I try to find something that I really want to learn or perfect, and present on that topic. This coming spring, I am presenting “Rails and Legacy Databases”, a topic that appears to be the limiting factor of why people do not try Rails. I have run into this problem many times and have developed some tips and tricks to work in these situations. So, by presenting this topic, I can persuade people to try out a new technology to solve a problem they have. I am giving back to the community in a way that will not threaten my lively hood and will force me to understand my topic much deeper then I currently do.

Learning one new technology a year
Learning a new technology every year is a very common concept among IS professionals. This is a very broad suggestion and is quite valuable to everyone in the IS field. Think about all of the gadgets you have had over the years, and how many of them have evolved into something that can be used in business on a daily basis. From hand held games, which are similar to today’s PDA’s, to walkie-talkies that were used like we use cell phones today.

By learning a new technology, which can be anything from a new computer language to the latest gadget, you are stimulating your mind and enhancing creativity that can be used in your next project at work. I highly recommend picking a new technology each year and making it your goal to learn it, explore it and figure it out. Learning something new will help you to be a better rounded IS professional. Make sure to blog and document your experiences so others in the IS community can benefit.


80-20 Time
“80-20 Time” is a concept that 80% of your time should be spent on company-sponsored projects and 20% of your time should be spent on projects not directly related to your company.

80% projects are related to the focus of the company and drive the company’s business model, and are also considered your day-to-day projects. 20% projects are those in which you, or fellow co-workers, have an interest. These are projects that are more innovative and generally loosely related to the company or their products.

As IS professionals, we need to be creative and learning all of the time. Constant learning is required, because technology doubles every 18 months, making it almost impossible to stay on top of new technologies. Everyone needs to have a life outside of work, so by being able to use 20% of your workday to learn a new technology, or try out new ideas with an existing one, you open up the doors of creativity.

I have found it very inspirational to work on a project not related to work, but using technologies that I work with on a daily basis. Being a web software developer, I see the most rapid change in technology as the web grows. While at work, developing custom web applications, I have found the best way to get myself refocused and excited for work is to develop an application of my liking, on the side.

The most recent example is while attending “Rails Conf” 2008 in Portland, OR, my close friends and I developed a site called BoozeFindr.com. While Boozefindr is not something that my work will endorse, because they currently do not have a structured 80/20 policy, I took it upon myself to use a portion of my own time to develop this application. From developing this application, I learned how to use the Google Map API and interface with multiple geocoding services.

About a month after I developed Boozefindr, I was called upon to develop an application for a client that included geocoding and address radius calculation. I was able to complete this task faster turning more of a profit for my company. Had I never done this before, I would have spent upwards of 8 hours learning how to do this task, plus another 8 hours implementing it, like the first time. This time, I was able to complete the task in 4 hours. So I took the initial 16 hours and cut it down to 4 hours. The next time, I could implement this in far less time and pass an even grater savings on to my company.

The reason I support 80-20 time, and you should also, is I had to use personal time to learn something that I would use at work. Had I been given more time at work to play with this new technology and still qualify for billing bonuses, I would have taken that 16 hours and done that at work and been so excited that I probably still would have spent another 16 hours outside of work and been able to implement that task in my billable project in 2 hours.


There are a few ways to implement 80-20 time.
1. Dedicate 2 hours a day to personal projects
2. Dedicate 1 day a week
3. Let a developer save 20% time for use at one time

With option one, you are limited, because 2 hours a day is barely enough time to get moving. With option two, you have the ability to spend 8 solid hours on your project and make some progress, and the rest of the week on work projects. By having internal projects, your company probably has more ability to plan project deadlines around this philosophy. Option three would be best in a consulting situation; this would allow you to say “I have 4 weeks of 20 time, so I would like to be billable for the month of May working on this project” allowing you to still hit quarterly numbers.

The main key points of 20% time are:
* The project should be of interest to the employee
* The project should be approved and shown beneficial to the employer
* The project worked on in 20% time belongs to the employer

By allowing the employee to formulate a project that is of interest, they are able to use their imagination and expand creativity. By making the employer approve the project, they know what the employee is working on and have the ability to make sure it is beneficial to the company. This produces a win, win, win situation. The employee wins, because they get to do something they are passionate about; the employer wins, because they have passionate employees that are excited to come to work, and the industry wins with new ideas that can be shared from these projects.

These simple ideas are things that everyone in the IS field is capable of. If you do not feel comfortable about presenting at a conference, then attend the conference and share your ideas with smaller groups of people. If you prefer to not be social, make sure you blog about your ideas and findings. The goal is to become a better IS professional by doing things that aid the community, which makes the community better. We are all in this together and need to help each other to succeed in the world today. The key is to get involved and communicate!

Wednesday, October 22, 2008

How to improve the IS field, by improving yourself as an IS professional

Well it is that time of the year. For school the papers begin to fly and I finally get to write about a topic that I have a passion for, how to make myself better. Over the past few years I have had some very good mentors that have shown me many ways to do this and I figured it is something I should share with the world.

My paper "How to improve the IS field, by improving yourself as an IS professional" will focus on many different ways to improve yourself and by doing so will improve the field or community. One of these topics is on blogging, and while thinking about my track record of posts, I decided that it would be a good exercise to write each section as a blog post then compile everything together.

Over the next couple of weeks I will be posting more often putting my final academic thoughts out on the web for everyone to see.

I hope you will comment on these topics and debate my posts so that I can incorporate these comments into the final paper.

-CH

Friday, August 22, 2008

Bossman Gem

So I recently needed to implement a site wide search and happened to find this ruby gem at the right time (http://github.com/jpignata/bossman-gem/tree/master). I did have to mess with a few things to get it working the way I wanted it so I figured I would share my example here.

First you need to add the git hub sources and install the gem

gem sources -a http://gems.github.com
gem install jpignata-bossman


Next you'll want to create a new initializer, I called mine boss.rb and put this code in it:

require 'bossman'
include BOSSMan
BOSSMan.application_id = "your_yahoo_api_key"


Next you'll want to create a search controller in your application, then you will want put this code in the controller for your action that will handle the results.

@search = BOSSMan::Search.web("#{params[:your_form][:your_search_field]}", 0, 50)

The 50 is the number of results that you want back. I do not store the search results or do any pagination in this example.

Lastly you'll want to code up your views. Here is a sample of my results view and my search form:

*** Search Form ******

<% form_tag :action => "search_results" do %>


<%= label :search_form, :find %>:
<%= text_field :search_form, :find %>



<%= submit_tag 'Search' %>


<% end %>

*** Results View *****

<% if @search.count.to_i > 0 %>
<% @search.results.each do |result| %>


<%= link_to result.title, result.url %>

<%= result.abstract %>


<% end %>
<% else %>
No results found
<% end %>

Tuesday, May 20, 2008

New Job

So I just started my new job and moved in to an apartment for the summer before I head back to school in the fall. I figured I would post a few pictures of my new place for all those internet stalkers out there. :) Since I'll primarily be doing rails development with a little .net tossed in there look for some tidbits of knowledge I pick up along the way.

-CH

http://www.flickr.com/photos/johnsonch/sets/72157605170352155/

Wednesday, April 30, 2008

Code Camp 5

So Code Camp 5 has been announced (http://www.twincitiescodecamp.com) and once again I'll be speaking on something other than .NET to give developers some exposure to other tools that they can use to expand their knowledge. This session I am co-presenting with Brian Hogan of NAPCS (http://www.napcs.com), 'Becoming a Documentation Ninja'. The focus of our topic is using DocBook to create and manage your documentation. I have found DocBook quite interesting and it makes maintaining documentation less frustrating then using Word. As I dive more into DocBook I will keep posting my finds. Brian on the other hand has been using DocBook for awhile now working on his two books (I'm hoping are released soon).

Tuesday, April 08, 2008

Back on the blog.....

Ok so I have really been slacking lately, but hey with school and work things are really crazy. Its been a crazy week, I was able to present at Code Camp last Saturday. It was a great experience to present to such a large group. While at Code Camp I was able to talk to and meet many great people,D’Arcy Lussier, Chris Sutton, and Javier Lozano among others. It was amazing the discussions that we had there. My talk went off good and had some great people in the session that contributed to the discussion even teaching me a thing or two.

Later in the day I went to a couple different sessions about MVC and .NET. The first one was put on by Chris Sutton, it was a second part to the introduction of Microsoft's MVC Framework for ASP.NET it was very interesting and brought me closer to understanding .NET by actually being able to implement a web application in the style I like to use.

The second session I went to was put on by D’Arcy Lussier, this was a very informational session as D'Arcy skipped the powerpoint and code examples and led us in a round table discussion of .NET, MVC, and general web application theories. It was nice to hear that I'm not the only one that feels that the ASP.NET framework has brought about a mass amount of developers that don't understand statelessness.

Here is my code and slide deck from Code Camp