Time Machine Tip: Disable Antivirus
February 26th, 2009
My initial Time Machine backup seemed to be taking far too long. After a quick glance in the Console, the reason was painfully obvious: Symantec Antivirus AutoProtect. For whatever reason, it eats up CPU processing power and brings the speed of a backup to a halt. Disable it while backing up.
Two quick ways to make testing much more enjoyable
December 11th, 2008
If you’re doing TDD, and especially if you’re just starting out, you know how frustrating debugging your code can be. These tools/tips make TDD much, much more enjoyable.
1. autotest + quiet backtrace
This is a really a two-fer, but in my opinion, these two tools together make me exponentially more productive. autotest keeps your test suite running in the background, and re-runs them every time a file changes. The reasons for using autotest are beyond the scope of this short post, because there are so damn many good ones. If you’re not using it already, just take my word for it and start, now. Right now.
quiet backtrace is a nifty little tool developed by the generous geniuses over at thoughtbot. In short, quiet backtrace filters all the irrelevant backtrace “noise” that are produced when a test fails or hits an error. When a test fails, the only information you really want is the fail message, and more importantly, the actual line number in the test file that failed! Instead of over-working your eyes trying to dig through the wrapped backtrace lines telling you which path ruby took to get to the failed assertion, quiet backtrace filters out all the crap and outputs only the usable information.
Now, what really makes these two powerful together is that since using autotest and quiet backtrace together, I never have to leave my text editor to mess with the console window running my tests. By itself, autotest eliminates the need to manually re-run your test suite every time. Still, quite often I found myself not only needing to leave the text editor, but also use my mouse (gasp!) to scroll up in the console window because the backtrace scrolled so long that I could no longer see the actual error message.
2. tail -f log/test.log
This isn’t really a “tool”, but more of a massively overlooked convenience on my part. It’s easy to overlook the test log because the development log is always front and center, as it’s output by default when you run script/server. However, the test log gets updated on every request, just like the development log. So, when you’ve hit a weird error in functional or integration tests, and you just can’t figure out why you’re getting a redirect where you’re expecting successful request, turn to the test log. Better yet, use the tail -f command to keep up as it is updated.
I’ll say briefly that virtually every testing product put out by thoughtbot has made testing a much more enjoyable experience. I want to keep this post short, so I’m going to cut it off here. But seriously, go check out all the goodness being produced by those Giant Robots.
Nevermind that last article
November 20th, 2008
If you happened to read my post on managing plugins with git, pretend you didn’t because it doesn’t work as expected. I thought ignoring the .git directories in my clones plugin repositories would do the trick, but I was mistaken. My quest continues…
Ugh...
November 18th, 2008
From an email I just received from Google:
New Gmail code base available to IE6 users: Users of Internet Explorer 6 can now access significant Gmail performance improvements as well as new features like colored labels, group chat, an updated contact manager, remote sign out and more. To access these features, simply sign in to Gmail. If you don’t see these new features immediately, you may still need to get the latest IE6 updates from Microsoft.
Message to you poor souls still using this garbage browser: please stop. Ugh…
Michael Milken & Muhammad Yunus on Charlie Rose
November 15th, 2008
http://www.charlierose.com/view/interview/9324. Really fantastic message in this interview, which is essentially that we ought to be encouraging entrepreneurship and self-employment as the means to achieve a higher standard of living and an improved quality of life (i.e. the American Dream).
Muhammad Yunus is an economist who won the Nobel Peace Prize a couple of years ago (2006, I believe) for his work in encouraging and pioneering micro-finance in third-world and developing countries. Now, with Michael Milken (famed inventor of the junk bond, now massive philanthropist), he is working to bring the concept of micro-finance to America. I am overjoyed to hear people advocating the message of entrepreneurship and independence. As layoffs continue to accelerate, the concept of financial independence being achieved through entrepreneurship could not be more important.
Try to be punctual in all your dealings
October 30th, 2008
“Try to be punctual in all your dealings. You will find it difficult to get along with some men, deal as little as possible with such….Save your credit, for that is better than money….If you go on in business, be content with moderate gains. Don’t be too hasty to get too rich….I was you to live so as to be fit to live and fit to die.”- from The Snowball: Warren Buffett and the Business of Life
Unbelievable
October 18th, 2008
Over in Indiana, PA and Northern Cambria, PA, volunteers fielded complaints of a massive wave of ugly robocalls both paid for by John McCain's campaign and those paid for by third parties. The third party call was interactive, and purported to be from Barack Obama himself. The call starts out reasonably, and then "Obama" asks what the listener thinks is the most important issue. Whatever the response, "Obama" then launches into a profane and crazed tirade using "n***er" and other shock language.
shoulda == 'painless unit testing'
October 15th, 2008
I’m just getting started unit testing my models with shoulda and so far it has been a wonderful experience. In large part, shoulda is no more than syntactic sugar for Test::Unit::TestCase. However, the crux of the philosophy behind shoulda is that it ought to be just as easy to test your ActiveRecord models as it is to write them. So, if it only requires one line of code in your model to build an ActiveRecord association, then it should only take one line of code to test that association. Such is the magic of shoulda.
Equally important is the simplicity of the core parts of the language. The shoulda source is extremely easy to read and follow. For example. the ActiveRecord macros are simply methods that wrapshould blocks, which are mixed in to Test::Unit::TestCase as class methods.
# taken from ThoughtBot::Shoulda::ActiveRecord::Macros
def should_require_attributes(*attributes)
message = get_options!(attributes, :message)
message ||= default_error_message(:blank)
klass = model_class
attributes.each do |attribute|
should "require #{attribute} to be set" do
assert_bad_value(klass, attribute, nil, message)
end
end
end
It wasn’t long before I found myself wanting a macro to test if a model contained a specific callback. It’s so easy to create your own macros it’s silly. Simply create a folder called “shoulda_macros” in RAILS_ROOT/test/ and any files in that folder are automatically included. Here’s the macro I wrote:
class Test::Unit::TestCase
def self.should_have_callback(type, name)
klass = model_class
should "have #{type.to_sym} callback named #{name.to_sym}" do
assert_not_nil(klass.send(type.to_sym).detect { |callback| callback.kind == type.to_sym && callback.method == name.to_sym }, "#{type.to_sym} callback method #{name.to_sym} not found.")
end
end
end
In my opinion, shoulda is hands down the most painless way to test ActiveRecord models. Also, the fact that it is not a drop-in replcement for Test::Unit, rather, it builds on top of it, is a major plus for me. Call me conservative, but there is a certain added feeling of safety and solidarity I have when my test framework is built on top of the built-in Ruby testing package (Test::Unit), rather than replacing it outright, which is what rspec does. (I am still using rspec to test my controllers, and I’m looking forward to seeing what shoulda offers in this department)
For a great introduction and explanation of shoulda, checkout Tammer Saleh’s presentation from MountainWest RubyConf 2008.
syslogd cpu usage bug in leopard
October 4th, 2008
My mac had been acting a little funky lately, so I popped open Activity Monitor to find that syslogd was taking up about 99.9% of my CPU. Not good. I had noticed Little Snitch warning me lately of some outgoing messages to Apple’s crash report server, but I hadn’t thought much of it. Silly me.
I think what was happening was that syslogd was trying to record something to my system’s asl database, and probably when I migrated to Leopard about a month ago, that file became corrupted. Thanks to this thread I seem to have fixed the problem. I’ll repeat the steps recommended in that thread.
- sudo launchctl unload /System/Library/LaunchDaemons/com.apple.syslogd.plist
- sudo mv /var/log/asl.db /var/log/asl.db.orig
- sudo launchctl load /System/Library/LaunchDaemons/com.apple.syslogd.plist
- Restart (probably not necessary, but let’s do it just to be safe)
Now no more cpu-eating syslogd madness. Too bad I just bought more ram.
Git problems on Ubuntu Gutsy
July 28th, 2008
This may seem like a bit of an edge case, but if you’re using a setup similar to mine, it is very relevant. Here’s the long and short of it: if you’re hosting private git repositories on a server that only allows access to a non-standard ssh port (i.e. not port 22), then you must build git from source. The reason for this is that the version of git in the Ubuntu Gutsy package manager is 1.5.2 (as of this writing), and that version does not support specifying port numbers in your remote urls. Pooey.
So, we have to build git from source. I highly recommend following this tutorial. That post doesn’t cover installing the git documentation, so I’ll hit on that real quick. Follow Chris’ post until you get to the last section, where you compile and install git.
To install the man pages, you need to install a monstrosity of a package (somewhere around 700mb after installed) calledasciidoc. Note: this will take A WHILE. (If anyone knows how to do this without downloading a 700mb package, please let me know and I’ll update this post.)
sudo aptitude install asciidocNow, download and unpack the latest stable version of git, and substitute these last two steps for the one’s Chris has:
make MOZILLA_SHA1=1 prefix=/usr all doc sudo make MOZILLA_SHA1=1 prefix=/usr install install-doc
I almost forgot
July 4th, 2008
It’s July 4th, and I’ve been posting about css and cool job postings. How selfish of me.
Happy birthday America!
Displaying inline list items
July 4th, 2008
I am not a css designer. I hate the language, I hate the implementation, I hate the inconsistency of browser support. This is no fault of css or the good people who have pioneered and built the language. Rather, it is more the nature of a client-side technology. Javascript has suffered many of the same problems, but cross-browser support has gotten noticeably better in recent years.
Unfortunately, css is probably the one web technology (other than HTML) that is nearly impossible not to use. For the most part, my deep hatred of css programming is due to the “hackish” nature the language has been forced to adopt, almost exclusively because of Microsoft Internet Explorer 5.5 and 6, the massive number of bugs these browsers have, and Microsoft’s failure to patch these browsers. That said, let’s get on with it.
Often I need to display a series of items on the same line. Whenever possible, I try not to use floats because of the plethora of bugs in earlier versions of IE. My first attempt is often to use <li>’s, set list-style: none; and display: inline;. However, due to the nature of how a display: inline; element is meant to be displayed, this approach is simply not useful for any type of content beyond a menu/nav bar. So, we are forced to float the list items. I don’t know about you, but I feel defeated.
<ul id="products">
<li>
<div class="prod_img"><img src="path/to/image" alt="blah" /></div>
<div class="description">
<strong>Here's a little description.</strong><br />
<span>Here's some more.</span>
</div>
</li>
<li>...</li>
</ul>
And here’s the style rules that should satisfy our needs:
ul#products {
list-style: none;
overflow: auto;
border: 1px solid black; /* border added to illustrate forthcoming IE display bug */
}
ul#products li {
list-style: none;
float: left;
}
We have the overflow: auto; declaration so that the containing ul “hasLayout”. We have to to do this when a containing element contains all floats, or elements that don’t flow in the normal course of the document. As expected, IE 6 screws this up. We have to add a seemingly ambiguous height property declaration:
ul#products {
height: 100%;
}
There, now we’ve got it. Inline list items that can contain block-level items, while remaining on the same line.
A short rant
Maybe this a bit whiny/preachy, but having to resort to this kind of thing royally pisses me off. It’s not that it’s a lot to type, or that I had to implement some css hack that only IE version x will recognize. No, it’s simply that I had to make a special exception just for older versions of IE, while everything else works the way it’s supposed to work.
That, in a nutshell, is why I enjoy server-side programming, and why I for the most part deplore client-side programming. With server-side technologies, you know your boundaries. You are confined to the limits of your server operating system software, and the limits of the language in which you’re working. If you work within those limits, generally speaking, things will work the way they are supposed to work.
With client-side technologies, namely CSS, you end up spending just as much time learning and implementing the bugs, workarounds, and compatibility issues that you do actually writing code! This problem is not exclusive to Microsoft, albeit they are a big part of it. A perfect example is cross-browser compatibility for the various css display modes. All of those display properties have been part of CSS since CSS version 2 was released. Are you ready for a laugh? CSS2 was released in May 1998, now more than 10 years ago! Seriously!? Ten years, and we still can’t get cross browser support for inline-block. Rant over.
Best job posting ever
July 4th, 2008
Check this out. What a great way to advertise a position.
Firefox 3 text resizing quirk
July 3rd, 2008
If you, like me, are the type who occasionally likes to resize your text while reading a web page, you may be unhappy with how Firefox 3 handles this. In Firefox 2, and all other browsers (to my knowledge), the browser simply resizes the text on the page. In Firefox 3, images and everything are resized/re-rendered. I don't like this; all I want is my text resized, not a bunch of blurry images while I'm trying to ready. Eh.
My first plugin: mass_assignment_murderer
July 2nd, 2008
I recently published my first public plugin called mass_assignment_murderer. You can get it here from github. Currently, a subversion release is not planned. Basically, the plugin addresses the mass assignment problem covered in Railscast Episode 26.
mass_assignment_murderer provides an ActiveRecord class method cleverly titled, has_mass_assignment_murderer, which protects your models from mass assignment through a has_many or many-to-many association. Specifically, it looks for an methods that end with “_ids” and then calls attr_protected on those methods.
For a future version, I’m thinking of simply auto-protecting all such methods in all models, without having to make any sort of declaration.