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)
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...
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)
m
# [,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
mcstd
# [,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
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:
plot(x,y)
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
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) diagram
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
1: a diagrammatic presentation; broadly: a structured framework or plan : outline
figure
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
illustration
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
cartoon
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 ;
Thesaurus.com
diagram
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
illustration
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
cartoon
Part of Speech: noun
Definition: funny drawing, often with dialogue or caption
Synonyms: animation, caricature, comic strip, drawing, lampoon, parody, representation, satire, sketch, takeoff
www.wordassociation.org
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
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!
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.
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)
This should work in many different distros and versions with only minor modification.
sudo aptitude install openssh-server
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.
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 192.168.1.1).
Forward port 22 traffic to your statically assigned PC (see image below for router specs).
Use a service like dyndns.com to associate a static IP address with your dynamically assigned address.
Run ddclient to update dyndns.com.
sudo aptitude install ddclient
Here is a configuration file (/etc/ddclient.conf) that works for me:
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.
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 http://ppa.launchpad.net/matt-price/mattprice/ubuntu lucid main deb-src http://ppa.launchpad.net/matt-price/mattprice/ubuntu lucid main
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 -L22000:internalserver.super.duper.com:22 gateway.super.duper.com # 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.