Category: Computers

URL forwarding

Forwarded my blog from my old server to this one. Added a Rewrite rule to httpd.conf on the old server in the main site <VirtualHost *:80> section:

RewriteEngine On
RewriteRule ^.*/blog(.*)$$1

Postscript site

Here’s a site with a good Postscript library for drawing variable width lines.

To add a rounded end I added an arc command after the bolt function:
20 setlinewidth
newpath 0 0 moveto
0 -50 200 -150 200 0 rcurveto
reversepath bolt
5 0 179 arc

I used two of these curves to draw a stylized pear.

Putting video clips on my blog

Putting video clips on my blog was a bit harder than I expected. I first tried converting the .MOV files the camera writes into .avi files using ffmegX and posting them using <embed> tag code. The files showed up great on my Mac but not at all on a Windows computer.

Flash format files, .flv, are the easiest cross-platform way to post video clips. Flash does require that the site supply a Flash player. There are many Flash players available. I tried OS FLV and it worked nicely.

To edit video files I used avidemux, then ffmegX to convert them to .flv, and I put them on the site using the ‘noscript’ <embed> code suggested by OS FLV with the OS FLV player.swf.

Scanners for macro photography

Scanners can be used for macro photography, at least the ones with a great depth of focus. The scanners with CCD sensors tend to have a good depth of focus while the thin scanners with a CIS sensor can only focus on objects a mm or two from the glass.

I collected a list of scanners recommended for macro photography.

from here:
EPSON Perfection 3170
from here.
Microtek ScanMaker X6 EPP
Artec AM12S, AM 2400-U Pro
Epson Expression 836XL
3D Pro Scanner
Memtek Memorex SCF 9360P 3D
from here:
Epson Perfection 1240U Scanner
Epson Perfection 1200U

Checking specs, these also look well suited:
Epson Perfection 2480
Epson Perfection V300
Epson Perfection 2450
Epson Perfection 3490

256 colors in vim on OS X

Terminal colors are broken out of the box in OS X terminals. In part due to a poor OS X terminal implementation, part due to problems with vim. I try new colorschemes and get strange, random looking results.

After many fruitless searches I finally got 256 colors working in vim in a terminal. This post and the GVim site were very helpful. It turns out that the included Terminal app in OS X only supports 16 colors. The terminal background can be set to any color which confuses the issue. The colortest Perl script available on the Gvim site makes this clear.
OS X Terminal colortest:
colortest run in Terminal

The free GNU licensed iTerm terminal does support 256 colors.
iTerm colortest:
colortest run in Terminal

OK, now the terminal supports 256 colors. There are still some hoops to jump through to get vi to show colors though. Most colorschemes are built for gui (using 24-bit RGB colors), so vim needs to be built with gui support. This can be checked with :echo has(‘gui’). It reports 1 for yes, 0 for no. The vim I had (default or Fink installed) didn’t have gui support, so I downloaded GVim and copied it over the old vim:

cp /Volumes/Vim-7.2.148/ /usr/bin/vim

and now vim has gui support.

I copied /usr/share/vimrc to /usr/bin because the downloaded vim didn’t know to look in /usr/share and added a few configuration lines:

” Doesn’t get set right.
set t_Co=256

” Needed because the new vim doesn’t know to look in /usr/share
set runtimepath=~/.vim,/usr/share/vim/vim72_2,/usr/bin/vimfiles,/usr/bin,/usr/bin/vimfiles/after,~/.vim/after
let $VIMRUNTIME=’/usr/share/vim/vim72_2′

syntax on
colorscheme LightTan

OK, so now 256-color support works and I can set colorschemes. They still don’t look right because colorschemes made for the gui don’t look right on a 256-color terminal. There’s a great vim script called CSApprox that converts gui colors to the closest of the 256 colors and makes gui colors look pretty good in a terminal. Download it, unzip it, and copy files to the vim directory:
sudo cp plugin/CSApprox.vim /usr/share/vim/vim72_2/plugin
sudo cp autoload/csapprox.vim /usr/share/vim/vim72_2/autoload

and now when I load colorschemes they look pretty close to what the Vim colorscheme test site shows, with the only difference due to font differences.

To get full color support when I log into a linux machine I need to do some more setup. To get gui support in terminal:
yum install vim-X11
and then add to /etc/profile:
alias vi=’gvim -v’
and “source /etc/profile” to enable it.
and add:

set t_Co=256

if &t_Co == 256
colorscheme LightTan

to /etc/vimrc to force 256-color mode and pick a colorscheme.

I also copied the CSApprox files to /usr/share/vim/vim70 and now it works when I ssh to this machine as well!

Indie games

I ran across the independently produced game World of Goo. Fun game, the stylish graphics caught my eye.

So I wondered what was involved in creating a modern game. What’s done? Tech wise, graphics engine, physics engine, AI, etc. Art and sound. Looked around, found these two sites:

