While tinkering with Ruby 1.9 in TextMate I found that Ruby was segfaulting on the TextMate Ruby Bundle output screen.
/Users/codethought/Applications/TextMate.app/Contents/SharedSupport/Bundles/Ruby.tmbundle/Support/RubyMate/catch_exception.rb:16: [BUG] Segmentation fault
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.4.0]
Turns out you can fix the error yourself… as I found at rubyflow.com
To quote here:
Edit the catch_exception.rb file in your Ruby bundle in TextMate. To get into it on my machine I had to do:
Then, comment out the require “cgi” line. And then remove all references to CGI::escapeHTML.
But a simpler way is to go is to download the change that someone else made from github and install it yourself.
And put the new version catch_exception.rb in the following directory yourself:
And your problem will be resolved.
I’m sure you’ve probably seen this question in your programming classes.. I decided I wanted to play with Ruby again and was remind of this problem, so thought it might be fun as a simple exercise to do this in Ruby.
The problem is to take a long integer and convert it to hours, minutes and seconds. This is a common issue in games, for example, where a countdown timer is represent internally in seconds. But players don’t want to see some huge number like 43678 seconds. They’d rather see 12:07:58 for hours, minutes and seconds. A couple of uses of the mod operator, and a couple of uses of the built-in formatter and you’re good to go.
Update: I wanted to clean up the code a bit more and put the ruby equivalent of a “main” via the
__FILE__ check. This way you can just reuse the code via require if you so desire.
def format_time (timeElapsed)
@timeElapsed = timeElapsed
#find the seconds
seconds = @timeElapsed % 60
#find the minutes
minutes = (@timeElapsed / 60) % 60
#find the hours
hours = (@timeElapsed/3600)
#format the time
return hours.to_s + ":" + format("%02d",minutes.to_s) + ":" + format("%02d",seconds.to_s)
if __FILE__ == $0
formatter = TimeFormatter.new
While I was getting some old Ruby code of mine out to convert ruby code to pretty HTML-formatted code suitable for blogging from Wolfman’s Howlings I got the following error:
./ruby2html.rb: line 9: require: command not found
./ruby2html.rb: line 10: require: command not found
./ruby2html.rb: line 11: require: command not found
./ruby2html.rb: line 14: syntax error near unexpected token `('
./ruby2html.rb: line 14: ` code= File.read(ARGV)'
Never saw this problem before, but obviously it was frustrating.
What had happened was I hadn’t deleted the tab spaces before the
#!/usr/bin/env ruby line.
Apparently if there is any white space before the #!/usr/bin/env ruby the script will not run.
While I was playing with Rails 2.1 I decided to try the SQLite3 support that comes built into OS X instead of using MySQL. Upon trying to run a migrate command via rake I was created with:
no such file to load -- sqlite3/database
After some digging around I found out that (for at least a few people) having the
sqlite3-ruby-1.2.2 gem installed creates this problem… The following resolved it:
gem uninstall sqlite3-ruby
Select gem to uninstall:
3. All versions
daorriss$ sudo gem install sqlite3-ruby -v=1.2.1
Building native extensions. This could take a while...
Successfully installed sqlite3-ruby-1.2.1
1 gem installed
Installing ri documentation for sqlite3-ruby-1.2.1...
Installing RDoc documentation for sqlite3-ruby-1.2.1...
After that rake db:migrate worked without a hitch. But if anyone could tell me what could cause the problem with sqlite3-ruby-1.2.2 I’d appreciate it.. 🙂
I don’t know why this isn’t better documented or stated anywhere so I’ll just iterate it here. If you want to peruse the documentation for Rails and your installed Gems type the following
And in your terminal prompt you should see
Starting gem server on http://localhost:8808/
And you should be set.
Mongrel Developer/Creator, Zed Shaw, cut loose on the Ruby and Rails communities in a recent posting to his website. He gives some interesting insights into who the major players are, and cuts through some of the hype surrounding rails.
While caustic in his delivery, he makes excellent points about the industry in general. If you’re a .NET developer – you won’t like the jabs in it. If you’re a VB.NET developer – find another blog – you shouldn’t be here anyway – much less reading Zed’s stuff. Most of what I write probably shoots right over your head, anyway.
But I digress.. while reading his rant, Zed got me thinking about Rails and the actual availability of work for Rails developers. Especially when he mentions the fun times he had with the Raymond James Vancouver offices (his mistake there was working for a company that deals in financial data – oh the stories I could tell about Actuaries). Anyway… the question I asked myself is simple enough – what if I actually needed to find a job doing Rails development in Seattle right now? I was rather disappointed to see in the midst of all of the Rails-hype that there are only three jobs involving Rails in the Seattle area at the time I write this (according to Monster.com). One of them is for a small dot-bomb shop, one is for Amazon (I’d rather eat hot lead then work at Amazon) and one is actually a System Administrator/Tech Support position and involves no development at all.
I was talking about this exact situation with one of my friends who works for a major software tools vendor (No, not Microsoft – my .NET developer friends know better than to try to sell me on their shallow J2EE ripoff). I was talking to him about that there’s all of this hype around Rails.. but I’m not seeing any real job demand for it. This wandered into the a discussion about biggest Rails Hypefest of them all – RailsConf. People come from miles around to get dipped in the Rails Kool-Aid and renew their momentum for the Rails Hype Machine. About how Rails is the Next Big Thing(sm).. about how Rails is the next Java only bigger and better!!
Now… lots of hype.. the “next big thing”… where have I heard this before..? Something about “Write Once, Run Anywhere”…
Anyway… What he said to me about RailsConf was what I had largely noticed. Most of the attendees are basically kids with little or no practical industry experience who think Ruby on Rails is the up and coming thing and want to ride that wave. And Zed’s right – there really are people in that community that are saying that if you love Visual Basic and ColdFusion then you should come over to Ruby on Rails. Why? Because the VB programmers got found out for the lousy coders they are and got rousted out of the J2EE developer community??
Don’t get me wrong… I love Rails… And Ruby is a fun language to code in. I still love Java and J2EE and I’m very proud of the work I’ve done in it. However, Java was hyped so badly when it came out that it really hurt the technology and my ability to evangelize it. So much so in fact that for a while I was having a hard time finding work. Worse yet, Sun still hasn’t learned their lessons and still tries to hype garbage technologies with little actual value. And Rails really has a ton of potential to be a “Next Big Thing”. But they need to do less hype and focus on keeping their community together and working on solid tools. Yes.. that includes learning to get along with the crazy brother that everyone hates, but everyone also knows is right.
Most people when they get into developing for Ruby on Rails on OS X probably use this handy guide to install the latest Ruby and Rails on OS X
If you build Ruby on your Leopard installation to use the latest and greatest ruby-1.8.6-p111 release following that guide you’ll probably be greeted with something like this upon calling
gcc -I/sw/include -fno-common -pipe -fno-common -DRUBY_EXPORT -I. -I. -I/sw/include -c dmyext.c
ar rcu libruby-static.a array.o bignum.o class.o compar.o dir.o dln.o enum.o error.o eval.o file.o gc.o hash.o inits.o io.o marshal.o math.o numeric.o object.o pack.o parse.o process.o prec.o random.o range.o re.o regex.o ruby.o signal.o sprintf.o st.o string.o struct.o time.o util.o variable.o version.o dmyext.o
gcc -I/sw/include -fno-common -pipe -fno-common -DRUBY_EXPORT -I. -I. -I/sw/include -c main.c
gcc -I/sw/include -fno-common -pipe -fno-common -DRUBY_EXPORT -I. -I. -I/sw/include -c dmydln.c
gcc -I/sw/include -fno-common -pipe -fno-common -DRUBY_EXPORT -L. -L/sw/lib main.o dmydln.o libruby-static.a -lpthread -ldl -lobjc -o miniruby
ruby: [BUG] Segmentation fault
ruby 1.8.6 (2007-09-24) [i686-darwin9.1.0]
make: *** [.rbconfig.time] Abort trap
It’s a simple fix. Just remove the
--enable-pthread configuration option.
./configure --prefix=/usr/local --disable-pthread --with-readline-dir=/usr/local --enable-shared
make call should run without incident. The only real change I’ve noticed (no doubt related to disabling pthreads) is that my Ruby benchmark takes longer to run…
Ruby 1.8.6 patch 111 on i686-darwin9.1.0
It took 10.488273 seconds to run. 95344 iterations per second.
My friend Lori noted a great way to Add to the Ruby Library Path. She also noted that I had no way to put comments on my blog. Users would get sent to a page telling them to log in, but I never provided the login link
Fixed — check out the “Links” section on the blog page. You’ll see there are two new links to Register and Login. You have to register so you can log in so you can post comments.
In Ruby not library management is not always as simple as running
Some Ruby code is distributed simply as libraries. So where do you put these libraries? The clue is
in the Ruby
irb(main):001:0> puts $LOAD_PATH
This tells you that you can put your library code in any of the above listed directories and
if Ruby still can’t find the code it will try the current directory you’re running code in before
Personally I end up using the
I just saw on the Codegear Ruby newsgroups that a vulnerability on the net/https
library was reported. Basically the library doesn’t validate the server certificate
CN (Common Name).
You can read the details here:
Patches have been done for Ruby to accommodate this and you can download them from here: