Roger's woze

April 25, 2007

perl cygwin

Filed under: Uncategorized — rogerdpack @ 4:11 am

To install cygwin perl you need to first install make, then cpan will work. You may need to also install gcc. I don’t know why these are not installed.  Anyway if you get the message after Make ” — NOT OK” that means that something is not installed.

how to recreate a DB in postgres

Filed under: Uncategorized — rogerdpack @ 4:10 am
how to re-create a DB from an sql of itself (a different version of itself) or what not.
<code>
dropdb logs_state_tracker
createdb -T template0 logs_state_tracker
psql logs_state_tracker < /tmp/logs_state_tracker_latest.sql
</code>

how to create a text box in html

Filed under: Uncategorized — rogerdpack @ 3:17 am

<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.

April 24, 2007

vi for replacing one word and a space on a line with nothing:

Filed under: Uncategorized — rogerdpack @ 12:13 am

:%/^\S+ \n::

April 17, 2007

SSH tunnelling

Filed under: Uncategorized — rogerdpack @ 11:56 pm

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

Filed under: Uncategorized — rogerdpack @ 11:38 pm

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

Filed under: Uncategorized — rogerdpack @ 11:36 pm

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

random ruby generate commands

Filed under: Uncategorized — rogerdpack @ 11:34 pm

generate scaffold dbTableNameWith (actually model name) appearanceNameIThink (notice — no ss’s)

If you just want to generate a new controller

generate controller_name

and then create “view” pages for it in app\views\controller_name (like index.rhtml)

How to serve a file in RoR

Filed under: Uncategorized — rogerdpack @ 11:31 pm

# 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

Filed under: Uncategorized — rogerdpack @ 2:14 am

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.

Older Posts »

Powered by WordPress