Ah yes, it’s that wonderful time of year again: fantasy baseball time. Anyone who plays fantasy sports can tell you that other than getting a check for winning your league (something I would know nothing about), the best part of the season is the draft.
My fantasy draft preparation always involves the creation of a spreadsheet. [...]
Entries Tagged as ‘Ruby’
March 9, 2009
Baseball Draft
October 27, 2008
Ruby String Concatenation
Ran in to a bug tonight. See it?
def display_value
display_value = notes.blank? ? “untitled” : notes
display_value << ” (#{ shortcut })” unless shortcut.blank?
display_value
end
Need a hint? The symptom was the +notes+ field being unexpectedly changed.
+display_value+ is pointed at +notes+. “<<” then goes ahead and changes that value (which both attributes are pointed at), thus both are [...]
July 7, 2008
Rails Upgrade Bumps
After skimming the “What’s New” posts for several Rails versions without finding anything worth jumping at, it was time to upgrade. While JSON enhancements (fixes) are the driving reason for the move, there certainly are a few “nice to haves” that I’ve been looking forward to checking out.
Partial Updates
Unfortunately, one of the things I’ve been [...]
December 2, 2007
Leading zeroes on Time.strftime
Not sure why this isn’t in the Ruby documentation (at least where I normally check) but the common annoyance of leading zeros on Time.strftime can be avoided simply by using “%l”.
It does come with another inconvenience though: you get a leading space instead of a leading zero…
November 14, 2007
Nice(r) Hash treatment for URLs
Isn’t it nice how Rails lets you add form elements using the convention:
store[manager] = Bob Smith
store[location][state] = Wisconsin
store[location][zip] = 53590
And easily process them on the server side with something like:
Store.new(params[:store])
So, why does this:
link_to “Store”, :controller => :store, :action => :show, :store => { :manager => “Bob Smith”, :location => { :state => “Wisconsin”, :zip => [...]
February 26, 2007
Links for blackberry’s
A user recently reported an issue with our emails. The issue being that our links weren’t properly coming through on his Blackberry unit, while links from others looked fine.
After a bit of digging the issue ended up being that:
<a href=”http://seekingalpha.com”>SA</a>
displayed like this (which is desired on the unit):
SA <http://seekingalpha.com>
While this:
<a href=’http://seekingalpha.com’>SA</a>
displayed:
SA
Not sure if ignoring [...]
December 6, 2006
Receiving Email with ActionMailer
This really was a snap.
A nice and simple testing recipe (#68) demonstrates how to read in an email from a fixture in just a few lines and pass them to your processing method (MailReceiver.receive in this case).
def read_fixture(action)
IO.readlines(”#{FIXTURES_PATH}/mail_receiver/#{action}”)
end
def test_something
email = read_fixture(”junk_mail”).join
MailReceiver.receive(email)
# assertions
end
And then a few lines on how to feed it “for real”. and [...]
October 2, 2006
Be careful with assert_not_equal
As I discovered today, assert_not_equal has a pretty big problem: it does exactly what you ask it to do.
I just need to make sure that a user has at least one record:
assert_not_equal 0, UserPreference.find_by_user_id(user_id)
As you may have just caught: that is always going to pass. Not a tough mistake when you’re motoring along and [...]
September 21, 2006
Send an image
You’d think it would be easy to send an image to a client with a framework as wonderful as Rails.
After doing quite a bit of searching for the simple way, I really didn’t turn up too much. Finally, I decided I would just open the file and write it out the old fashioned way: [...]
September 15, 2006
String Concatenation
A reporting application I am working on requires the results of some quite large queries to be parsed and presented to users via a web page. The query timings are an issue themselves, requiring some creative SQL, indexes, views, and some batch jobs to shape the data for the web application to efficiently utilize [...]