Archive for April, 2009

Preparing to go to Jazzfest

Friday, April 24th, 2009

I am in New Orleans for the Jazz and Heritage Festival, more often known as Jazzfest. I am planning on taking some pictures and posting them here, but don’t expect me to be blogging reliably fro the next few days.

Sprinkle and Passenger Stack

Tuesday, April 21st, 2009

I started using sprinkle with the passenger-stack recently. So far, it has been easy to get started with and fairly intuitive. I chose it rather than puppet or some of the other declarative server configuration DSL because it doesn’t need to install anything extra on the server to work.

This is great for the kinds of things I have been working on, because they are fairly small, and don’t need many servers.
I think if I were managing more things, I might choose puppet, because the overhead would be justified.

One of the things I like about sprinkle, is the DSL is pretty straight forward, eg the package definition for passenger looks like this:

package :passenger, :provides => :appserver do
  description 'Phusion Passenger (mod_rails)'
  version '2.1.3'
  gem 'passenger' do
    post :install, 'echo -en "\n\n\n\n" | sudo passenger-install-apache2-module'
 
    # Create the passenger conf file
    post :install, 'mkdir -p /etc/apache2/extras'
    post :install, 'touch /etc/apache2/extras/passenger.conf'
    post :install, 'echo "Include /etc/apache2/extras/passenger.conf"|sudo tee -a /etc/apache2/apache2.conf'
 
    [%Q(LoadModule passenger_module /usr/local/ruby-enterprise/lib/ruby/gems/1.8/gems/passenger-#{version}/ext/apache2/mod_passenger.so),
    %Q(PassengerRoot /usr/local/ruby-enterprise/lib/ruby/gems/1.8/gems/passenger-#{version}),
    %q(PassengerRuby /usr/local/bin/ruby),
    %q(RailsEnv production)].each do |line|
      post :install, "echo '#{line}' |sudo tee -a /etc/apache2/extras/passenger.conf"
    end
 
    # Restart apache to note changes
    post :install, '/etc/init.d/apache2 restart'
  end

I had some problems, like the version of passenger in the passenger-stack master branch on github is a point release behind the phusion’s, which is annoying because when passenger updates itself to 2.2.0, the configs are not updated and apache tells you it can’t find the mod_passenger.so file.

Also, it puts the passenger config in a slightly unusual place(/etc/apache/extras), for an apache module, as well as appending stuff to /etc/apache2/apache2.conf. This prevents it from idempotency, because if you run it twice, it will add additional lines to the config files. So, in the vein of scratching my own itch and what have you–you know, that open source thing–I rewrote it.

package :passenger, :provides => :appserver do
  description 'Phusion Passenger (mod_rails)'
  version '2.2.0'
  gem 'passenger' do
    post :install, 'echo -en "\n\n\n\n" | sudo passenger-install-apache2-module'
 
    # Create the passenger conf file
    loading = %Q(LoadModule passenger_module /usr/local/ruby-enterprise/lib/ruby/gems/1.8/gems/passenger-#{version}/ext/apache2/mod_passenger.so)
    conf = %Q(PassengerRoot /usr/local/ruby-enterprise/lib/ruby/gems/1.8/gems/passenger-#{version}
PassengerRuby /usr/local/bin/ruby
RailsEnv production)
 
    post :install, "echo '#{conf}' >> /etc/apache2/mods-available/passenger.conf"
    post :install, "echo '#{loading}' >> /etc/apache2/mods-available/passenger.load"
    post :install, 'a2enmod passenger'
    # Restart apache to note changes
    post :install, '/etc/init.d/apache2 restart'
  end
 
  verify do
    has_file "/etc/apache2/mods-enabled/passenger.load"
    has_file "/usr/local/ruby-enterprise/lib/ruby/gems/1.8/gems/passenger-#{version}/ext/apache2/mod_passenger.so"
    has_directory "/usr/local/ruby-enterprise/lib/ruby/gems/1.8/gems/passenger-#{version}"
  end
 
  requires :apache, :apache2_prefork_dev, :ruby_enterprise
end

Now, it takes advantage of the debian convention of keeping module loading and configuration files go in /etc/apache2/mods-available that are symlinked into /etc/apache2/mods-enabled by the a2enmod utility. This is immediately obviously awesome to anyone who has contemplated the horror of trying to parse the apache main config to see if the stuff they want to add is already there and needs updating.

I also added some verifiers so that it won’t rerun if there were no errors. Pretty cool, no?

Ruby is awesome–lazy scripting

Monday, April 20th, 2009

Sometimes I find myself doing tedious things like trying to grab the dollar amounts from text copied from the web. More and more often I turn to irb for these sort of things. For example, a few minutes ago, when I wanted to analyze my spending habits I copied the data into a file and manipulated it.

I grabbed the lines from the file

irb(main):001:0> lines = File.readlines 'transactions'


And selected those with dollar signs (with a little effort–sometimes I forget whether it is =~ or ~=).

irb(main):002:0> monies = lines.select {|l| l ~=  /\$(.*)/}
SyntaxError: compile error
(irb):2: syntax error, unexpected '='
monies = lines.select {|l| l ~=  /\$(.*)/}
                               ^
	from (irb):2
	from :0
irb(main):003:0> monies = lines.select {|l| l =~  /\$(.*)/}

Then I grabbed the numbers using map.

irb(main):008:0> nums =monies.map {|m| m.sub( /\$(.*)/,$1).to_f}

From there, I could do all sorts of things.

I could sum numbers.

 total =nums.inject(0){|sum,i|sum+i}

I could get the average.

total/nums.length

I could even see how much of the total was due to transactions under $20.

nums.reject {|i|i>20}.inject{|s,i|s+i}

In short, I like ruby.

What I am Reading

Sunday, April 19th, 2009

I have this bad habit of reading books concurrently. Partly, it is because I like to graze on books. Sometimes a technical stuff is too heavy, sometimes even space opera is too much…maybe not.

  • Ruby in Practice I have written a bit about this already
  • Programming ErlangI started this, got side tracked and have started reading it again.
  • Godel Escher Bach Just awesome
  • Misspent youth Peter F. Hamilton is my favorite space opera writer. This isn’t space opera though it deals with many of the same things his space operas do. 70 year old man receives rejuvenation treatment->20 and the weirdness that ensues.
  • Ender in Exile Not as good as I would like so far, but I am giving it more time.

Quake Live is a wonderful…

Friday, April 17th, 2009

..way to get my fps fix.

I rock-ish

Also,
funny pictures
moar funny pictures

Ruby in Practice is Good

Thursday, April 16th, 2009

I have been reading Ruby in Practice over the past week or so as you know. Currently, I am on page 114 which talks about using active resource to consume RESTful webservices( you could use RESTClient, but thats another story) and has a box about the ever awesome BlankSlate class.

I haven’t really learned many “whoah, ruby does what?? Sweet” things from it, most of those are behind me. Now, I get more “Whoah, X project really abstracts that annoying thing into a nice interface.” kind of feelings, which are more satisfying in some ways and less in others. I guess what I am saying is that I have grown to know ruby much better over the past six months or so using it at work every day, than the past, uh, five? years. Which is sweet.

But back to the book( I ramble when I feel braindead):

The things I have learned from reading this book remind me of ruby itself. It has glued together various bits of ruby that I know, in the same way you can use ruby to glue together other technologies. Most of my ruby smarts have been picked up through hacking at things and reading blog posts by knowledgeable people, but that sometimes leaves some gaps in my knowledge. This book has helped me to tie some of the things I have learned together(w00t Hebbian Learning).

For instance, spec tasks

While I know that rspec has a set of extensions for rake, I had not used them outside rails, in fact in the project I was working on I just wrote the following.

task :spec do
  sh "spec --colour --reverse #{FileList['spec/**/*_spec.rb']}"
end

The problem with this is that when any of the specs fail, I get a huge trace from the ran shell script that I have to scroll past before I can see the failed specs.

But, if I included the spec tasks I could do stuff more like this.

require 'spec/rake/spectask'
Spec::Rake::SpecTask.new('spec') do |task|
  task.spec_files =FileList['spec/**/*_spec.rb']
  task.spec_opts = ['--colour','--reverse']
end

Now things work like they do when you generate the tasks from within rails. I had read the lib/tasks/rspec.rake file when I was looking over the generated code in one of my rails apps, but it was a little too complicated to grok easily.

The other things I am looking for are cool projects that I should be more aware of. Sometimes, they are only mentioned but that doesn’t mean they are not awesome. Some that I would like to play with include:

  • Chronic a date string parser that tries to be able to handle stuff like: “next tuesday” and “summer”
  • FasterCSV I saw this at Mountain West Ruby Conf and made a mental note to read it at some point(so much for mental notes)
  • Heckle runs tests. Breaks your code. Sees if the tests fail like they should.

Later.

Labor: A Labor Saving Device

Wednesday, April 15th, 2009

Confused?

I did some chores today. Laundry, cleaned kitchen counter tops. I really think about these things more than they are worth. Usually I just grumble about it, or read books on time management. The problem is I spend so much time thinking about and avoiding it, it would have taken less time just to do it.

It is a sort of zen, or yoda thing. About mindset.

Do or do not, there is no try.

or

Does a dog have a buddhalike nature?

The answer is Mu. In that the question is stupid on the face, and there is no valid answer. It isn’t a “Why is the sky blue” sort of question.

“Would it be better to do A or B?”

The answer is either if you are not doing anything yet.

I feel accomplished today.

Also, Bacolicio.us

Moo Revealed

Tuesday, April 14th, 2009

I got some Moo cards a while back. I was trying to have them for mwrc, but alas I ordered them too late. Anyway, here they are:

moo

TED, Inspiration, Etc

Monday, April 13th, 2009

When I was in Japan, I was introduced to TED by one of my professors( he does presentationzen). Since then I have gone to their website every now and and again to watch the amazing and inspiring talks they have. One of the reasons I think TED is so great is that it puts a big emphasis on really good presentations. It probably also has an amazing back channel, hallway atmosphere–whatever. I was going to say something about how it costs a lot to attend, but after reading some of the registration info, I saw that it is more complicated than that. You need to apply to even attend the conference.

So, the presentations are awesome.

My Senior year of my CS degree, I would spend my lunches in the ACM room, watching TED talks and occasionally taking naps. I often stayed up too late and was tired in the middle of the day. A tradition I am still continuing as you would know by looking at the times I post on my blog.

And now for something moderately related.

I have been interested in the effect of mobile communications on social interaction for a while now, so I found this funny, especially since I am interested in getting a smarter phone than my current.

Spring

Sunday, April 12th, 2009

Daffodils