If you’re wondering what happened to this site, I decided that I was sick of trying to use Mephisto for blogging software. I love Rails development, but Mephisto was a pain in the ass and a major memory hog compared to a much more stable Wordpress. It was taking down my slice pretty regularly and discouraging me from posting because it was a pain to use comparatively. I haven’t moved the old posts over yet, but they will be coming in the next few weeks. I’d move them sooner, but they’re mostly about stuff that is long since out of date. I’d say I hope to post more frequently, but I’m not entirely sure that’s true. We’ll see if having an easier to use blogging system installed precipitates more frequent posting.
Mephisto no more
May 25th, 2009Programming Perl Instead of Ruby
July 13th, 2008I’ve got a new job and it’s working almost completely in Perl. Who’d have thought? Fortunately, it really is true that if you know one programming language fairly well, you’ll understand others fairly easily. Modifying code in Perl is easy as long as I have other code to refer to, and I often forget it’s a new language. Learning all the names, faces and practices in my new job is much harder than learning a bit of new syntax. However, if I had to sit down and write something in Perl from scratch it would not go well.
There’s definitely a few things I’ve noticed about Perl that I don’t like compared to Ruby:
* Sigils. I keep forgetting to prepend my variables with those $@% sigils. That’s not me cursing there, those are the sigils for scalars, arrays and hashes. The worst is when you’re references the whole array (@foo) you use a different sigil than when you’re referencing a scalar element in the array ($foo[0]).
* Objects feel like a hacked up addon to the language. You have to “bless” things to make them objects and you’re always passing around references to $self to object methods. You can’t make methods private. Weird stuff.
* No interactive shell built in. I loved having irb to try things out when I was learning Ruby - heck, I still do. Fortunately, after a bit of searching and bad advice on just using the Perl debugger I found Perl Console.
* Always needing to say “my variablename” instead of just “variablename” if I want local variables. It seems like variables should be local by default and you say something if you want to make them local.
There’s some things about Perl I’m not sure if I like or dislike yet:
* Default variables. Strangely named variables like $_ and @_ pop up everywhere. The idea is if you don’t want to come up with a name for variables while you’re iterating or passing parameters, you don’t have to thus saving all that typing and thinking. However it certainly makes the code harder to read for those who don’t know Perl and I suspect it might make things always harder to read even once I get used to it.
* Regular expressions everywhere. This will be good for me to get better with this powerful feature, but damned if regular expressions aren’t ugly.
* There’s always more than one way to do something. This is true in most every language, but Perl seems to take a lot of pride in it, and often the idiomatic Perl way of doing something is quite a bit harder to read than the non idiomatic way.
The main thing I like about Perl so far is that the Perl community seems to have a sense of humor. Perl books are always making jokes and variables in Perl code are given entertaining names.
Aside from the new language difference, the new job is great for me to get used to coding in a large codebase and with teams. We use quite a few Extreme Programming practices like test driven development, and even more impressive, pair coding. These practices more than make up for anything I don’t like about Perl.
ruby-debug 0.10.1 Broken On Windows
May 24th, 2008Since the old rails breakpointer quit working in versions of Ruby after 1.8.4, the preferred method for debugging rails has been to use ruby-debug. This is a separate gem, so to install you just do
gem install ruby-debug
However, the current version of ruby-debug (0.10.1) runs into problems on Windows, namely it doesn’t work and spews out an error message when you try to run it directly:
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require’: no such file to load — c:/ruby/
lib/ruby/gems/1.8/gems/linecache-0.42-x86-mswin32/lib/../ext/trace_nums (LoadError)
from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require’
from c:/ruby/lib/ruby/gems/1.8/gems/linecache-0.42-x86-mswin32/lib/tracelines.rb:8
from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require’
from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require’
from c:/ruby/lib/ruby/gems/1.8/gems/linecache-0.42-x86-mswin32/lib/linecache.rb:63
from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require’
from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require’
from c:/ruby/lib/ruby/gems/1.8/gems/ruby-debug-base-0.10.1-mswin32/lib/ruby-debug-base.rb:3
from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require’
from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require’
from c:/ruby/lib/ruby/gems/1.8/gems/ruby-debug-0.10.1/cli/ruby-debug.rb:5
from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require’
from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require’
from c:/ruby/lib/ruby/gems/1.8/gems/ruby-debug-0.10.1/bin/rdebug:7
from c:/ruby/bin/rdebug:19:in `load’
from c:/ruby/bin/rdebug:19
I’ve found two possible ways to fix this. The first is simply to revert back to ruby-debug version 0.10.0
gem uninstall ruby-debug
gem install ruby-debug –version “=0.10.0″
The other way to fix the problem I found on a ticket in Rails Trac
In the file ruby\lib\ruby\gems\1.8\gems\linecache-0.42-x86-mswin32\lib\tracelines.rb
I changed the line from
require File.join(@@SRCDIR, ‘..’, ‘ext’, ‘tracenums’)
to
require File.join(@@SRC_DIR, ‘..’, ‘ext’, ‘extconf.rb’)
I suppose the advantage to this method is that you have the newer version of ruby-debug with all it’s fixes, although I don’t really know what those are.
Finally Back Online
May 6th, 2008Now that I’m finally back in the USA it’s time to start blogging about technical things again. I doubt anyone really noticed, but this site was down for the last few months as my free Rails hosting expired back in February and I didn’t bother to renew it. I was also too busy to resetup Mephisto on my other server, especially since I haven’t found that I’ve liked Mephisto very much. I decided I’d continue with it and try to change the things I didn’t like, if for no other reason than it’s good practice deploying Rails apps. I’ll have the old articles back up in the near future.
Rails Plugins: scope_out and will_paginate
June 26th, 2007Round 1: scope_out
A plugin I have found immensely useful is the scope_out plugin by John Andrews. The rationale for using the plugin is very nicely summed up by Dan Manges:
* Your conditions are defined in ONE place.
* You can extend associations if you want caching.
* The ‘raw’ with_scope is available, making applying multiple conditions easy.
* The find and calculate methods are both available.
Use it like so:
class Project < ActiveRecord::Base hasmany :tasks, :dependent => :deleteall end
class Tasks < ActiveRecord::Base belongs_to :project scope_out :active, :conditions => “status = ‘active’” end
Now you can do the following:
# All active tasks
@tasks = Task.find_active(:all, :order => ‘due_on’)
# The active tasks for the project with memoization preserved
@tasks = @project.tasks.active
If you don’t see why that’s useful or understand what the means, read the whole blog post and contrast it with Jamis Buck’s take on associations, which is what originally led me to scopeout. I don’t like Jamis’ idea of defining methods on the associations because there’s some methods I need to use as part of the association OR as just a method on the original class. Also, what if a user also hasmany tasks? You have to redefine what ‘active’ is for that association too.
To install it appears you have to go to the svn repository since it’s not found in the default rails plugin repositories
ruby script/plugin install http://scope-out-rails.googlecode.com/svn/trunk/
and then rename /vendor/plugins/trunk to /vendor/plugins/scope_out. Round 2: will_paginate
Using scoped out I’d been paginating my conditions with Rails classic pagination
def index
@task_pages = Paginator.new self, Task.find_active(:all).count, 10, params[:page]
@tasks = Task.find_active(:all, :order => ‘due_on’,
:limit => @person_pages.items_per_page,
:offset => @person_pages.current.offset)
end
But now that pagination isn’t going to be part of the rails core I went looking for what people were going to do and found Err’s will_paginate plugin, which is slicker than what I’ve been doing anyway.
@tasks = Task.paginate :page => params[:page]
But can I still use my scope_out definitions?
@tasks = Task.paginate_active :page => params[:page]
NoMethodError: undefined method `find_all_active’ for Task:Class
Not yet. willpaginate implements a method missing bit o’ code so you can do findby’s with an implicit all:
# These are equivalent
@tasks = Task.paginate_by_priority “high”, :page => params[:page]
@tasks = Task.paginate_all_by_priority “high”, :page => params[:page]
However, the way the regular expression is written messes up scopeout. This is easily fixed by replacing one line of code in vendor/plugins/willpaginate/lib/will_paginate/finder.rb. Replace
finder.sub! /^find/, ‘find_all’
on line 91 with
finder.sub! /^find_by/, ‘find_all_by’
Now paginateby will still have an implicit all and scopeout definitions will work with the pagination. I’m pretty sure this change doesn’t break anything with the will_paginate plugin, but if anyone finds problems with this let me know.
Peepcode: Building a Full Rails Stack on Ubuntu 6.06
May 7th, 2007I just signed up for a slicehost account today and am trying to setup my new server according with the deprec capistrano recipes according to the free bonus peepcode video: Building a Full Rails Stack on Ubuntu 6.06.
The first capistrano task you have to run is really hard to read since the free video download is pretty poor quality, so you can’t read the underscores very well at all.
cap setup ssh keys
should be
cap setup_ssh_keys
running it the wrong way got me the error
command “sudo chgrp -R deploy /var/www/apps/rails_app” failed on www.servername.com
RCov - Code Coverage in Rails
April 17th, 2007If you haven’t been doing test driven development, and you should be, you may not be sure how well tested your rails application is. You can use rake stats to get your code to test ratio, but that only gives you a general sense of how you’re doing, but just knowing that your ratio is 1.0 to .7 doesn’t really ensure anything. You can write some tests in one line that test dozens of lines of code fairly well.
This is where using rcov comes in to save the day. Thankfully Coda Hale has written a rails plugin to make running rcov on your projects super easy. The instructions on his page tell you to install rcov by downloading it, but there’s a prepackaged gem that makes installation even easier. Let’s install it:
gem install rcov
Now Coda Hale recommends installing the plugin using -x to add and svn:externals entry, but I can’t stand having svn:externals since every time I want to update or commit I become dependent on someone else’s svn repository. You’re better off using piston if you need to keep your plugins up to date. So go ahead and run:
ruby script/plugin install http://svn.codahale.com/rails_rcov
Now you’re pretty much done for installing. Just run rake with a little change
rake test:units:rcov
You’ll now find a folder in your rails project called coverage. Look in there and find the index file and open it up. You now can see how well covered all your models are. If you open the individual model coverage file you can see exactly which lines aren’t covered and begin writing tests for them. There’s other options you can pass to rcov too, so take a look at the documentation if you want to get fancy. The only other command I run is
rake test:functionals:rcov RCOV_PARAMS=”–sort=coverage”
So the difference there is I’m testing the controllers with functionals instead of the models with units and sorting the output by code coverage. This way I can easily see the models and controllers I need to do the most work on.
Moving the Documents and Settings Folder to a Different Drive
March 23rd, 2007I thought this would be easy, and it was - once I figured out one little thing. You’ll probably come across Microsoft’s KB Article 236621 which got me most of the way there. The second method listed says to search the registry and replace all instances of “Documents and Settings”. This works fine if you’re just moving the folder to somewhere else on the same drive with a different name. However I wanted to move all the user profiles from the C drive to the same folder name on the D drive on a terminal server.
First of all, trying to do this with the regular old regedit program is awful since it doesn’t do search and replace. I found a free program called Blade’s Registry Replacer that worked great for doing search and replace on the registry and generating an undo file.
Now that you’ve got that you’ll want to replace all instances of “C:\Documents and Settings” AND all instances of “%SystemDrive%\Documents and Settings” (this is the part I was missing earlier) with “D:\Documents and Settings” or whatever you want to call the folder on the D drive.
Feisty Fawn Upgrade
March 16th, 2007I don’t know what possessed me to upgrade before this is technically even in beta, but Kubuntu’s update manager asked if I wanted to with a nice easy to click ‘yes’ button. What’s it doing tempting me like that? For a prebeta it went pretty well. It had to download over a Gig of new files. Once that was finally done it started installing, and something went wrong. It then notified me I needed to reboot. I wish I hadn’t.
kernel panic : not syncing; VFS: Unable to mount root fs on unknown-block(0,0)
I found tons of articles on google, but it took a while to find something helpful. Finally I found the following advice:
1. boot from live cd
2. open a terminal
3. mkdir /mnt/linux
4. mount /dev/hda1 /mnt/linux
5. chroot /mnt/linux /bin/bash
6. mount -t proc /proc /proc
What this does is essentially give you a terminal working on your hard drive that isn’t booting. From there I just ran
sudo apt-get dist-upgrade
to finish the install process, and amazingly linux boot up and the new artwork looks very nice. So far every time I’ve upgraded Ubuntu it breaks my wireless, so I’m getting pretty good at fixing it. My built in wireless card on my Inspiron 9300 is Network controller: Broadcom Corporation BCM4309 802.11a/b/g (rev 03). I have to use ndiswrapper to install drivers. Running
ndiswrapper -l
showed the driver was still installed but running but iwconfig had the incorrect card showing. Thank goodness for ndiswrapper’s driver list that took me forever to find before. It has links straight to the driver downloads. I figured I’d reinstall the drivers, but once I did running dmesg showed
bcm43xx: Error: Microcode “bcm43xx_microcode5.fw” not available or load failed.
Looks like the new wireless drivers I downloaded needed a newer firmware. I found running
sudo aptitude install bcm43xx-fwcutter
sudo /usr/share/bcm43xx-fwcutter/install_bcm43xx_firmware.sh
took care of that for me. Phew. And now I’m running Feisty Fawn with working wireless. I’m not seeing a lot of differences so far, but this is the first thing I’ve done.
User Control In Linux
February 15th, 2007There’s a great article that touches on something I mentioned in my previous Linux post. While I usually perceive a benefit from being able to endlessly tweak Linux, sometimes I don’t and very few other people ever will. Kathy Sierra makes the best graphs and graphics for her article, and one that applies here is the “Is your product worth the users effort?”. The perceived payoff for Linux is still fairly low, and the learning curve very high. While the perceived payoff for upgrading to Windows Vista might also be low, at least the perceived learning curve and pain is also low.
Some free Linux distribution really needs to address the “canyon of pain” that users have to cross to make the switch. As much as advanced users often hate things like wizards, something like this could really help out a lot of new Linux users. Or even something as silly as the welcome to Windows movie that comes with new Dells. I can’t wait to get these things turned off considering I’ve bought and built dozens to hundreds of computers in my work, but when I hand over those new computers to users who aren’t computer savvy, the first thing they really want is desktop icons linking to tutorials. For most users just learning how to check their email would be kicking ass on a new operating system, forget about piping commands or using awk.
I know something I’d love to see is a bunch of peepcode style screen casts that come preloaded. I’ve been loving these things lately for learning some Rails stuff even though I already most of the stuff in them. I wish I had known about them before to save myself hours of combing through blog articles and api documentation to get the basic concepts. The articles and API documentation are great for reference once I understand basically what I’m doing, but man are they a slow way to feel like you’re ready to kick ass. And that’s exactly where new windows users are. There’s plenty of articles and forums out there, but they take a long time to wade through. Even some great concise places like ubuntuguide are great for getting software installed, but past that you’re pretty much on your own.
In summary, all the control users have in Linux is great in the long run, but there needs to be a way to easily just get new users started that doesn’t leave them feeling overwhelmed and lost.