Friday, July 17, 2009

How to version control your projects with bazaar

So you have a project named 'supercool' that happens to sit in a directory named (what else) 'supercool'. Assuming you have bazaar installed on your client computer and the server, this is how you start a project under a centralized "lock-step" model. IMHO, this model works best for solo projects if you have a server available to you:


cd supercool # make sure you are at the top level directory of your project
bzr init # starts up version control in this directory (an independent branch right now)
bzr add # will recursively add files in your project
bzr ci -m 'initial commit' # makes a commit to your branch
# the next step assumes you have already made the directory /home//bzr on your server
# this step will create a centralized repository on your remote
bzr push sftp://<user>@myserver.domain.org/home/<user>/bzr/supercool
# now, we need to 'bind' our independent branch to the remote branch
# which transforms it into "centralized mode"
bzr bind sftp://<user>@myserver.domain.org/home/<user>/bzr/supercool

# to check out a fresh copy on a different computer
bzr co sftp://<user>@myserver.domain.org/home/<user>/bzr/supercool


So, now you can work on files in your project and have them versioned. Your daily work-flow will look like this:

# assuming you are in your project directory...
bzr up # update your repo with any changes in the centralized repo
## do some work...
bzr add <file1> <file2> # add any new files, etc.
bzr ci -m 'adding new files, changed some other ones'

That's it! The bazaar documentation is great, particularly the user guide.

Friday, June 26, 2009

Adding Music to a Blogger Blog using Playlist.com

There are basically two ways you can add a playlist.com music player to your blog on blogger blogs. The first that I tried was to use one of blogger's prepared gadgets. I found that these did not look very good. Instead, there is a better way.

1) Visit playlist.com and go to "Post My Playlist." Choose "Get the code for any other social network, blog or your own personal website >>". It is currently the last choice, choice "E". Follow their directions to get the code. Select and copy it.

2) Go to your blog and sign in. Go to "Customize", "Layout", "Page Elements", "Add a Gadget", "HTML/Javascript". Paste the code into the main field and you're set.

3) Sizing the player: View the blog and see how it looks. If you don't like the dimensions, you can change the element dimensions by going back and editing the html of the element. The height and width show up in several places in the code, so you'll want to change them all. For my blog, I currently have it set to 300px wide and 208px tall. I have copied the code from my blog, removing the "<" and ">" characters so that it wouldn't actually insert the player into this post. You can see that the easiest approach is really to do a ctrl+f to find all the numbers. Just be careful that they are really dimensions and not part of another number or for something else (for an example of a number you shouldn't change, see the blue 208).

div style="text-align: left; margin-left: auto; visibility:visible; margin-right: auto; width:300px;" object width="300" height="208" param value="http://www.profileplaylist.net/mc/mp3player_new.swf" name="movie"/ param value="never" name="allowscriptaccess"/ param value="transparent" name="wmode"/ param value="config=http%3A%2F%2Fwww.indimusic.us%2Fext%2Fpc%2Fconfig_black_shuffle.xml&mywidth=290&myheight=208&playlist_url=http%3A%2F%2Fwww.indimusic.us%2Floadplaylist.php%3Fplaylist%3D42390100%26t%3D1245208454&wid=os" name="flashvars"/ embed border="0" allowscriptaccess="never" flashvars="config=http%3A%2F%2Fwww.indimusic.us%2Fext%2Fpc%2Fconfig_black_shuffle.xml&mywidth=300&myheight=208&playlist_url=http://www.indimusic.us/loadplaylist.php?playlist=42390100&t=1245208454&wid=os" type="application/x-shockwave-flash" height="208" src="http://www.profileplaylist.net/mc/mp3player_new.swf" style="width:300px; visibility:visible; height:208px;" width="300" wmode="transparent" name="mp3player"/ /embed/object br/ a /a /div

To know what will look best in your blog, you might take some time to read through the html for your blog to find your sidebar width. If it is a percentage then you may just have to guess at the width until you get it how you want it. If it is set to a number of pixels (like 250px) then you can just change the width to 250px. That should usually give a good fit. If not, try a different width.

Wednesday, June 24, 2009

Weather-util alias for linux

