tag:blogger.com,1999:blog-53209735123296742072024-02-20T08:36:23.565-05:00lambda { }lambda { put(self).in(:pipe).and.call() }Hoshhttp://www.blogger.com/profile/18207044645655351666noreply@blogger.comBlogger28125tag:blogger.com,1999:blog-5320973512329674207.post-8999157500214895512011-02-11T14:39:00.008-05:002011-08-26T14:08:01.533-04:00Agile rspec with let()Rspec 1.3 has the least-used, yet significant feature called let().
Here's how you set up Rspec 2, for those who have not caught on to let().
describe Friendship do
before :all do
@users = (1..5).collect { Factory(:user) }
end
after :all do
@users.each { |user| user.destroy! }
end
it 'should do something' do
@users.each do |user|
user.should be_valid
end
# Something Hoshhttp://www.blogger.com/profile/18207044645655351666noreply@blogger.com5tag:blogger.com,1999:blog-5320973512329674207.post-9110140853138423342011-01-18T19:22:00.005-05:002011-01-18T19:37:48.353-05:00Scoping and Closure in Ruby 1.8The other day, I had to wrote code in this form:class_eval do [:foo, :bar].each do |a| _cache = :"@#{a}_cache" define_method a do _cache end endendI had to ask myself: does this really do what I expect? I know the define_method closes over the _cache variable, but is it really isolated in each iteration? Am I really referencing a different _cache on each iteration? I tried this in the Hoshhttp://www.blogger.com/profile/18207044645655351666noreply@blogger.com0tag:blogger.com,1999:blog-5320973512329674207.post-33461884085406962942010-09-10T16:38:00.004-04:002010-09-15T17:01:51.775-04:00Trick Debugging with Object#tapSince ActiveSupport 3.0 deprecated Object#returning in favor of Object#tap, we can make use of inline debugging like this:(1..100).to_a.map { |x| x * 2}.inject( 0 ) { |a, b| a + b}.tap { |sum| p sum }Being used to Symbol#to_proc, this looks so awkward. I'd rather do this:WATCH = lambda { |*args| p *args }(1..100).to_a.map { |x| x * 2}.inject( 0 ) { |a, b| a + b}.tap(&WATCH)Extending that ideaHoshhttp://www.blogger.com/profile/18207044645655351666noreply@blogger.com0tag:blogger.com,1999:blog-5320973512329674207.post-12052735982707438942010-07-06T14:48:00.005-04:002010-07-06T14:56:30.860-04:00Writing ebooks with ERBFor me, the upper limit of acceptable commute time is 10 minutes, but a longer commute time does give me time to think up of things while navigating a familiar route. One such idea came from a sudden desire to write a book. Having gotten Stanza for my iPod, and having a mind that cross-links ideas together like an encyclopedia, I'd want to publish it via epub and on a MediaWiki platform. I'm Hoshhttp://www.blogger.com/profile/18207044645655351666noreply@blogger.com0tag:blogger.com,1999:blog-5320973512329674207.post-62653917683926863622010-06-25T16:36:00.006-04:002010-06-25T17:04:21.264-04:00Stealing Let from RspecSince Rspec 1.3, you could define variables in example groups that cascaded down, thus more or less eliminating the need for a before block. You do this by calling let(). By defining them with the right words, the spec code gets simplified and reads more naturally. I found it weird that it would be named after something I kept seeing around in Lisp, so I looked it up and found this. I did not Hoshhttp://www.blogger.com/profile/18207044645655351666noreply@blogger.com3tag:blogger.com,1999:blog-5320973512329674207.post-61699275720498206162010-06-24T10:06:00.001-04:002010-06-24T10:08:16.734-04:00Untitled Haiku #1irb(main):001:0> lisp(:code_generator).to_ruby=> :metaprogrammingHoshhttp://www.blogger.com/profile/18207044645655351666noreply@blogger.com1tag:blogger.com,1999:blog-5320973512329674207.post-24171741378580990962010-06-11T14:54:00.004-04:002010-06-11T15:12:42.084-04:00Remarkable 4.0.0.alpha4Rails 3.0 Beta4 is out! and thanks to Louis T. we have released a alpha4 that tracks Rails 3.0 Beta4. You will need to run RSpec 2.0 alpha11 in order to run this version.As usual, remarkable/rails does not work. I know a lot of people have asked for this. I personally don't have a need for those macros, though there are a few who looks like they are stepping up to the plate. If you want an Hoshhttp://www.blogger.com/profile/18207044645655351666noreply@blogger.com0tag:blogger.com,1999:blog-5320973512329674207.post-38406702498567774482010-06-08T15:21:00.004-04:002010-06-08T15:32:19.651-04:00Remarkable 4.0.0.alpha3Remarkable 4.0.0.alpha3 has been released, thanks to João Vitor and Louis T..Changesalpha3 requires Rspec 2.0.0.alpha11In keeping with Rspec 2.0.0.alpha11, the module Rspec was changed to RSpecThis required changes in the i18n localization files. You will now need to use r_spec instead of rspec{{}} was changed to %{} as per deprecation warnings in the i18n gemA Gemfile is used for the convenienceHoshhttp://www.blogger.com/profile/18207044645655351666noreply@blogger.com0tag:blogger.com,1999:blog-5320973512329674207.post-6413948116048351392010-05-26T08:48:00.005-04:002010-05-26T09:36:26.877-04:00Remarkable 4.0.0.alpha2Remarkable 4.0.0.alpha2 now released. This release reorganizes and simplifies loading of the component. Here's how you install it:sudo gem install remarkable_activerecord --preAdd Remarkable to your Gemfile:group :test do gem 'rspec', '>= 2.0.0.alpha7' gem 'rspec-rails', '>= 2.0.0.alpha7' gem 'remarkable', '>=4.0.0.alpha2' gem 'remarkable_activemodel', '>=4.0.0.alpha2' gem 'Hoshhttp://www.blogger.com/profile/18207044645655351666noreply@blogger.com0tag:blogger.com,1999:blog-5320973512329674207.post-51870788233183321072010-05-18T14:38:00.007-04:002010-05-18T14:58:06.496-04:00The knife is out for ruby ... ORLY?Warning: Link BaitFrom Hacker News, comes "The Knife is out for Ruby". "Dynamic languages are coming to the end of their honeymoon period. This is bad for Python and maybe PHP, but it is nothing short of a disaster for Ruby."... leaving aside the religious war of Static vs. Typed language, how about viewing this from the point of view of Pragmatic Extropy?"Type safe static languages like C#, JavaHoshhttp://www.blogger.com/profile/18207044645655351666noreply@blogger.com0tag:blogger.com,1999:blog-5320973512329674207.post-86226929659436349762010-05-17T22:10:00.004-04:002010-05-17T22:32:54.986-04:00Adventures with chef-server and Gentoo, part 9Continued from Part 8So my nifty Ghetto DNS for Rackspace Cloud backfired on me.I spent several hours (!?) trying to figure out why (1) the recipe works on my dev environment, (2) the recipe works at our in-house Xen Cloud Server environment, and (3) the recipe refuses to work on the Rackspace Cloud Server.I had narrowed it down to the fact that:search(:node, "rackspace_private_ip:#{Hoshhttp://www.blogger.com/profile/18207044645655351666noreply@blogger.com1tag:blogger.com,1999:blog-5320973512329674207.post-48732120650465990982010-05-17T12:59:00.003-04:002010-05-17T13:25:06.156-04:00Adventures with chef-server and Gentoo, part 8Continued from Part 7Although in Part 7, I said that was the end of the Chef iteration for now, I wanted to finish up just one more thing. (It's always just one more thing). I attempted to install a fresh chef-server for our internal lab environment, now that I've finished up with the recipes on my dev environment. I followed through the notes I took in Part 2, and proceeded to run into a Big Hoshhttp://www.blogger.com/profile/18207044645655351666noreply@blogger.com0tag:blogger.com,1999:blog-5320973512329674207.post-58899463321596655292010-05-14T21:00:00.005-04:002010-05-14T23:20:03.389-04:00Adventures with chef-server and Gentoo, part 7Continued from Part 6Earlier this week, I integrated veszig's's Portage code into my set of cookbooks. I've also merged in veszig's keywords, use, etc. provider into a seperate module. Along the way, I cleaned up some things (my fascination with Scheme is showing through in the code) and made it so that it will default to EIX if available and fallback to emerge --search if not. I monkey-patched Hoshhttp://www.blogger.com/profile/18207044645655351666noreply@blogger.com0tag:blogger.com,1999:blog-5320973512329674207.post-77027248898628318312010-05-11T16:04:00.004-04:002010-05-11T16:14:09.035-04:00Idea: Cost Accounting using ChefSince Chef describes your infrastructure as a set of resources, I think it is possible to go beyond the basic bandwidth + CPU/hours for cost accounting.Suppose you have a set of heterogenous web sites, each using a different classification of recipes:Site A: static filesSite B: static filesSite C: PHP-FCGI (Wordpress)Site D: Python (Trac)Site E: Ruby on Rails 2Site F: Ruby on Rails 3In our Hoshhttp://www.blogger.com/profile/18207044645655351666noreply@blogger.com0tag:blogger.com,1999:blog-5320973512329674207.post-49394750720578086602010-05-11T00:08:00.002-04:002010-05-11T16:15:11.377-04:00Idea: Rubygems for Chef CookbooksOne day (but not today), we will need the equivalent of Rubygems for Chef Cookbooks. Or at the very least, site cookbook collections.Hoshhttp://www.blogger.com/profile/18207044645655351666noreply@blogger.com1tag:blogger.com,1999:blog-5320973512329674207.post-90304451729866389782010-05-07T20:56:00.005-04:002010-05-07T21:05:49.132-04:00Wireless Virtual MachinesProblem:I don't like doing dev work on OSX, so I have a number of VMWare vms running Gentoo Linux where I do my actual development. OSX works great to provide anywhere-access via wireless and sleep.Most free wifi places such as Panera's, Border's, and Barnes & Nobel requires you to access their website first before they let you through.Besides, I don't like using VMware to bridge connections for Hoshhttp://www.blogger.com/profile/18207044645655351666noreply@blogger.com1tag:blogger.com,1999:blog-5320973512329674207.post-87063040876449997962010-05-07T15:04:00.008-04:002010-05-07T17:07:13.686-04:00Adventures with chef-server and Gentoo, part 6Continued from Part 5Lots of updates:I further refined the portage_conf definition. You can pass :force_regen to force a regeneration of make.conf. This is necessary in the case of mirrorselect if you need to install a package. I added a bunch of recipes. Here is an index of them so far:portageBase portagechef_overlay Installs veszig's chef-overlayfeature_buildpkgEnable building binary Hoshhttp://www.blogger.com/profile/18207044645655351666noreply@blogger.com2tag:blogger.com,1999:blog-5320973512329674207.post-5485205547462777882010-05-07T11:03:00.004-04:002010-05-07T11:11:37.352-04:00Data Driven Application Deployment with Chef - Blog - OpscodeFrom Opscode: Data Driven Application Deployment with Chef - Blog - Opscode.I was wondering when they were getting around to this. As I mentioned in a previous post, we're going to use "segments" at work, and that would be data-driven. In our case, it would be Rackspace Cloud Servers, not EC2 and Rackspace Cloud Files, not S3, but the principles remain the same. The databags seems like a great Hoshhttp://www.blogger.com/profile/18207044645655351666noreply@blogger.com0tag:blogger.com,1999:blog-5320973512329674207.post-71655856431824249412010-05-04T16:51:00.005-04:002010-05-04T18:31:32.934-04:00Adventures with chef-server and Gentoo, part 5Continued from Part 4Many Gentoo configurations, such as excluding rsync categories in /usr/portage, installing layman to manage overlays, setting up a local rsync mirror, or having Portage pull binary packages first all require editing configurations found in /etc/make.conf. While we can attempt to manage /etc/make.conf, we end up with the same issues with managed /etc/portage/package.use. A Hoshhttp://www.blogger.com/profile/18207044645655351666noreply@blogger.com1tag:blogger.com,1999:blog-5320973512329674207.post-16278870422401522902010-05-03T19:46:00.005-04:002010-05-04T18:31:21.851-04:00Adventures with chef-server and Gentoo, part 4Continued from Part 3When I followed the instructions for chef-overlay, I noticed a feature for Portage that I never knew existed. For those not familiar with Gentoo, you can specify fine-grained control over the exact version number of compile-time features with four files, /etc/portage/package.use, /etc/portage/package.keywords, /etc/portage/package.unmask, and /etc/portage/package.mask. The Hoshhttp://www.blogger.com/profile/18207044645655351666noreply@blogger.com0tag:blogger.com,1999:blog-5320973512329674207.post-24884001949893757802010-05-03T15:06:00.008-04:002010-05-03T15:53:57.516-04:00Adventures with chef-server and Gentoo, part 3Continuing from Part 2The next step comes in a bundle of two. I am targeting the Rackspace Cloud platform. Each Rackspace slice gives you two ethernet devices. eth0 points to a public IP address and eth1 gives you a private IP address in the 172.* range. Packets going through eth0 incurs a charge while packets routed through eth1 does not. Since the default, non-nanite install of Chef assumes youHoshhttp://www.blogger.com/profile/18207044645655351666noreply@blogger.com0tag:blogger.com,1999:blog-5320973512329674207.post-19610039346581174812010-04-29T13:08:00.002-04:002010-04-30T13:35:48.275-04:00Adventures with chef-server and Gentoo, part 2Followup to part 1Once I had a chef-server and webui all set up on my dev box, the next part is to create a "stem cell" image that has chef loaded up on there. Chef 0.8 uses SSL for its new validation mechanism, and so the server creates public/private keypairs for the validation. These are encapsulated in a Chef concept called a client. It took me a while to figure out that client was not a goodHoshhttp://www.blogger.com/profile/18207044645655351666noreply@blogger.com0tag:blogger.com,1999:blog-5320973512329674207.post-66719592909771832252010-04-27T18:43:00.005-04:002010-04-27T18:52:42.633-04:00Adventures with chef-server and Gentoo, part 1I had been circling around chef-server and Gentoo for a while. There are three ways to install Chef-server:Install it manuallyUse chef-solo to bootstrap chef-serverUse system packagesNeedless to say, (1) was not fun. While (2) invokes the mystical recursive experience of Lisp-written-in-Lisp or maybe, the Stand Alone Complex, as someone who is more excited about using Chef, I just want to get on Hoshhttp://www.blogger.com/profile/18207044645655351666noreply@blogger.com1tag:blogger.com,1999:blog-5320973512329674207.post-34989476573503695072010-04-27T13:33:00.009-04:002010-04-29T14:10:39.489-04:00Three free Rackspace Cloud backup images? Not so fast.Biting the bullet, I went ahead and prepared a Gentoo 10.1 "stem cell" image on Rackspace Cloud so I can use it for my nascent infrastructure. I got it prepared (even though I made a mistake and started the bootstrap from 2008.1, but that is OK) and had the image backed up. According to the control panel:To move an image to Cloud Files, click the Move link in the table below. You may keep as manyHoshhttp://www.blogger.com/profile/18207044645655351666noreply@blogger.com2tag:blogger.com,1999:blog-5320973512329674207.post-23423270444503908812010-04-23T12:13:00.003-04:002010-04-23T12:21:51.280-04:00Improving macro registration for Remarkable 4Since one of the emerging design principle for Remarkable 4 is to shadow Rails 3, and Rails 3's biggest strength is its modularity, I've decided to split Remarkable into components following the Rails 3 modules. For now, we have remarkable (core), remarkable-activemodel, and remarkable-activerecord. I plan for remarkable-rails to be split into remarkable-rack and maybe Hoshhttp://www.blogger.com/profile/18207044645655351666noreply@blogger.com1