When you are coding, you should try to separate out the things that change from the things that stay the same. This isn’t my idea, but it is worth tip’n here as I just saw a really good, simple example of this…
Read the rest of this entryFortune...
July 8th, 2008
I got his when I logged into one of my OpenBSD boxes today. Interestingly true…
Read the rest of this entryExamples of Behaviour Spec'n
June 30th, 2008
In my previous post (Spec Behaviour not Implementation) I went on a froth roll about why you should treat controller actions as black boxes. Here I give an all to common example of why this is good and how you can write specs that won’t break at the most trivial change.
Read the rest of this entryTip #27 - Spec a Behaviour, Not an Implementation
June 28th, 2008
This has been said a lot, and doesn’t really need repeating by someone like me, but, as this is a tips page, I should put it here.
Read the rest of this entryTip #24 - Being clever in specs is for dummies
June 25th, 2008
This tip is coming to you from a frustrated developer having to read someone else’s specs….
Read the rest of this entryTip #23 - Know your fundamentals
June 21st, 2008
You would expect any professional to know their stuff, for a Ruby on Rails beginner, this is no less important.
Read the rest of this entryHere is how to convert the microsoft way of storing color values (which looks like 16777215 for white) into the familiar RGB CSS style HEX values (which look like #FFFFFF) in Ruby.
1 2 3 4 5 6 7 8 |
def long_to_rgb_hex_string(val) r = "%x" % (val % 256) g = "%x" % ((val / 256) % 256) b = "%x" % ((val / 65536) % 256) "#" + [r,g,b].collect { |c| c.to_s.ljust(2, '0')}.to_s end long_to_rgb_hex_string(2093422) # => #6ef11f |
Or Grant Hutchins gave this as an option from the comments:
1 2 3 |
def long_to_rgb_hex_string(val) sprintf(’#%06x’, val) end |
Any other good options? :)
blogLater
Mikel
RSpec Story xhr problem
June 6th, 2008
If you are using RSpec stories (and if you are not, why not?) you might run into this little problem. doing an xhr :post returns ArgumentError: wrong number of arguments (4 for 3)
Read the rest of this entryTip #22 - How to ask a question about Rails
June 5th, 2008
This tip actually applies to every open source project out there… it is, how do you ask a question that will get you the maximum chance of a good answer?
Read the rest of this entryTip #21 - Developer Info On Every Page
June 4th, 2008
When you are making a rails site, you sometimes need to get to the session hash or the params hash and see just what got sent back to the browser, but going in, editing the template and reloading is just a PITA, here is a quick tip that can help you have that (and any other) information no more than a click away, at any time, and any view….
Read the rest of this entryTip #20 - Subscribe to Rails Envy
May 28th, 2008
Even though they got my name wrong :) Gregg Poolak and Jason Seinfield have a fantastic podcast that you all should subscribe to.
Read the rest of this entryTip #19 - Raaums Hints Rock
May 27th, 2008
When I was learning Ruby on Rails, this site by Raaum was a god send.
Read the rest of this entryTip #17 - Struct Your Stuff!
May 13th, 2008
Ruby is a really dynamic language, and you can do a lot of cool things, one of them is a Struct (Structure) that allows you to make throw away objects that you can call methods on….
Read the rest of this entryTip #16 - Valid Models Don't Have to be Hard
May 12th, 2008
If you are using BE DE DE or TE DE DE, then you will get situations in your specs or tests where you want to be able to just create a valid model of another type to test against. This is where factories and builders come in handy.
Read the rest of this entryTip #14 - Custom Error Messages in Validations
April 23rd, 2008
If you use Rails, you sometimes get a situation where the custom error messages just don’t work, here is how you can fix it…
Read the rest of this entry