Friday, December 17, 2010

Shell escaped file names in ruby

When files have crazy characters in their filename (like ' or ""), it can make creating a robust script challenging. After all, if you write the script with either a single quotation mark or a double quotation mark, the other one will trip you up:

file1 = "my'crazy'file.txt"
file2 = 'my"crazy"file.txt'
system "mv \"#{file2}\" bettername.txt"  # fails on file2
system "mv '#{file2}' bettername.txt"    # fails on file1

The answer is to use the multiple arguments invocation, which will properly escape your filename to be fully shell compatible:

system "mv", file1, "bettername.txt"  # works on file1 or file2

Thursday, December 9, 2010

Playing with (compiling) the redesigned NArray

Masahiro Tanaka has been redesigning NArray. Word is that it may be pulled into mainline ruby.

So, what is it like? Amazing from what I can tell. How do you play with it? At least on Ubuntu 10.10, this is what I did (there may be other dependencies I've neglected here):

sudo apt-get install libatlas-dev libatlas-base-dev
# modify extconf.rb:
have_header("atlas/cblas.h")   ===>   have_header("cblas.h")
# modify linalg.c
#include <atlas/cblas.h>   ===>   #include <cblas.h>
# for ruby 1.9, you also need to change a few normal array things:

diff -r ../narray-new-1.8/narray.c ./narray.c
<     n = RARRAY(idxargs)->len;
<     ptr = RARRAY(idxargs)->ptr;
>     n = RARRAY_LEN(idxargs);
>     ptr = RARRAY_PTR(idxargs);
< const static size_t zero=0;
> //const static size_t zero=0;
> static const size_t zero=0;
<      ndim = RARRAY(v)->len;
>      ndim = RARRAY_LEN(v);
>     VALUE *ptr;
<  RARRAY(v)->ptr[i] = SIZE2NUM(na->shape[c]);
<  RARRAY(v)->len++;
>  RARRAY_PTR(v)[i] = SIZE2NUM(na->shape[c]);
>  ptr = RARRAY_LEN(v);
>     ptr++;
diff -r ../narray-new-1.8/nstruct.c ./nstruct.c
<      ndim = RARRAY(argv[i])->len;
>      ndim = RARRAY_LEN(argv[i]);

now, you should be able to "ruby extconf.rb", "make", and then require 'narray' or require './'

Tuesday, September 28, 2010

Compile ruby 1.9.2 on Ubuntu

assumes you have build-essential package installed
tar -xjvf ruby-1.9.2-p0.tar.bz2
cd ruby-1.9.2-p0
./configure --enable-shared --program-suffix=1.9.2
make check # optional
sudo checkinstall make install
# [follow the defaults until here:
# NOTE that you want the extra files inside your directory.
# those extra files contain things like the openssl libraries!!

    Some of the files created by the installation are inside the build
    directory: /home/jtprince/src/ruby-1.9.2-p0

    You probably don't want them to be included in the package,
    especially if they are inside your home directory.
    Do you want me to list them?  [n]: n
    Should I exclude them from the package? (Saying yes is a good idea)  [y]: n

# At this point, you can install the package on machines of the same
# architecture with "sudo dpkg -i ruby-1.9.2_p0-1_amd64.deb" [depending on your arch]

sudo rm /usr/bin/ruby
sudo ln -s /usr/local/bin/ruby1.9.2 /usr/bin/ruby

Okay, now you need to get rubygems working properly. Remember, rubygems comes with ruby 1.9.X, so you don't need to download it separately.

At this point, we have to ensure our soft links point where we want and to tell gems to point to ruby 1.9.2

sudo cp /usr/bin/gem1.9.{1,2}
# then edit /usr/bin/gem1.9.2
# change #!/usr/bin/ruby1.9.1 ==> #!/usr/local/bin/ruby1.9.2

# now set up the soft link so that "gem" calls our gem1.9.2
sudo rm /etc/alternatives/gem
sudo ln -s /usr/bin/gem1.9.2 /etc/alternatives/gem

Maybe it is unnecessary, but I moved my local gem folder so that all my gems are compiled from scratch again to ensure they have been built against 1.9.2. how to set up a local gem environment

mv ~/.gem/ruby/{,not_using_}1.9.1
mkdir ~/.gem/ruby/1.9.2

Tuesday, September 21, 2010

Installing graphviz on Ubuntu Lucid Lynx 10.04

If you want sfdp (a great layout for large graphs), then you need the .debs from the graphviz site (not through the ubuntu repos).

Download the develpment snapshots here
note, if you don't use the language specific bindings listed, you don't need to download those.

sudo aptitude install libdevil1c2 libgtkglext1
sudo dpkg -i graphviz_*.deb graphviz-dev*_all.deb 
graphviz-doc*_all.deb libgraphviz4_*.deb libgraphviz-dev_*.deb libgv-ruby_*.deb

Now, you can run sfdp!

Sunday, September 5, 2010

for anything complicated, ruby eats bash for breakfast shows a bash solution to the issue debated here. Regardless of how good a bash script is, it inevitably is not very DRY, I think because it is hard to be DRY in bash scripting.

Here is a ruby solution. Of course, all I did was factor, which is easy in ruby:

#!/usr/bin/env ruby

lame_opts = "--preset standard -q0"

if ARGV.size == 0
  puts "usage: #{File.basename(__FILE__)} .flac ..."
  puts "output: .mp3"
  puts ""
  puts "uses lame opts: #{lame_opts}"
  puts "retains tag info"

tag_convert = {
  :tt => "TITLE",
  :tl => "ALBUM",
  :ta => "ARTIST",
  :tn => "TRACKNUMBER",
  :tg => "GENRE",
  :ty => "DATE",

ARGV.each do |file|
  tag_opts = do |key,val|
    # comes out as TITLE=
    data = `metaflac --show-tag=#{val} #{file}`.split("=",2).last
    "--#{key} #{data}"
  mp3name = file.chomp(File.extname(file)) + ".mp3"
  `flac -dc #{file} | lame #{lame_opts} #{tag_opts.join(" ")} --add-id3v2 - #{mp3name}`
Fairly easy to follow, especially since we don't repeat ourselves. Most of the code is in creating a useful help message.

For Perl hackers, here is the entire script on a few lines of less than 105 chars per line:

tag_convert = {:tt=>"TITLE",:tl=>"ALBUM",:ta=>"ARTIST",:tn=>"TRACKNUMBER",:tg=>"GENRE",:ty=>"DATE"}
ARGV.each do |f| 
  tgs = {|k,v| "--#{k} "+`metaflac --show-tag=#{v} #{f}`.split("=",2).last}.join(" ")
  `flac -dc #{f} | lame --preset standard -q0 #{tgs} --add-id3v2 - #{f.sub(/.flac$/i,".mp3")}`
There are still ways to compress this further, but it is very concise and surprisingly easy to follow (if you know ruby).

Wednesday, September 1, 2010

For sets of integers, lookup speed goes: Array > Hash > Set

You have some set of integers and you need to query it repeatedly to determine if a member is in it or not.

require 'benchmark'
require 'set'

ar = (0...1000).to_a

ar_index = []
hash_index = {}
ar.each do |v|
  ar_index[v] = true
  hash_index[v] = true

set_index =
access = (0...1000).to_a

TIMES = 10000

Benchmark.bmbm do |r|"array index") { TIMES.times { access.each {|v| ar_index[v] } } }"hash index") { TIMES.times { access.each {|v| hash_index[v] } } }"hash include") { TIMES.times { access.each {|v| hash_index.include?(v) } } }"set include") { TIMES.times { access.each {|v| set_index.include?(v) } } }
The output (ruby 1.9.1p378 (2010-01-10 revision 26273) [x86_64-linux]):

                   user     system      total        real
array index    0.730000   0.000000   0.730000 (  0.745341)
hash index     0.990000   0.000000   0.990000 (  1.003517)
hash include   1.310000   0.000000   1.310000 (  1.332846)
set include    1.970000   0.000000   1.970000 (  2.024808)

It's faster to numerically round than to sprintf in ruby

require 'benchmark'

class Float
  def round_to(x)
    (self * 10**x).round.to_f / 10**x

  def ceil_to(x)
    (self * 10**x).ceil.to_f / 10**x

  def floor_to(x)
    (self * 10**x).floor.to_f / 10**x

  def round_to_sprintf_f(x)
    ("%.#{x}f" % x).to_f

  def round_to_sprintf_sprintf(x)
    sprintf("%.#{x}f", x)

  def round_to_sprintf_modulus(x)
    "%.#{x}f" % x


num = 34.2342134
place = 3

TIMES = 1000000
Benchmark.bmbm do |r|"numeric round_to (float)") { TIMES.times { num.round_to(place) } }"numeric round_to (to string)") { TIMES.times { num.round_to(place).to_s } }"sprintf (float)") { TIMES.times { num.round_to_sprintf_f(place) } }"sprintf (string)") { TIMES.times { num.round_to_sprintf_sprintf(place) } }"sprintf modulus (string)") { TIMES.times { num.round_to_sprintf_modulus(place) } }
The output:

% ruby -v
ruby 1.9.1p378 (2010-01-10 revision 26273) [x86_64-linux]
                                   user     system      total        real
numeric round_to (float)       0.820000   0.000000   0.820000 (  0.819920)
numeric round_to (to string)   1.990000   0.000000   1.990000 (  1.989912)
sprintf (float)                3.620000   0.000000   3.620000 (  3.614758)
sprintf (string)               2.650000   0.000000   2.650000 (  2.654812)
sprintf modulus (string)       3.190000   0.000000   3.190000 (  3.191807)

The conclusion: Regardless of whether you are going to a string or numeric after rounding, it is faster to round numerically than with sprintf. Also, using the sprintf function is faster than '%'. Usually speed doesn't matter, but when it does...

Thursday, August 19, 2010

apply & sweep : Column-wise & Row-wise operations in R

How do you do operations on rows and columns in R? apply and sweep are the main tools. Here is an example of "autoscaling" (mean center and divide by standard deviation) on each column:

[I verified that this is correct on oocalc]

# 1 -> across the rows
# 2 -> across the columns 
m <- matrix(data=c(1,2,3,4,4.5,6,7,8,9,10,11,13), nrow=4, ncol=3)
#      [,1] [,2] [,3]
# [1,]    1  4.5    9
# [2,]    2  6.0   10
# [3,]    3  7.0   11
# [4,]    4  8.0   13

colmeans <- apply(mymatrix, 2, mean)  # the column-wise means
# mc = the column-wise mean centered data
mc <- sweep(m, 2, colmeans, "-")   # subtract is the default

col_stdev <- apply(m, 2, sd)  # column-wise standard deviations

mcstd <- sweep(mc, 2, col_stdev, "/")  # divide by standard deviations

#            [,1]       [,2]      [,3]
# [1,] -1.1618950 -1.2558275 -1.024695
# [2,] -0.3872983 -0.2511655 -0.439155
# [3,]  0.3872983  0.4186092  0.146385
# [4,]  1.1618950  1.0883839  1.317465

Thursday, August 5, 2010