Indie Game Developer Links

Never found the a straightforward answer to my question though.


Reading the ‘how we made it’ articles on their site, it looks like World of Goo was made using the open source PopCap framework. PopCap includes two physics engines, the 2D Chipmonk Physics library and the 3D ODE physics library!

Dawkins ‘Weasel’ program as a Perl one-liner

Explained at Panda’s Thumb:

Over at uncommon descent William Dembski is musing over Richard Dawkins Weasel program. Why you may ask? Way back in prehistory (the 1980’s) Dawkins wrote a little BASIC program (in Apple BASIC of all things) to demonstrate the difference between random mutation and random mutation with selection, which many people were having trouble grasping. Now, this wasn’t a simulation of natural selection, and Dawkins was very careful to point this out.

But as a demonstration of selection versus simple random mutation, with the string “methinks it is a weasel” being selected in a matter of minutes, when simple random mutation would take longer than the age of the Universe, it was pretty stunning. As a result, creationists have been having conniption fits over this little program for decades. Such is its power, the Issac Newton of Information Theory, William Dembski, spent a not inconsiderable portion of his time attacking this toy program. In particular, he claimed that after every successful mutation, the successful mutation was locked into place, and couldn’t be reversed. But he was wrong, and it seems he just can’t admit it.

The Weasel program starts with a random string. Then each generation ‘offspring’ strings are generated, each with one letter randomly changed. From among the offspring, the string closest to the target string is chosen each generation. Rather quickly this process of mutation and selection will change any string into the target string. I start with “Creationism is nonsense” and my target is “methinks it is a weasle”, the target Dawkins uses.

Since the creationists are having trouble making such a program, I wondered *just how short* a program could be written to do this. Here’s a first attempt as a eight line Perl one-liner. It can be cut & pasted into a Unix terminal:

perl -e '$|=1;$s="Creationism is nonsense";$e="methinks it is a weasle";$try=11;$let=length($s);@e=split(//,$e);while($s ne $e){$i=-1;while($i++< $try){$new_s[$i]=$s;$chr=int(rand(27))||-64;substr($new_s[$i],int(rand($let)),1,chr(96+$chr));@spl=split(//,$new_s[$i]);$j=0;$new_sc[$i]=0;while($j<@e){$new_sc[$i]++if$e[$j]eq$spl[$j++]}}@sc=sort{$new_sc[$b]<=>$new_sc[$a]}(0..$#new_sc);@new=(shift@sc);while(@sc&&$new_sc[$sc[0]]==$new_sc[$new[0]]){push@new,shift@sc}$s=$new_s[$new[int(rand(@new))]];printf("Generation %5d, %-2dmismatches:  $sr",++$n,$let-$new_sc[$new[0]]);}print"n";'

(When I cut & paste the one liner on my Mac it changes the final single quote to an end quote and the last two pairs of double quotes to funny double quotes, so keep an eye out and change them back if you need to).

And the normal length 35 line program with comments:


$s="Creationism is nonsense";
$e="methinks it is a weasle";
$try=11; #New offspring per generation.


while($s ne $e) {
  #Make $try new strings.
  while($i++< $try){

    #Mutate one char of the new string.
    $chr = int(rand(27)) || -64;

    #Count the characters in the new string that match the target string.
    while($j<@e){$new_sc[$i]++ if $e[$j] eq $spl[$j++]}

  #Find high scoring offspring strings.
  @sc = sort {$new_sc[$b]<=>$new_sc[$a]}(0..$#new_sc);

  @new=(shift @sc);
  while(@sc && $new_sc[$sc[0]] == $new_sc[$new[0]]){push @new,shift @sc}

  #Set new string to a random offspring strings from among the high scoring offspring.
  $s = $new_s[$new[int(rand(@new))]];

  printf("Generation %5d, %-2dmismatches:  $sr",++$n,$let-$new_sc[$new[0]]);

The shape of programmer’s brains

I ran across a remarkable paper, “The Camel has two Humps”. Incoming Introduction to Programming students all *want* to learn to program, but about half the class never gets the hang of it and never will. The authors found a test that identifies the students that can learn to program.

The authors’ pretest asks questions about variable assignment: a=10, b=20, a=b. There is a typical meaning for these assignments in programming languages but the incoming students may not know them. So the authors classify the type of logic required to reach different answers and whether the students use the same logic for each question or switch around on different questions. Students who come up with consistent answers for different questions are the students who can learn to program.

Here’s a key figure:
consistent and inconsistent answers corellated with grades

This is remarkable, a way to candle incoming CS students and figure out (mostly) which ones can learn to program.

One notable thing that further research can answer is about the oddballs. The 2-3% of initially inconsistent testers that *do* learn to program–what sort of programmers are they? Do they end up writing different programs than the typical programmer?