With administrator rights open weatherrc (should be in etc/)

The file should have a bunch of entries that look similar to this. I am showing how I created an alias for DFW.

[DFW] #Alias name
City = Dallas Ft Worth #http://tinyurl.com/28pxfg (Find your city)
ID = KDFW #ID code, see note below on how to find it
St = TX #Enter your state's abbreviation

It is easiest to find your ID code by going to http://weather.noaa.gov/ and finding your Current Weather Conditions location. When you have found it look for the four letter identification, that is your ID.

Create your own aliases by adding to the weatherrc file.

Save the file and go to the terminal and type: weather DFW
If you want more information, tell it to be verbose: weather DFW -v
If you want the forecast: weather DFW -f

Thursday, May 21, 2009

Multiple ANOVA tests in R by a grouping factor

If you have ever needed to run multiple ANOVA's according to or by a certain grouping factor here is your guide:

To do Type III sums of squares you'll need the car package. To split up your data by a grouping factor you'll need the doBy package.

install.packages("car")
install.packages("doBy")
library(car)
library(doBy)

Begin with a dataframe that has your factors, response, and grouping factor as columns (Y = response, A = factor A, B = factor B, Group = grouping factor)

If you have never read in data before into R, try something like this:

data<- read.table("/home/user/Desktop/data.txt")

I prefer to simply use text files that are delimited by space or tab.

Next name your columns:

names(data)<-c("Y","A","B","Group")

Now you need to split your data up according to your grouping factor.

data_split<-splitBy(~Group,data=data)

Lastly, run this loop:

i <-1 while(i <=length(data_split)){    
print (Anova(lm(Y~A+B+A*B, data_split[[i]]),type="III")[4,4])
i<- i +1
}

R output can be accessed in row and column fashion [r,c]. I have this particular code give me only the p-value from the interaction of factors A and B. By changing [4,4] to other numbers you can access whatever part of the ANOVA table you want. Hope this helps.

Friday, May 8, 2009

two-column default for wmii-ruby (sort of like xmonad)


How to default to 2 columns in wmii-ruby?


Add this to your wmiirc-config.rb file:

on_createclient do |cid|
tag = read("/client/#{cid}/tags")
# does the last line start with a "1", then only one column
if read("/tag/#{tag}/index").split("\n").last.match(/^1\s+/)
write("/tag/sel/ctl", "send sel right")
end
end

Basically, if you have one column of applications and you open another client, this will shove your client to the right, making a 2nd column. This should work on the wmii 3.5-3.6 series.

This (not going automatically into 2 columns) has bothered me a lot in the past and when I was trying out xmonad I found that they do this in the default layout. [It would be fun to implement the rest of the basic xmonad layouts in wmii-ruby...]

What is wmii-ruby? (in case you're asking)


I've been playing around again with wmii-ruby. wmii is a minimalist window manager for X11 (i.e., graphics on *nix-ish OS's) that is very scriptable and wmii-ruby is (you guessed it) wmii scripted in ruby. Best features:
  1. tiling window manager (use all your screen space)
  2. uses very flexible tagging system to keep things organized.
  3. very scriptable (see above example)
  4. can use a mouse but don't really need to
It really is aimed more at hacker-types than the general public, but it is quite educational figuring out how to do many of the things you take for granted with a more feature rich desktop like gnome or KDE.

Thursday, April 30, 2009

Battle for Wesnoth: Kid-Friendly

artwork from Battle for Wesnoth, modified by JTP

Introduction

Skip intro

The Battle for Wesnoth--consistently ranked at the top of open-source games--is a really extraordinary strategy game that also happens to be free. On the surface it doesn't seem that special: it doesn't feature any stunning graphics and it is turn-based, so it is much more contemplative than action-packed. Why is it so great? Well, you really need to play it a while to understand, but the main things are:
  1. Very interesting strategy component - sort of feels like playing a higher-level Risk game or a slower turn-based Rise of Nations. To win you have to deal effectively with day/night, terrain, attack/defense, recruitment, character development, health etc. There are enough components to keep things interesting but not so many to be overwhelming.
  2. Engaging storylines - compelling single (and even some multi-user) campaigns.
  3. Character development - Characters can be developed somewhat (i.e, raise levels) which provides some familiarity (and hence attachment) to them but this is limited to only a few levels which prevents this aspect from overshadowing the game's strategy component.
  4. Good AI - the computer doesn't really make dumb moves, you either have to outsmart or overpower the enemy to win.
  5. Visually beautiful - I mentioned that the graphics are 2D, but even though they are simple, they are quite engaging. Much of the artwork is really great.
  6. Good music - in a classical-esque tradition.
  7. Free.
  8. Extendable - it isn't very difficult to create your own game or campaign.