Regression line, R^2 (Pearson's correlation coefficient), slope, and y intercept in R

A basic feature in Excel and OpenOffice Calc is to find and plot the regression line. Here is an example of doing this in R. This is more work in R, but you are sacrificing for more power.

Here is how we get the data out:

x = c(1,2,3,4,5)
y = c(3,4,5,5.1,6.2)
pearsons_r = cor(x,y)
r_squared = pearsons_r^2
fit = lm(y~x) # notice the order of variables
y_intercept = as.numeric(fit$coeff[1])
slope = as.numeric(fit$coeff[2])

Here is how we plot it:

abline(lm(y~x)) # again, notice the order
function_string = paste("f(x) = ", slope, "x + ", y_intercept,  sep="")
r_sq_string = paste("R^2 =", r_squared)
display_string = paste(function_string, r_sq_string, sep="\n")
mtext(display_string, side=3, adj=1)  # top right outside of the margin

Thursday, June 17, 2010

clone a VDI Virtual Box image for using elsewhere

How robust is this procedure (found here)?
  1. Shut down the virtual machine you would like to copy
  2. In File > Virtualdiskmanager, select the virtual machine disk image you would like to copy, and press the Release button
  3. In a terminal window, issue following command (see virtualbox user manual):
    vboxmanage clonevdi /directory/image1.vdi /directory/image2.vdi
  4. In File > Virtualdiskmanager, add the new disk image you've created in step 3
  5. In the main virtualbox window, press the New button to create a new virtual machine, and link it to the new disk image you've created.

Wednesday, June 9, 2010

Cartoons in biology?? How about: diagram, figure, illustration or schematic

Molecular biologists often refer to depictions of cellular processes or structure as cartoons.  (here is an example).  I think it is a poor word choice.  Cartoon is generally used to indicate a humorous depiction or an unfinished product (i.e., a sketch on a carton), so it is somewhat insulting to the creator of the illustration (unless it is, in fact, unfinished or humorous).  What I think they are trying to say by calling their diagram a cartoon is something like: "do not forget that this diagram is a vast oversimplification of reality!  Proteins are not really boxes and lines are really not protein associations!  Proteins aren't made of ribbons!"  At times, one also gets the feeling they are trying to convey something more, "Our field is so complex, our diagrams are ludicrously simple compared to reality!" or even, "Aren't I cute for calling this a cartoon even though this is a science talk!"

Fortunately, there are several other words suggesting that a depiction is not a precise representation of reality but rather a simplification that serves to emphasize certain facts or relationships, and they don't carry any of cartoon's demeaning connotations: diagram, figure, illustration, schematic.  IMHO, these are vastly preferable for referring to depictions of biological phenomenon.  This seems to be well supported by definitions, synonyms, and word associations:

Merriam-Webster (online)

Etymology: Greek diagramma, from diagraphein to mark out by lines, from dia- + graphein to write — more at carve
Date: 1619
1 : a graphic design that explains rather than represents; especially : a drawing that shows arrangement and relations (as of parts)
2 : a line drawing made for mathematical or scientific purposes

Inflected Form(s): plural sche·ma·ta \-mə-tə\ also schemas
Etymology: Greek schēmat-, schēma
Date: circa 1890
1 : a diagrammatic presentation; broadly : a structured framework or plan : outline
Etymology: Middle English, from Anglo-French, from Latin figura, from fingere
Date: 13th century
2 a : a geometric form (as a line, triangle, or sphere) especially when considered as a set of geometric elements (as points) in space of a given number of dimensions b : bodily shape or form especially of a person c : an object noticeable only as a shape or form
s moving in the dusk>

3 a : the graphic representation of a form especially of a person or geometric entity b : a diagram or pictorial illustration of textual matter


Date: 14th century
2 : something that serves to illustrate: as a : an example or instance that helps make something clear b : a picture or diagram that helps make something clear or attractive

Etymology: Italian cartone pasteboard, cartoon, augmentative of carta leaf of paper — more at card
Date: 1671
1 : a preparatory design, drawing, or painting (as for a fresco)
2 a : a drawing intended as satire, caricature, or humor b : comic strip
3 : animated cartoon
4 : a ludicrously simplistic, unrealistic, or one-dimensional portrayal or version ;


Part  of  Speech:      noun
Definition:     drawing, sketch of form or plan
Synonyms:     big picture, blueprint, chart, description, design, draft, figure, floor plan, game, game plan, ground plan, layout, outline, perspective, representation, rough draft

Part  of  Speech:      noun
Definition:     design
Synonyms:     architecture, arrangement, blueprint, chart, comp, composition, conception, constitution, construction, delineation, depiction, diagram, doodle, drawing, dummy, form, formation, game plan, idea, layout, makeup, map, method, model, outline, paste-up, pattern, perspective, picture, plan, project, scheme, strategy, study, tracery, tracing, treatment

Part  of  Speech:      noun
Definition:     object with design; depiction
Synonyms:     cast, composition, decoration, device, diagram, drawing, effigy, embellishment, emblem, illustration, image, model, mold, motif, motive, ornamentation, pattern, piece, portrait, representation, sketch, statue

Part  of  Speech:      noun
Definition:     drawing, artwork that assists explanation
Synonyms:     adornment, cartoon, decoration, depiction, design, engraving, etching, figure, frontispiece, halftone, image, line drawing, painting, photo, photograph, picture, plate, sketch, snapshot, tailpiece, vignette

Part  of  Speech:      noun
Definition:     funny drawing, often with dialogue or caption
Synonyms:     animation, caricature, comic strip, drawing, lampoon, parody, representation, satire, sketch, takeoff

associated to diagram
1.    chart    weak
2.    graph    weak
3.    draw    v. weak
4.    plan    v. weak
5.    block    v. weak
associated from diagram
1.    chart    medium
2.    picture    medium
3.    diaphragm    weak
4.    drawing    v. weak
5.    graph    v. weak

associated to schema
1.    scheme    strong
2.    axiom    weak
3.    concept    weak
4.    fema    weak
5.    pooh    weak
associated from schema
1.    scheme    strong
2.    database    weak
3.    diagram    weak
4.    paradigm    weak
5.    seem    weak

associated to figure
1.    stick    medium
2.    action    weak
3.    father    weak
4.    shape    weak
5.    authority    v. weak
associated from figure
1.    shape    medium
2.    eight    medium
3.    skate    weak
4.    skating    v. weak
5.    out    v. weak

associated to schematic
1.    plan    strong
2.    scheme    medium
3.    architecture    weak
4.    blueprint    weak
5.    diagram    weak
associated from schematic
1.    blueprint    strong
2.    system    strong
3.    design    medium
4.    drawing    medium
5.    love    medium

associated to illustration
1.    example    medium
2.    drawing    medium
3.    graphic    weak
4.    book    v. weak
5.    capella    v. weak
associated from illustration
1.    picture    strong
2.    drawing    medium
3.    book    weak
4.    cartoon    weak
5.    draw    weak

associated to cartoon
1.    animation    v. weak
2.    simpsons    v. weak
3.    anime    v. weak
4.    disney    v. weak
5.    character    v. weak
associated from cartoon
1.    character    medium
2.    network    weak
3.    animation    weak
4.    comic    v. weak
5.    tv    v. weak

Wednesday, May 26, 2010

Download all the mp3 links in a page given the url with ruby and nokogiri

You'll need ruby and the gem nokogiri installed. Then run this

#!/usr/bin/env ruby

require 'nokogiri'
require 'open-uri'

if ARGV.size == 0
  puts "usage: #{File.basename(__FILE__)} 'url' ..."

ARGV.each do |url|
  doc = open(url) {|io| Nokogiri.HTML( }

  mp3_links = doc.xpath("//a").select {|link| link['href'] =~ /\.mp3$/ }
  mp3_links.each do |link|
    href = link['href']
    outname = File.basename(href)
    puts "Downloading: #{outname}"
    open(href) do |io|,'w') {|out| out.print( }

Wednesday, May 12, 2010

A debian/ubuntu gem environment of your very own

There are some differences with the way apt-get rubygems and downloaded and 'sudo ruby setup.rb' gems behave. Here is how to bring the directory structure in conformity with the apt-get version and have your gem's bin folder in your path. This is for using gems on a per-user basis.

Add these two lines to your ~/.bashrc file:
# this will export the path to whatever version of ruby you are using:
export GEM_HOME="$HOME/.gem/ruby/`ruby -e 'x=RUBY_VERSION;print(x=~/^1.8/ ? "1.8" : x)'`"
export PATH="$PATH:$GEM_HOME/bin"

Then 'source ~/.bashrc' if needed and you can use either version of rubygems indistinguishably.

Now, you can install gems with either rubygems, you don't need sudo privileges, and your gem executables will be active. Wallah!

gem install rake

Friday, May 7, 2010

Yet another reason to love Ubuntu, multiple folder extraction

Today I needed to extract 20+ folders and I thought, I don't want to right-click over 20 times, wouldn't it be cool if I could just select all the folders, right-click and extract? Well, it worked like a charm and made my day. Now if only Ubuntu could solve the problem of all of my folders being over 2.5 Gb and taking forever to extract.

Tuesday, May 4, 2010

Your own legal ssh personal server on comcast with Ubuntu 10.04

Legal Matters

It appears to me that a personal ssh server is legal and acceptable to use [at least if you are with Comcast].
The Comcast Terms of Service:

The relevant bullets under Technical restrictions are:
* use or run dedicated, stand-alone equipment or servers from the Premises that provide network content or any other services to anyone outside of your Premises local area network (“Premises LAN”), also commonly referred to as public services or servers. Examples of prohibited equipment and servers include, but are not limited to, e-mail, Web hosting, file sharing, and proxy services and servers;
* use or run programs from the Premises that provide network content or any other services to anyone outside of your Premises LAN, except for personal and non-commercial residential use;  (my emphasis)
Also, note that the ssh port (22) is not blocked by comcast.

How to setup a personal ssh server

This should work in many different distros and versions with only minor modification.

  1. sudo aptitude install openssh-server
  2. Since I have kids with weak passwords using my computer, I only want a couple accounts to be accessible. Edit /etc/ssh/sshd_config and add something like this:
    AllowUsers user1 user2 user3
    This will prevent other user accounts from being accessible.
  3. It is generally a good idea to use a static IP address so your router knows where to send the ssh traffic.  Right click your wireless icon on the panel and edit your connection.  Shown to the right is a setup that is compatible with a linksys router (i.e., the router IP address is
  4. Forward port 22 traffic to your statically assigned PC (see image below for router specs).
  5. Use a service like to associate a static IP address with your dynamically assigned address.
  6. Run ddclient to update
    sudo aptitude install ddclient
    Here is a configuration file (/etc/ddclient.conf) that works for me:
    use=web,, web-skip='IP Address'

Now, you should be able to ssh into your home computer from anywhere in the world. Also, please note that you can do just about anything with ssh access.

Friday, April 30, 2010

Asus Eee PC 1201N Wireless WPA2 Ubuntu Lucid Lynx 10.04 Fix

I was able to use wireless on 9.10 by compiling the one talked about on newegg and elsewhere. However, I couldn't connect to the school's network. On 10.04, it appears that they are using the same driver and it has the same problems (appears to work but won't connect to my school's WPA2 network). I used Matt Price's package and it works now!

Here are the steps:
sudo add-apt-repository ppa:matt-price/mattprice

Then add these lines to /etc/apt/sources.list:
deb lucid main
deb-src lucid main

Saturday, March 6, 2010

ssh tunneling (port forwarding)

The past two places I've worked at have had a single computer that would accept outside ssh communication. However, other computers in the network also had useful things on them but could only be reached from inside the network. How to connect to these other computers directly?

ssh port forwarding allows you to open up an ssh session between you and your gateway computer. Then, you can use that port to interact with the other computers in the network. Here is an example of how to do this:

Open a terminal and type in something like this:
ssh -L<unused_port#>:<final_destination>:22 <gateway_computer>
ssh # e.g.
# you might want to add the -N and -C flags:
ssh -N -C ...
# -N Do not execute a remote command (useful for forwarding ports)
# -C compress (for slow network connections only)

Then, open another terminal and you can interact with the internal server as you normally would, just by interacting with your localhost through the specified port:
# log in to the internal server
ssh -p 22000 localhost
# scp stuff from the internal server
scp -P 22000 localhost:~/somefile.txt ./ # copy files from the internal server to local
# mount a folder from the internal server locally using sshfs
sshfs -p 22000 localhost:/home/<user>/<internal_dir> /home/<user>/mnt -o follow_symlinks

Yes that is localhost. You are connecting to port 22000 on the localhost and that is being tunneled via the gateway computer to the internal server!

This works but isn't the absolute slickest setup. Anyone know the equivalent commands for .ssh/config files?

This site has some alternative methods for mounting across ssh.

Thursday, March 4, 2010

Fonts in rumai (wmii)

How do you know what fonts you can use in rumai or wmii?
xlsfonts will list all the fonts in the format that wmii expects:

xlsfonts > available_fonts.txt

You can use the '*' symbol to generalize. Here are some that work ok. Some are quite ugly, others OK:

-*-dejavu sans mono-medium-r-*-*-14
-*-dejavu sans mono-medium-r-*-*-14

Tuesday, March 2, 2010

wmii (rumai) with gnome in Ubuntu 9.10 & 10.04

NOTE: modified from here

This is a step by step to install rumai as the windows manager in gnome.

  1. install necessary packages
    sudo apt-get install dwm-tools # for menus
    sudo apt-get install libixp libx11-dev  # for the install itself (necessary??)
    On Lucid Lynx I needed to install these two packages also:
    sudo apt-get install 9base libxft2-dev   # plan 9 file system (need on 10.04)
  3. Install a good build
  4. The Ubuntu wmii packages (karmic? and jaunty?) and even the current repo can be buggy. Download a solid build (hg2474) here or here. Unpack it, go into the src directory and sudo make install.
  5. modify some gnome settings
    gconftool-2 -s /apps/nautilus/preferences/show_desktop --type bool false
    gconftool-2 -s /desktop/gnome/background/draw_background --type bool false
    ## Tell gnome to use wmii as the window manager
    gconftool-2 -s /desktop/gnome/session/required_components/windowmanager wmii --type string
  7. have wmii fire up at login
  8. System -> Preferences -> Startup Applications Add an entry for /usr/bin/wmii
  9. get rumai
  10. make sure you have ruby and rubygems. Works great with ruby 1.9. (I'm using 1.9.1)
    gem install rumai
    Also make sure your rubygems are executable by adding something like this to your .bashrc:
    export PATH="$PATH:$HOME/.gem/ruby/`ruby -e 'print RUBY_VERSION'`/bin"
  11. grab a rumai config wmiirc
  12. To make it easy for beginners, my master branch work's out of the box:
    git clone git:// ~/.wmii
    For more advanced possibilities, you'll want to start with sunaku's and then branch, etc.:
    git clone git:// ~/.wmii
    Now make a soft link to the file this wmii will be looking in:
    ln -s ~/.wmii ~/.wmii-hg
    Now logout and back in and it should work. This is pretty stable and works pretty well. If wmii crashes, restart in a terminal or from the panel (add a "run application") with the command "wmii" or "killall wmii && wmii".

Friday, January 8, 2010

multifactorial plotting in R: lattice

I've mentioned before in personal communications that if you have lots of factors in a data set you can just flatten out the data set and then use openoffice data pilot to pivot around different factors (also can be done in ruby with Ruport and 'pivot'). This is a good method.

There is a much better method I recently came across: "trellis plots". The package in R is called lattice.

This is clearly the way to quickly and neatly plot multifactorial data in lots of meaningful ways.

Some resources:
In R (as sudo if you want system wide installation):
install.packages("lattice", dependencies=TRUE)  # I don't think there are any dependencies

Monday, January 4, 2010

pymix compilation errors on Ubuntu

pymix was a little tricky to compile. Here's what I did to get it working.

I downloaded and installed numpy [but that is probably not necessary].

Then I finally had to go into pymix's and change the location for where it was looking for arrayobject.h:
numpypath = prefix + '/lib/python' +pyvs + '/site-packages/numpy/core/include/numpy' # path to arrayobject.h
numpypath = '/usr/share/pyshared/numpy/core/include/numpy' # path to arrayobject.h

At this point, 'python build' worked, but the install failed with this error:

byte-compiling /usr/local/lib/python2.6/dist-packages/ to AminoAcidPropertyPrior.pyc
SyntaxError: ('invalid syntax', ('/usr/local/lib/python2.6/dist-packages/', 170, 14, ' as = alpha.pop(0)\n'))

turns out that 'as' is a reserved keyword in python 2.6, so you need to go in to that file and change it to something else, like: nada = alpha.pop(0)