Category: Ruby

  • Why Clint Eastwood is My Programming Hero

    This post has been stewing for a while. I’ve struggled for a way to describe the needless clash I see between the communities I work in. But I think I’ve found my analogy. Ever watch a Clint Eastwood Western? Not Dirty Harry, or any the modern-setting movies he’s been directing lately, but the Westerns. In […]

  • Simple String Extension in Ruby

    Based on a blog post from Steve Yegge… #ruby class String def endswith(arg) (self =~ /.*#{arg}$/) != nil end end #to test irb>”extension”.endswith(“ion”)

  • Benchmarking Recursion Using Factorial Function

    def fact(n)   (1..n).to_a.inject(1){|f,n| f*n} end def recursive_fact(n)   return n==1 ? n : n * recursive_fact(n-1) end require ‘benchmark’ do |b|“inject”){1000.times{fact(100)}}“recursive”){1000.times{recursive_fact(100)}} end

  • Mysql Gem on Leopard

    After getting a whole lot of errors, I found the only way I could get this gem to work is the following: -Install x86 version of mysql -Install Gem like the following: sudo gem install mysql — –with-mysql-dir=/usr/local/mysql –with-mysql-config=/usr/local/mysql/bin/mysql_config –remote I hope that helps…

  • Curry in Ruby

    Inspired by some currying examples in scheme, I wanted to try them in Ruby… def seq(oldfirst, keepold) lambda do |new, old, item, list| list.push(new) if old==item and  !oldfirst list.push(item) if keepold or old != item list.push(new) if oldfirst and old==item end end def insertF(new, old, list, func) temp = [] list.each do |item| new, […]