Skip to content
Oct 25 09

Confusing signs

by admin

I like taking pictures of confusing signs. It reminds me to be more mindful about the messages I put on clients websites.

On a fishing trip to Yellowstone I came across these signs.

Bears drive?

Bears drive?


does excluded mean not allowed, or excluded from the not allowed list?

does excluded mean not allowed, or excluded from the not allowed list?

Oct 11 09

Making a sortable, dynamic grid

by admin

GridI came up against an interesting challenge on a current project. This was actually pretty fun to figure out. Here is what I came up with.

I needed to display a grid with columns and rows that had information in each cell. The information in the cells needed to be dynamic, or change based on a UI perspective.

Also, if there were more than 10 rows in a column, the remaining cells needed to wrap to the next column.

This is definitely a job for a helper so I wrote these methods for the helper to render this sortable, dynamic grid. So far it seems to be holding up when rendering grids of various columns and rows.

  1.  
  2.   def my_grid
  3.     @my_data =
  4.     @my_data += ‘<table>’
  5.     @my_data += ‘<tr>’
  6.    
  7.     num = 1
  8.     #this starts a new column for each category
  9.     @columns.each do |col|
  10.       cell = Cell.find(:all, :conditions => [‘category_id = ?’, col]) rescue nil
  11.          
  12.       count = cell.size
  13.       item = 0
  14.       itemtotal = 1
  15.       cell.each do |row|
  16.         #if this is the 0 item start a new column
  17.         if item == 0
  18.                 @my_data += self.start_col
  19.         end
  20.        
  21.         score = row.get_my_score(row.id, @grid, @user).to_s
  22.         @my_data += self.list_item(score, row, itemtotal)
  23.        
  24.         #if this is the 9th item, or is the last of the cells, close the column and reset count
  25.         item += 1
  26.         if item == 10 || itemtotal == count
  27.                 @my_data += self.end_col(num)
  28.                 num = num.to_i + 1
  29.                 item = 0
  30.         end
  31.         itemtotal += 1
  32.       end
  33.      
  34.      
  35.     end
  36.    
  37.     @my_data += ‘</tr>’
  38.     @my_data += ‘</table>’
  39.     #return @my_data
  40.   end
  41.  

  1.  
  2. def start_col
  3.     @start = ‘<td valign="bottom"><div style="position: relative; bottom: 0px; display: block;">’
  4.     @start += ‘<ul style="vertical-align: bottom">’
  5.     return @start
  6. end
  7.  

  1.  
  2. def end_col(num)
  3.     @end = ‘</ul>’
  4.     @end += num.to_s
  5.     @end += ‘</td>’
  6.     return @end
  7. end
  8.  

  1.  
  2. def list_item(score, row, item)
  3.     @list = ‘<li class=key_’+ score +‘>’
  4.     #some stuff here…
  5.     @list += ‘</li>’
  6.     return @list
  7. end
  8.  
Oct 3 09

What I think of my hackitosh netbook

by admin

The pros and cons of my new hacintosh netbook… Or as a friend of mine calls it… hackintrash.

First, why did I get a net book?
My MacBook Pro is just over 4 years old now. It have pretty much been working night and day since I have owned it. It’s my 3rd 15″ mac book. Its a great machine and I have more than got my monies worth, but now it is starting to show signs of wear and tear. Taking my netbook to the office is a good way for me to get some more mileage out of the macbook.

Next, the cons. There aren’t many if you don’t have unreal expectations of the smaller processor. But there are a few things to be aware of. Not everything will work flawlessly. Things like bluetooth, ethernet port and the VGA port may have some issues. The webcam will probably work, but the mic might have an issue.

Most of the netbooks on the market at the time of this writing have less powerful processors and video cards. So, if you’re thinking of running photoshop, think again. Don’t even think about Final Cut.

And, for what ever reason, my netbook likes to have a kernel panic about every 3 and a half days if I dont shut it down from time to time. But I like just closing the lid and putting it to sleep, so i put up with the panics.

Now the pros. For 90% of what I used my macbook for around home and the office, the netbook has been pretty seamless. Now with 3 computers in 3 locations, that I need to work on day to day, keeping information synced would seem a daunting challenge. A few key apps and services are key for me to keep things together.

All of my web dev projects for work, freelance and personal are now kept on SVN. Beanstalk has been a perfect companion for my netbook. I can keep my web development work in sync with all my computers very easily.

To keep documents synced up between all these machines I use DropBox. And all my email is web based so Im covered there.

And to keep all my notes, thoughts and ideas in sync, Evernote is perfect.

Its great moving from machine to machine with virtually no difference in my workflow.

Go to these sites for more information:
http://gadgets.boingboing.net/2008/12/17/osx-netbook-compatib.html
http://www.wired.com/gadgetlab/2009/05/eight-months-with-a-hackintosh-netbook-conclusion-fantastic/
http://osxdaily.com/2009/09/19/the-ultimate-resource-for-building-a-hackintosh-netbook-or-hackintosh-desktop/

Sep 30 09

Don’t get your servers wet

by admin

This is a sad site. 3 new xserves, rusted out.

09302009137Exposed racks are inexpensive… until the ceiling leaks. Needless to say the replacements are in a enclosed, hepa filtered, locked case. And there is a huge ceiling pan with a drain.

I will say, that I was impressed that the servers were still running and serving sites with standing water inside the case. Amazing!

Sep 25 09

Fishing with the Family

by admin

A short hike is just what the family needed

After a very busy summer taking a short one mile hike in our hills was a real breath of fresh air. We took the rods but didnt expect to catch anything. Then emily helped me land this slab of a cutthroat.

Twin Lakes Cutthroat

Twin Lakes Cutthroat

Sep 23 09

Upload CSV to multiple tables

by admin

Uploading a CSV to a single table is easy enough, but what if elements of your CSV go to separate tables and needed to be primary and foreign keys for each other?

I have two tables, Categories and Items. I have a CSV that looks like this:
Category One,Item One,Item one descriptions,,
,Item two,Item two descriptione,,
,Item three,Item three description,,
,Item four,Item four description,,
Category Two,Item five,Item five description,,
,Item six,Item six description,,
,Item seven,Item seven description,,

My controller method looks like this:

require 'csv'
def csv_import
@parsed_file=CSV::Reader.parse(params[:csv][:file])
@parsed_file.each do |row|
category = row[0]
if !category.nil?
c = Category.new
c.name = row[0]
c.save
@new_cat = c.id
end


i = Item.new
i.name = row[1]
i.description = row[2]
i.category_id = @new_cat
i.save
end


redirect_to :controller => 'category', :id => params[:csv][:item]

And my form looks like this:
<% form_for :csv, :url=>{:controller=>"category", :action=>"csv_import"}, :html => { :multipart => true } do |f| -%>

Select a CSV File : <%= f.file_field :file -%> <%= submit_tag 'Submit' -%>

<% end -%>

Sep 16 09

Hosting on AWS part 2

by admin

Now i just want to run my rails app in production mode through apache instead of mongrel. Here is what I did.

First I needed to install apache.
yum install httpd

Then kill the existing mongrel process
pkill -9 mongrel_rails -u root

With apache installed I now have the directories I need. I moved my rails app from my webuser directory to my apache directory at /var/www/html.

Now i can start apache
apachectl start
If you go to your primary dns in a browser you should see the default fedora apache page.

Next I installed passenger
gem install passenger

Then the apache mod
passenger-install-apache2-module

Since I was using one of the pre-set AMI’s I am promted to install a few things.
* To install GNU C++ compiler:
Please run yum install gcc-c++ as root.

* To install Apache 2 development headers:
Please run yum install httpd-devel as root.

* To install Apache Portable Runtime (APR) development headers:
Please run yum install apr-devel as root

Then add these to the httpd.conf file
LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.2.5/ext/apache2/mod_passenger.so
PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.2.5
PassengerRuby /usr/bin/ruby

And add a virtual host to the conf file the way described in the apache mod install instructions.

Then restart apache
apachectl restart

That was it. My rails app is now running through apache.

Sep 15 09

Hosting on AWS

by admin

Just some notes from setting up a Ruby on Rails instance on AWS EC2.

During the set up process of the instance you will be able to download a private key. Put that private key in a safe directory and chmod it to 400.

Then after completing the setup of the instance and you can see that it is running, go to your command line and enter:

ssh -i /path/to/key/[name of key].pem root@[public DNS]

That will get you logged in. You will need to go to /home/[webuser] to checkout your web project from SVN. But first you need to install SVN:

yum -y install subversion

Now you can check out:

svn checkout http://address.of.your.repository/and/path projectname

cd in to config and nano the database.yml, make the needed changes, then nano the environment.rb and edit the rails version if needed. Then make the database:

mysql

create database [whatever]

exit

Then cd into the root of the new project you just checked out:

rake db:migrate

And if you have fixtures to test with

rake db:fixtures:load

Amazon runs mogrel so to test your project you can add this shell script:

#!/bin/sh
cd /home/webuser/[project name]/log && rm mongrel.pid -f
pkill -9 mongrel_rails -u root
cd /home/webuser/[project name] && /usr/bin/mongrel_rails start -e development -p 80 -d

chmod that to 755 and run ./restart.sh

Go to the public DNS address in your browser and you should see your project.

Next, I will be attempting to run Rails through Apache on AWS with passenger instead of mongrel. For now this got my project online.

Aug 26 09

Caught between PHP and Ruby

by admin

Am I a PHP Developer? Am I a Ruby Developer? How about, I am a Web Developer.

This is something I have been discussing with various co-workers for some time. Learning Rails over the last couple of years, and now finally having more opportunites to use Rails I find that I have taken a similar path that Derek Sivers outlines in this article (http://www.oreillynet.com/ruby/blog/2007/09/7_reasons_i_switched_back_to_p_1.html), but I dont see myself abandoning Rails or PHP. I enjoy working in both and they both have their strengths and weaknesses.

I read something on another blog recently that has stuck with me. It read, “If the only tool in your toolbox is a hammer, everything looks like a nail”.

Jul 20 09

I finally used fixtures

by admin

I finally had a project where I thought fixtures and unit testing made sense and now I’m wondering why wasn’t I doing this all along?

I have been using rake migrations pretty much since I started using RoR. But default data hasnt been much of an issue on my projects until this last one. So I looked into fixtures and Im regretting not taking the time sooner to get to know fixtures better.

One cool thing I came accross was how to handle foriegn keys when loading fixtures. It kept choking on fixtures:load because by default it will load fixtures in alphabetical order. For example: My fixture for accounts has a FK of user_id but the accounts fixture will be loaded before the users fixture is. Thus my FK problem.

I found some clever ruby scripts that alter the ENV variables and so on but i thought a more direct approach was to just run it like this

rake db:fixtures:load FIXTURES=users,accounts

Pretty cool.