10.20.08

Another Year, Another Rails Rumble

Posted in Rails, Ruby at 2:57 pm by mike

I just completed Rails Rumble with Chris and Chris. Our team was Ballmer’s Peak (here’s the reference to the source of our name) and we created an application call TightWad.

The purpose of TightWad is to give you a way to create and manage a number of budgets. In an economy like today’s, it’s important to manage and keep track of your daily spending. Any financial adviser will tell you the most important step to staying on top of your finances is to create a budget. Creating a budget is a great thing to do, but the hard part is following and managing it during your everyday life. That’s where TightWad comes in.

You can create a number of weekly or monthly budgets for yourself. Each budget has a name, short name for sending text messages, date range and spending limit. An example would be that you want to create a budget for eating out this week of $20. On the new budget page, you would enter a name of “Eating at a Restaurant” with short name “food” and date range of Monday to Sunday, and a limit of “20″.

This is where the fun starts :) Now that you have your new budget set up, you can send in payments to your budget using your cell phone. So let’s say that you have lunch at your favorite fast food restaurant. After you’ve paid for your meal, pull out your phone and text “spent 5.95 food My Favorite Restaurant” to the number 41411. Shortly after you send the message, you will get a message back saying that you have $14.05 left your account for the week. So now you can always know how much you have left in your budget.

You can also create a Recurring Budget. With a Recurring Budget you’ll automatically get a new budget every week/month with an email that let’s you know how much you can spend again. Plus it acts as a friendly reminder to keep you on budget.

I suggest you create an account and try it out for a few weeks. Let us know what you think by emailing Comments

01.14.08

Pop up Tabs

Posted in Example Code, CSS at 12:05 pm by mike

A few posts ago, I mentioned how I had implemented a different flavor of html tabs in an application I’m working on. Instead of doing a walk through, like I had been planning on, I just decided to get the code out there in the real world, as I’ve been very busy lately. First of all, you can view my demo. These tabs give another way to emphasize the selected tab, by changing the heights of the unselected tabs to be shorter. It also gives the ability to hover over an unselected tab to see more of its contents. This gives the feeling of thumbing through tabs.

So far I’ve tested this in Firefox and IE7 (Safari support coming soon, hopefully).

I’ve made the source and images available for easy download.

A few things to note about the styling of these tabs:

  • I’m using transparent PNGs for the shadows, so they aren’t particularly friendly with IE 6 without the PNG patch (not included).
  • The height of the image files is important. Because the tabs become partially hidden, the relative position of the bottom shadow is measured from the top of the tab. So when the height of the tab is changed, the height of the shadow image should be changed as well.
  • The tabs are actually hidden more than I would do on a normal site. This is simply to demonstrate how well it works, and how hidden the tab can be. For normal use, I suggest only hiding about 4 to 5 pixels, depending on padding.

I hope everyone likes how these work. Comments and feedback are always appreciated.

01.01.08

A new year, a new life

Posted in Uncategorized at 5:14 pm by mike

Happy New Year’s everyone! Since New Year’s Eve is my birthday, the new year always has a special meaning to me. Along with the new year, I get a new age. But this year means the beginning of the next chapter in my life. I finally graduated from college last month, and I begin working full-time at my job tomorrow morning. So after 23 years, it finally feels like my life is beginning. I’m anxious to start my new job, and to move to the cities and my new apartment. It’s a very exciting time for me.

12.04.07

Almost a Graduate

Posted in Uncategorized at 9:47 am by mike

Finally I have my blog back online. I transfered my domain to Linode because I finally decided to use a big-boy web host for my Rails applications. I’ve figured out how to get my own website running on an Ubuntu install, but unfortunately I somehow can’t get PHP to work, so I’m still using Dreamhost for this blog.

As far as school goes, I’m a mere two weeks away from being a college graduate. It’s very exciting. I’m not too worried about finding a job as I was hired by Champ Software; and as their lead designer of all things! I’ve been working for them since shortly after I met a few of their developers out in Portland for RailsConf. I now have a full-time position waiting for me after I graduate.

During my time with Champ, I’ve helped them make a few changes to the overall flow and look of their application. One feature that I’m very proud of that I implemented on their site was their tabbed navigation. “Tabbed navigation? But tabbed navigation is everywhere? What’s the big deal about that?” I hear yourself asking. Well the tabs that I developed make it a little easier to spot the active tab. Currently the few ways that active tabs are indicated usually include making the active tab the same color as its content, or graying out the inactive tabs. The method I’ve developed goes farther and partially hides the inactive tabs. I plan on doing a write up on the details of how to do this, as I’ve been given permission to share this work with the rest of the world. Stay tuned…

09.11.07

Tricky nested :include in Rails

Posted in Rails at 4:20 pm by mike

I had a number of people (2 is a number) asking for help in the last week about nesting includes in their find statements. So I decided I would share my long experience with these often confusing, yet so rewarding, include statements.

2 years ago when I wrote my first Rails app, I knew somewhat about the include option in the find method. But I knew only how to include a table only one jump away. This is documented in the API. But what if you want to include a table two tables away? If you were like me, you couldn’t find the answer, got confused, and went back to using SQL like you’re comfortable with. Here’s how my models were set up:

class InventoryLine
  belongs_to :item
  belongs_to :swap
end

class Swap
  belongs_to :person
  has_many :inventory_lines
end

class Item
  belongs_to :person
  has_many :inventory_lines
end

class Person
  has_many :swaps
end

So for me to include everything I had to do this:

@inventory_lines = InventoryLine.find_by_sql("SELECT *
    FROM inventory_lines
    left join swaps on inventory_lines.swap_id = swaps.id
    left join items on inventory_lines.item_id = items.id
    left join reps on swaps.rep_id = people.id...)

Later I learned that I could have used :joins => to include all of those joins with a normal Rails finder, but that isn’t the best answer either. You’ve already spent all of the time setting up your models to have relationships with each other using has_many, belongs_to, etc. Why would you turn that beautiful Ruby code InventoryLine belongs_to :swap into ugly SQL left join swaps on inventory_lines.swap_id = swaps.id?

Most people do that because they don’t know what’s available to them. This is in part to a few hints missing from the API. What isn’t in the API is the fact that you can use hashes, in combination with arrays, to join tables through other associations. If an table is connected to your object through another table, create the association by using a hash. e.g. {:first_table => :second_table}. So now that we know that, and we already know how to connect to a table only one association away (just stick it in an array), my last statement becomes:

  @inventory_lines = InventoryLine.find(:all, :include => [{:swap => :person}, :item])

Isn’t that much nicer? Here, :swap and :item are directly related to my InventoryLine model, so they belong in the array, or first element of a hash, for the :include.

Now it’s time to make things even more complicated. If you’re like me, some of the subtleties of Rails can be missed thanks to the fact that Rails makes things so transparent. What if I have a model that has two relationships, and both of those relationships point to the same model? This is the problem that occurred when I realized that my Swap model had two People: a Source and a Destination. So my Swap relationship had to change:

class Swap
  belongs_to :person
  belongs_to :source, :class_name => “Person”, :foreign_key => :source_id
  belongs_to :destination, :class_name => “Person”, :foreign_key => :destination_id
end

Now if I want to include everything in a find statement, I have to reference the relationship name.

  @inventory_lines = InventoryLine.find(:all, :include => [{:swap => [:source, :destination]}, :item])

<update date=”1/23/08″>
On the other side, I need to update the relationship between the Person model’s relationship with InventoryLines to reflect the change above.

class Person
  has_many :swaps
  has_many :swaps_as_source, :class_name => “Swap”, :foreign_key => :source_id
  has_many :swaps_as_destination, :class_name => “Swap”, :foreign_key => :destination_id
end

This gives me the granulated control that I need when dealing with determining the swaps a person has been involved in. They can be involved in a swap as either the source or the destination, and this more clearly spells out to me which relationship is which, even though both relationships involve the same model.
</update>

<update date=”12/17/08″>

In Rails 2.0, Optimized Eager Loading was implemented. This means that, by default, :includes aren’t actually translated into JOINS in the SQL statement,
unless a condition depends on it being there. So with the example above, how do we reference a Person’s Swaps when they have two separate relationships to
the swaps table? You have to understand the alias naming scheme Rails uses when doing multiple includes for the same table. This can be a little tricky.

When you’re only including one of the associations, the table name will be what you expect: the actual name of the table.

Person.find(:all, :include => :swaps_as_source, :conditions => "swaps.destination_id IS NOT NULL")

If you want to include multiple associations that reference the same table, you should know that any references to the first include you declare will still be the
table name. However once you want to reference that second include, Rails will alias the table name to the plural form of the reflection name, followed by the parent table name,
which is the first table listed in SQL’s FROM statement. In my example, if swaps_as_destination were the second include, any references to this table would be swaps_as_destinations_people
since I’m doing a search on the people table.

Person.find(:all,
  :include => [:swaps_as_source, :swaps_as_destination],
  :conditions =>
    "swaps.destination_id IS NOT NULL AND
     swaps_as_destinations_people.source_id IS NOT NULL"
)

</update>

This is what finally opened my eyes to what’s going on behind the scenes. When doing an include, I used to think that I was referencing the table name, in much the same way that you set up the has_many and belongs_to relationships for a model. But it turns out that you have to set up the reference in exactly the same way as in the model because you aren’t referencing the table, you’re referencing the relationship. Convention over configuration is great most of the time. But occasionally you’ll run into exceptions, like the one above.

09.10.07

I came. I saw. I Rumbled.

