test helper

I added assert_empty to check that an array is empty.

But the line number from test helper.rb was the first line of the test helper, not the line in the test.

Instead, I wanted to see the actual failure as the first line. Welcome remove_me_from_trace(exception)

class Test::Unit::TestCase
  def assert_empty(*args)
    begin
      args.unshift []
      assert_equal *args
    rescue => e
      raise remove_me_from_trace(e)
    end
  end

  def remove_me_from_trace(e)
    x=e.backtrace.shift until (x =~ /test_helper.rb/ )
    e
  end
end

even better rake db:migrate

I normally don’t like hacking rails files directly, but this is the only way I could extend rake db:migrate to support a friendly VERSION.

railities/lib/tasks/database.rake on line 111.

  # was ENV["VERSION"] ? ENV["VERSION"].to_i : nil
  # looks up version based upon migration files
  def version_num
    version=ENV["VERSION"]
    if version.to_i==0 && version.present?
      matches=Dir["db/migrate/*#{ENV["VERSION"]}*"]
      if matches.length > 0
        #prune off directory name
        matches=matches.collect{|n| n.gsub(/^.*\//,'')}

        unless matches.length == 1
          raise "VERSION #{version} matches "+
            "#{matches.join(', ')}"
        end

        #prune off version num
        version=matches.first.gsub(/([^_]*)_.*$/) {$1}
        puts "VERSION=#{version}"
      end
    end
    version ? version.to_i : nil
  end

In 3 places (migrate, up, down), the version code is changed from

ENV["VERSION"] ? ENV["VERSION"].to_i : nil

to

version_num

Now rake db:migrate:down VERSION=create_photo works like a charm.

better rake db:migrate

I have been using a schell script so I don’t need to remember the long version number associated with ruby migrations.

#given a migration task, return the version
#e.g.: rake db:migrate:redo VERSION=$(mver create_photo)
function mver() {
  scr=${1:?Please specify migration action}
  ls db/migrate/*${scr}* | sed 's=^[^0-9]*\([0-9][^_]*\)_.*$=\1='
}
which will run migration 20100302214328_create_photos_and_folders.rb

Had an error about removing Object::ClassMethods.
I added the following to environment.rb to help me home in on the conflict.
RAILS_DEFAULT_LOGGER = Logger.new(STDOUT)
ActiveSupport::Dependencies::log_activity = true

Had an error about removing Object::ClassMethods.

I added the following to environment.rb to help me home in on the conflict.

RAILS_DEFAULT_LOGGER = Logger.new(STDOUT)
ActiveSupport::Dependencies::log_activity = true
New Hope: I’ve failed a few times ripping my DVDs to the network so I can watch on my TV/WDTV Live. But this time it looks promising
Ripping is easy, but my mkv files have been horrible. Am backing up to an iso so I can re compress these videos once I figure out my best options.
#mov_dir is the directory that contains the the VIDEO_TS directory.
hdiutil makehybrid -o "${mov_dir}.iso" "${mov_dir}"
thanks

New Hope: I’ve failed a few times ripping my DVDs to the network so I can watch on my TV/WDTV Live. But this time it looks promising

Ripping is easy, but my mkv files have been horrible. Am backing up to an iso so I can re compress these videos once I figure out my best options.

#mov_dir is the directory that contains the the VIDEO_TS directory.
hdiutil makehybrid -o "${mov_dir}.iso" "${mov_dir}"
thanks
Question: Is it possible to calculate the Pythagorean Formula without the use of a square root function? source
In order to support Geokit in sqlite3, I need a way to calculate distances that does not require cosine or square root. In my problem space, the points are relatively close to each other.
C1=A+B
The error was very similar to the size of the lowest number. So subtracted a fraction of the lowest number.
C2=A+B-min(A,B)*0.6
Restated the formula with min and max, and tweaked the ratios.
C3=max(A,B)*0.945 + min(A,B)*0.415

calculation references
ABCc1errorc2errorc3error10001000141420005861400-1413605410007501250 17505001300501256-610005001118 15003821200821153-3410002501031 12502191100691049-18100001000   1000  01000 094555Please share if you can help me come up with a better approximation or if you see an error.
thanks Meridian.

Question: Is it possible to calculate the Pythagorean Formula without the use of a square root function? source

In order to support Geokit in sqlite3, I need a way to calculate distances that does not require cosine or square root. In my problem space, the points are relatively close to each other.

C1=A+B

The error was very similar to the size of the lowest number. So subtracted a fraction of the lowest number.

C2=A+B-min(A,B)*0.6

Restated the formula with min and max, and tweaked the ratios.

C3=max(A,B)*0.945 + min(A,B)*0.415
calculation references
ABCc1errorc2errorc3error
10001000141420005861400-14136054
10007501250 17505001300501256-6
10005001118 15003821200821153-34
10002501031 12502191100691049-18
100001000 1000 01000 094555

Please share if you can help me come up with a better approximation or if you see an error.

thanks Meridian.
require 'hotcocoa'
class Application
  include HotCocoa
  FULL={:expand => [:width,:height]}
  SHOW=[0,0,0,100]
  def start
    application :name => "MyTableView" do |app|
      app.delegate = self
      window(:title => "MyTableView",
        :frame => [10, 620, 330, 230]) do |win|
        win << split_view(:horizontal => true,
          :layout => FULL,:frame=>SHOW) do |sp|
          sp << sc=scroll_view(:frame => SHOW)
          sc << @tv=table_view(:data=>[],:columns=>[])
          sp << @pr=text_field(:text => 'type here',
            :font => font(:name=>'Monaco', :size => 16),
            :on_action => Proc.new {|t| type(t.to_s)})
        end #sp
        win.contentView.margin = 5
        win.makeFirstResponder @pr
        win.will_close { exit }
      end #window (win)
    end #application
  end
  def type(t)
    values={}
    t.split.each_with_index do |v,i|
      values["c#{i}"]=v
      if i >= @tv.tableColumns.size
        @tv.tableColumns << column(:id=>"c#{i}",
          :title=>"Word #{i+1}")
      end
    end
    @tv.dataSource.data << values
    @tv.reloadData
  end
end
Application.new.start

#thanks again to everburning.com

require 'hotcocoa'
class Application
  include HotCocoa
  FULL={:expand => [:width,:height]}
  SHOW=[0,0,0,100]
  def start
    application :name => "MyTableView" do |app|
      app.delegate = self
      window(:title => "MyTableView",
        :frame => [10, 620, 330, 230]) do |win|
        win << split_view(:horizontal => true,
          :layout => FULL,:frame=>SHOW) do |sp|
          sp << sc=scroll_view(:frame => SHOW)
          sc << @tv=table_view(:data=>[],:columns=>[])
          sp << @pr=text_field(:text => 'type here',
            :font => font(:name=>'Monaco', :size => 16),
            :on_action => Proc.new {|t| type(t.to_s)})
        end #sp
        win.contentView.margin = 5
        win.makeFirstResponder @pr
        win.will_close { exit }
      end #window (win)
    end #application
  end
  def type(t)
    values={}
    t.split.each_with_index do |v,i|
      values["c#{i}"]=v
      if i >= @tv.tableColumns.size
        @tv.tableColumns << column(:id=>"c#{i}",
          :title=>"Word #{i+1}")
      end
    end
    @tv.dataSource.data << values
    @tv.reloadData
  end
end
Application.new.start
#thanks again to everburning.com

require 'hotcocoa'
include HotCocoa
require "lib/bezel.rb";
framework 'ScriptingBridge'

class Application
  def start
    application :name =&gt; "Ask Google" do |app|
      app.delegate = self
      @main_window = bezel_window(
        :frame =&gt; [450,300,128,128],
        :buttons =&gt; [
          ["Google it",lambda { |s| doit }],
          ["Quit",lambda { |s| exit }]])
    end
  end
  def open_url(url)
    @safari.documents.first.URL=url
    sleep(1) #wait for safari to load url
    @safari.windows.first.currentTab
  end
  def fill_form(tab,form,values={})
    values.each_pair do |n,v|
      safari_do tab,"document.#{form}.#{n}.value='#{v}'"
    end
    safari_do tab,"document.#{form}.submit()"
  end
  def safari_do(tab,cmd)
    @safari.doJavaScript(cmd, :'in'=&gt;tab)
  end
  def doit
    @safari = SBApplication.
      applicationWithBundleIdentifier('com.apple.Safari')
    @safari.activate #bring to front
    tab=open_url('http://www.google.com/')
    fill_form tab,:f, :q=&gt;"macruby"
  end
end
Application.new.start

thanks python people and @lrz

require 'hotcocoa'
include HotCocoa
require "lib/bezel.rb";
framework 'ScriptingBridge'

class Application
  def start
    application :name => "Ask Google" do |app|
      app.delegate = self
      @main_window = bezel_window(
        :frame => [450,300,128,128],
        :buttons => [
          ["Google it",lambda { |s| doit }],
          ["Quit",lambda { |s| exit }]])
    end
  end
  def open_url(url)
    @safari.documents.first.URL=url
    sleep(1) #wait for safari to load url
    @safari.windows.first.currentTab
  end
  def fill_form(tab,form,values={})
    values.each_pair do |n,v|
      safari_do tab,"document.#{form}.#{n}.value='#{v}'"
    end
    safari_do tab,"document.#{form}.submit()"
  end
  def safari_do(tab,cmd)
    @safari.doJavaScript(cmd, :'in'=>tab)
  end
  def doit
    @safari = SBApplication.
      applicationWithBundleIdentifier('com.apple.Safari')
    @safari.activate #bring to front
    tab=open_url('http://www.google.com/')
    fill_form tab,:f, :q=>"macruby"
  end
end
Application.new.start
thanks python people and @lrz

require 'hotcocoa'
class Application
  include HotCocoa
  FULL={:expand =&gt; [:width,:height]}
  SHOW=[0,0,0,100]
  def start
    application :name =&gt; "MyTableView" do |app|
      app.delegate = self
      window(:title =&gt; "MyTableView",
        :frame =&gt; [10, 620, 330, 230]) do |win|
        win &lt;&lt; split_view(:horizontal =&gt; true,
          :layout =&gt; FULL) do |sp|
          sp &lt;&lt; scroll_view(:frame =&gt; SHOW) do |sv|
            sv &lt;&lt; @table=table_view(
              :data =&gt; [], :columns =&gt; [
                column(:id =&gt; :c1, :title =&gt; "Word 1"),
                column(:id =&gt; :c2, :title =&gt; "Word 2"),
                column(:id =&gt; :c3, :title =&gt; "...")])
          end #sv
          sp &lt;&lt; @prompt = text_field(:text =&gt; 'type here',
            :font =&gt; font(:name=&gt;'Monaco', :size =&gt; 16),
            :on_action =&gt; Proc.new {|t| type(t)})
        end #sp
        win.contentView.margin = 5
        win.makeFirstResponder @prompt
        win.will_close { exit }
      end #window (win)
    end #application
  end
  def type(t)
    c1,c2,*c3=t.to_s.split ; c3=c3.join ' '
    @table.dataSource.data &lt;&lt; {:c1=&gt;c1,:c2=&gt;c2,:c3=&gt;c3}
    @table.reloadData
  end
end
a=Application.new.start
thanks everburning

require 'hotcocoa'
class Application
  include HotCocoa
  FULL={:expand => [:width,:height]}
  SHOW=[0,0,0,100]
  def start
    application :name => "MyTableView" do |app|
      app.delegate = self
      window(:title => "MyTableView",
        :frame => [10, 620, 330, 230]) do |win|
        win << split_view(:horizontal => true,
          :layout => FULL) do |sp|
          sp << scroll_view(:frame => SHOW) do |sv|
            sv << @table=table_view(
              :data => [], :columns => [
                column(:id => :c1, :title => "Word 1"),
                column(:id => :c2, :title => "Word 2"),
                column(:id => :c3, :title => "...")])
          end #sv
          sp << @prompt = text_field(:text => 'type here',
            :font => font(:name=>'Monaco', :size => 16),
            :on_action => Proc.new {|t| type(t)})
        end #sp
        win.contentView.margin = 5
        win.makeFirstResponder @prompt
        win.will_close { exit }
      end #window (win)
    end #application
  end
  def type(t)
    c1,c2,*c3=t.to_s.split ; c3=c3.join ' '
    @table.dataSource.data << {:c1=>c1,:c2=>c2,:c3=>c3}
    @table.reloadData
  end
end
a=Application.new.start
thanks everburning

redirect app

I currently work on port 80, but coworkers work on port 3000. So the urls they send often do not work. I created an app that bounces all local 3000 requests to port 80.

mkdir -p bounce/public bounce/tmp
cd bounce
created config.ru:
app = proc do |env|
    url="http://#{env['SERVER_NAME']}#{env['REQUEST_URI']}"
    return [302, { "Content-Type" => "text/html", "Location" => url }, "try <a href=\"#{url}\">#{url}</a>" ]
end
run app
enabled port 3000 in /private/etc/apache2/httpd.conf:
Listen 3000
added entry to passenger pref pane. But it didn’t create the proper vhosts entry. I changed port 80 to 3000
<VirtualHost *:3000>
  ServerName site1.local:3000
  ServerAlias test.local:3000
  DocumentRoot "/Users/kbrock/projects/bounce/public"
  RackEnv development
  <directory "/Users/kbrock/projects/bounce/public">
    Order allow,deny
    Allow from all
  </directory>
</VirtualHost>
All is working.