Kid-friendly graphics


I have a lot of young boys who happen to really like this game. For a game set in a fantasy world completely realized with community contributed artwork, Wesnoth is remarkably kid-friendly. While there is nothing approaching pornography in it, there are a handful of portraits and units that are not attired as modestly as could be hoped. Most of the ones I've tidied up really didn't need it much, but since I was at it...

The beauty of open-source is that the software (in this case the images) can be modified to suit one's own tastes. I took liberty to touch up a few pictures, trimmed some others and wrote a script that will replace them in one click. The replacement artwork is rough around the edges, but it gets the job done (see my conglomerate image above).

How to run wesnoth-kid-friendly


This assumes you are on Windows (instructions are included in the zip file for other OS's):
  1. Install Battle for Wesnoth - ideally in the default location so my script can find it.
  2. Install the one-click ruby installer. (go the section "Ruby on Windows" and click on the "Ruby One-Click Installer link")
  3. Download my zip file. (this contains kid-friendly up artwork and a script to copy them into place).
  4. Unzip it.
  5. Click on wesnoth-kid-friendly.rb (NOTE: this writes over the old images. Of course, you can always reinstall it if you don't like what I've done)
By default, I scan typical linux and windows directories for a Battle for Wesnoth directory. If the script isn't finding your installation, you can run the program on the commandline with the path to the Wesnoth directory given as the only argument. Or email me with the path of your directory and I'll add it to the script.

Tuesday, April 28, 2009

Keyboard Shortcuts in Gnome, KDE, wmii, or whatever

Ubuntu Jaunty Jackelope put keyboard shortcuts in their proper place (disabling those in metacity and putting them in 'Keyboard Shortcuts'). However, when opening a gnome terminal from this shortcut, you have to explicitly tell it to start in your home directory or it will start in '/'

System->Preferences->KeyboardShortcuts  then [+Add]

gnome-terminal --geometry 80x52 --working-directory $HOME

I like to set up my keyboard shortcuts with a script since I like to use them on whatever computer I'm on. I did this before with gconftool2 and that worked fine, but now a person has to set them in a different location in a different way... which got me thinking that it would be nice to set keyboard shortcuts in a cross-desktop (KDE, Gnome, wmii, whatever) kind of way.

Solution: xbindkeys

sudo apt-get install xbindkeys

Make a file called '.xbindkeysrc' in your home directory with something like this in it:

"gvim"
control+alt + g
"nautilus"
control+alt + n
"firefox -new-window http://gmail.com"
control+alt + e
"nautilus"
control+alt + h
"firefox"
control+alt + f
"gnome-terminal --geometry 80x40"
control+alt + t
"rhythmbox"
control+alt + m

now you can turn on the shortcuts with the simple command 'xbindkeys', but we'd really like for them to be turned on once when we login. Turns out cross-desktop startup is not very uniform but I think the proper way to do this (cross-desktop) is to do this:

Make sure you have a directory called '.config/autostart'. Then add a file to it called 'xbindkeys.desktop' with content along these lines:

[Desktop Entry]
Type=Application
Name=XBindKeys
Exec=xbindkeys
Icon=system-run
Comment=
Name[en_US]=XBindKeys
Comment[en_US]=
X-GNOME-Autostart-enabled=true

This is what happens in Gnome when you add an entry in System->Preferences->StartupApplications.

Tuesday, April 14, 2009

Installing Storey's edge microarray software on Ubuntu

It takes a few steps to install this (Intrepid Ibex, Ubuntu 8.10), but here's how I got it working (we'll see if there are any bugs):