Posted in Uncategorized at 8:11 am by mike

The Rails Rumble is over! What a weekend. I really enjoyed my time with Chris, Ian and Ned this weekend. I think we all had a pretty good time at the Rumble. I’m just a little dissappointed in the final state of the project. We all had things we had to do yesterday, so we had to call it quits around mid-afternoon, which means we didn’t get a lot of the core functionality done. But we have talked about continuing development on our own servers. I think we have a pretty decent idea here, and I would like to see it go somewhere. Check out iCanHazTrofy.com for updates.

09.08.07

Let’s get ready to… numble?

Posted in Uncategorized at 10:29 pm by mike

Oh, rumble. That’s it. I’m sitting outside in front of a fire at 11:00 on a Saturday night programming for out Rails Rumble project. I’m working with Chris, Ian and Ned. We’re making a website for people to go and register their Christmas wishlists for sharing with their families, or any groups they belong to, in order for others to see what they want. Also, anyone who register’s in a group can choose to use our Secret Santa method, which will set up everyone in the group with a secret santa. We will also allow charities to register wish lists for underprivileged families, similar to Adopt a Family or other programs. It will be available at elflist.us.

08.28.07

New Car and Brain Crack

Posted in Uncategorized at 9:45 am by mike

I’m really excited right now. I just bought a new car this past weekend and I am absolutely in love with it. It’s a 2003 VW Passat. Manual of course (I’m such a control freak). It took about 2 weeks of searching to find this one, but it was very worth it.

In other news, I’m looking through my Word Press account and I’m realizing that I’m writing a lot of blog posts that I’m not posting. For those of you who haven’t heard of him, Ze Frank is a “content creator” who for a year made quick video posts almost every weekday. He was the one who coined the term “Brain Crack,” referring to those ideas you come up with and work on and just let sit without ever letting it actually see the light of day. It could be because you’re afraid to share it with the world, or you just want to keep working on until it’s perfect. Unfortunately nothing is ever perfect, so sometimes you just need put it out there and let others decide. I need to remember that.

Also, this is my last week at Web Dev. It’s bitter sweet. I’ll have more time to work on other projects, but I’ll miss hanging out with the people here. At least I’ll still be able to drop in and bug everyone once in a while :)

08.20.07

“Hello Wisconsin!”

Posted in Uncategorized at 9:41 am by mike

I just got back from a trip to Milwaukee after visiting my cousins this weekend. I went with Kaley, and we all had a really good time. Friday night we stayed at Danny’s house and went out for a few drinks at the local bars in Port Washington. I had visited him at his house before, but never actually saw the rest of the town. I was actually impressed at how nice it was. He’s less than a mile away from the lake, yet I never knew this or knew what was around him. It had a very pretty marina and a great view from its parks of the lake. I look forward to visiting again.

The next day we went down to Milwaukee to see my cousin Sam at his apartment. After that, we all went to the Brewer’s game. The game was amazing! I was so impressed by the stadium. It makes me wish I lived in Milwaukee just so that I could go to more games at Miller Park. The stadium was just massive. And I loved being at a place where I was rooting for the same team as everyone else. And it was even better to see a win! I don’t think I’ll ever go back to a game in the Metrodome. The only problem was that it was raining that day, so we had to walk from our car to the stadium in the rain. But at least the stadium has the closable roof. It would have been nice to see an outdoor game, but it was a whole lot better than getting rained on.

The next day my cousins had plans, so Kaley and I just went to Bay Shore mall for lunch before getting on the road to go back home. All in all it was a fun weekend. I’m looking forward to the next time Sam, Danny and I get to hang out again.

08.02.07

Yin and Yang

Posted in Uncategorized at 10:46 pm by mike

So yesterday started out as a very good day. I didn’t go to bed the night (morning) before until 5 am, so I planned on sleeping in to get caught up on sleep. However Kaley had other things in mind as she woke me up when she called me around 10 to tell me that she finally got her job that she applied to months ago. She applied for an HR position at Fort Snelling back in May (I think) and just yesterday did she finally get a letter saying that she could start working Monday. For those of you counting, that’s at least 4 months that she’s been waiting for this job. So I was very excited for her when she called me and told me that she finally got a starting date for her new job. That same day I got a nice raise from the MyDecisionHelper project. Which is great, other than making it harder to choose which project I want to work on. That was my Ying. Then came the Yang.

Later that afternoon I tried to call Kaley just to chat for a few minutes. The problem was I couldn’t get through to her. I knew something had to be happening if the cell phone calls weren’t getting through. I then checked the news on CNN and saw that the bridge in Minneapolis had collapsed. I couldn’t believe what I was seeing. For everything good that seemed to happen yesterday, it did end pretty badly. Thankfully no one that I know was affected, but it’s still a tragedy. I hope that everything will be ok from now on…

« Previous entries ·