how to create a text box in html

<code>

<SELECT NAME=”Morefruit” SIZE=”4″ MULTIPLE >
<OPTION SELECTED> Apples
<OPTION> Bananas
<OPTION> Oranges
<OPTION> Watermelon
<OPTION> Kiwi
<OPTION> Cantaloupe
<OPTION> Strawberries

<default select name=”Fruit”>
</SELECT>
</code>

Notice the “size =” meaning how much of a drop down you’ll have.

SSH tunnelling

ssh -L means “connections I make ‘into’ this port on my machine, will make their way through this tunnel and into the foreign port on the foreign machine (some other prog running there that [not ssh]).

Creating fixtures that link amongst themselves

Note well that when creating fixtures for RoR testing you CANNOT really link to straight names, within other files, like

(one entry)
CoolCast:
id: 3

and another

HasBoth:
id: 5
single_internet_file_id: FavoriteMP3Url # uh...this doesn't seem to work
user_blended_cast_id: CoolCast
file_location_and_name: "yoyo.mp3"

where those are names–the names don’t work (just become zeroes, somehow), so…just use (hard coded) numbers.

nil in fixtures

a note:
in test/fixtures, when you write

name:
id: 34
name: "Roger"
number: nil

this actually assigns number as 0! This means that if you test in your model code for “number.blank?” this will now return true, since it is actually zero. The use of nil is truly misleading here, and should be done away with, in my opinion. So you can instead just call
...
if !user and !filename
...
do whatever in your model “verify” methods, and nil will work. Don’t use blank, basically.

end
instead of
if user.blank? and filename.blank?
do whatever
end

How to serve a file in RoR

# this is how to send it out–through Ruby. Unfortunately it appears that webrick buffers all output, so…with a 1 gig file…that is not good–it runs out of memory.
# send_file(realFileCompleteName,
# :filename => @user_blended_cast.name,
# :type => ‘image/gif’,
# :disposition => ‘attachment’,
# :streaming => ‘false’ # If false, the entire file is read into server memory and sent to the client. Otherwise, the file is read and written to the client in :buffer_size chunks. [from Agile Web Development p. 431]

# :buffer_size => ‘4096’
# }

Ruby starting a class as a thread

Here’s a function to start a class as if it were a thread (a la python)

def startGoFunctionAsThread()
return Thread.new() { ||
go() # this is defined somewhere else in the class
}

end
Remember if you run this as

a = objectName. startGoFunctionAsThread

to run a.join to wait for it to complete.

Ruby exception handling

how to do ruby try/catches

begin
file = open(“/tmp/some_file”, “w”)
# … write to the file …
rescue

# ex: rescue Timeout::Error, Errno::ECONNREFUSED

# or  rescue Exception => exception
# … handle the exceptions …
ensure
file.close # … and this always happens.
end

Roger's meanderings, notes to himself, bug reports, and other things