edge website


  1. Install R

  2. sudo aptitude install r-base

  3. Download and unpack the source file:

  4. linux src page
  5. Install impute

  6. Download the above link and install with something like this:
    sudo R CMD INSTALL packages/impute_1.0-5.tar.gz

  7. prepare the compiling environment

  8. sudo aptitude install g++-4.2 gfortran-4.2 tetex-base
    # (also might need tetex-extras ...)
    sudo rm /usr/bin/g++ # just removes the soft link
    sudo ln -s /usr/bin/g++4.2 /usr/bin/g++
    sudo rm /bin/sh # just a link to /bin/dash
    sudo ln -s /bin/bash /bin/sh

  9. Compile the sucker

  10. cd src ; make ; make install

    The make install command just copies the .so files up a directory
  11. Run the software

  12. R

    Then from within R started at the base of the package:
    source("edge.r")
    edge()

  13. Restore the original environment

  14. sudo rm /usr/bin/g++
    sudo ln -s /usr/bin/g++4.3 /usr/bin/g++
    sudo rm /bin/sh
    sudo ln -s /bin/dash /bin/sh

Parametric and non-parametric t-testing

If your data are distributed normally, the t-test can help you determine if the means of your two samples are greater than or less than each other (one-tailed) or just plain different from each other (two-tailed). These examples are for paired samples, to make them not paired just delete the "paired=TRUE" statement altogether, default is unpaired.

We'll use the same data throughout:
x <- c(1.83, 0.50, 1.62, 2.48, 1.68, 1.88, 1.55, 3.06, 1.30)
y <- c(0.878, 0.647, 0.598, 2.05, 1.06, 1.29, 1.06, 3.14, 1.29)

When using your own data you just need them in vectors (as shown).

One-tailed
t.test(x,y,paired=TRUE,alternative="greater")
t.test(x,y,paired=TRUE,alternative="less")

Two-tailed
t.test(x,y,paired=TRUE)

What if your data are not normal? The non-parametric Wilcoxon test will do the trick. The Wilcoxon rank-sum test is for independent samples (unpaired). The Wilcoxon signed rank test is for paired samples.

wilcox.test(x, y, paired = TRUE)

Who is R?

After several years of using R to do various tasks from simple t-tests to much larger data sets I think I finally understand who R is.

R is like the computers of yesteryear, it does what you tell it, and only what you tell it, period. If you want more than the minimal amount of output, you have to ask for it. But it also has a bit of an attitude, for example, instead of outputting the type 3 sums of squares in ANOVA like virtually every other statistical package, it outputs the type 1 sums of squares by default. Why you might ask? The reason is because they want you to first think about what type of sums of squares you want, so by default they give you the one that isn't the most commonly used one. Hence R has a steep learning curve, which after several years I am still trying to surmount.

Enough talk, time for some code in the next post.

Saturday, April 11, 2009

Instant switching: compiz (gtk), emerald, metacity

In various places these are incorrectly listed. At least as of Intrepid Ibex, here's how to switch between window managers... still trying to figure this out...
metacity --replace
emerald --replace
compiz-decorator --replace
compiz # to start things up for compiz

Oh, but when I try it out I'm getting some problems. In theory ... Just put each of these lines in a custom application launcher on your panel (and maybe put those in a single drawer)

Thursday, March 26, 2009

ocaml batteries on Ubuntu

OCaml is a functional programming language. I'm trying to learn it right now, but it clearly has a steep learning curve, especially if you aren't familiar with functional programming languages. It does seem impressive in many ways, but we'll see, eh?

Anyway, the standard library seems a little sparse, so I am trying to install 'batteries'. Turns out it wants some dependencies to build and they aren't entirely straightforward. Here's how to get it building:

sudo aptitude install libcamomile-ocaml-dev libzip-ocaml-dev libtype-conv-camlp4-dev
libsexplib-ocaml-dev libbin-prot-camlp4-dev libocamlnet-ocaml-dev

(do we need libmagic-ocaml-dev ??)
This is super weird, you have to configure the program as super user because it wants to make a directory for batteries in /usr/local. Anyway, here's the install

sudo ./configure
sudo make all opt install install-doc

And it does take forever to make the documentation (maybe 5 minutes to install on my computer).