Archive for March, 2010

php on cims web site

Tuesday, March 30th, 2010

Cims has super funny permission settings on its public_html folders. I have a LaTeX in browser running there which is a very simple script. The real trouble was setting up the permissions.

Here’s the permissions of the containing folder, latex-in-browser/:


drwx---rwx   2 jacobson asj237        21 Mar 30 10:33 latex-in-browser

And of the relevant php files, latex-in-browser/index.php and latex-in-browser/typeset.php:


-rwx---r-x   1 jacobson asj237      4203 Feb  6 00:47 latex-in-browser/index.php
-rwx---r-x   1 jacobson asj237       795 Mar 30 10:33 latex-in-browser/typeset.php

Another thing that I found was the command in my typeset.php script:


  $output=`pdflatex -interaction nonstopmode -halt-on-error $texFile`;

was not being executed. But when I did


which pdflatex

and found the full path to pdflatex. Then


  $output=`[insert/full/path/to]pdflatex -interaction nonstopmode -halt-on-error $texFile`;

worked fine.

OpenGL cube map example on Mac OS X

Friday, March 26th, 2010

I had some trouble getting the demos from NVidia’s cube map OpenGL tutorials to work on my MacBook Pro running Mac OS X 10.5 with NVIDIA GeForce 9400M graphics card. It seems that this demo code is totally outdated, not to mention you need to change some things to get OpenGL programs working on Mac OS X. (You can just download the modified cube map demo)

The basic things you need to change in the cube map demo is:

  1. Get rid of all of the _EXTs from the GL constants. I guess, these are hanging around from the days when the cube map was not well supported. Now, and especially on Mac OS X, you should expect that it is.
  2. Likewise get rid of the run time check for GL_EXT_texture_cube_map:
    glutExtensionSupported("GL_EXT_texture_cube_map")
  3. Change the includes from #include <GL/gl.h> to #include <OpenGL/gl.h> and #include <GL/glut.h> to #include <GLUT/glut.h>

Lastly to compile use the following:

cc -o cubemap cubemap.c -framework GLUT -framework OpenGL -lXext -lX11 -lm
cc -o cm_demo cm_demo.c trackball.c tga.c -framework GLUT -framework OpenGL -lXext -lX11 -lm

You will probably get these warning when compiling the cm_demo program though it didn’t seem to matter:


cm_demo.c: In function ‘loadFace’:
cm_demo.c:256: warning: incompatible implicit declaration of built-in function ‘exit’
cm_demo.c: In function ‘keyboard’:
cm_demo.c:356: warning: incompatible implicit declaration of built-in function ‘exit’
tga.c: In function ‘gliReadTGA’:
tga.c:385: warning: assignment from incompatible pointer type
tga.c:388: warning: assignment from incompatible pointer type

This got the whole thing working:
cube map demo screenshot

Note: I have made all the necessary changes to the demo:
Download cube map demos with these changes already made

Find big directories using du and (e)grep

Thursday, March 25th, 2010

Here’s a simple script I’m using to locate big directories (larger than 1GB):


du -h | grep "^ *[0-9][0-9.]*G"

The output looks like this:


1.1G	./Art/2007
2.5G	./Art/2008/Party Freakz Pasta Party
6.3G	./Art/2008
9.2G	./Art
 24G	./Documents/Parallels/Windows 7.pvm/Windows 7-0.hdd
 24G	./Documents/Parallels/Windows 7.pvm
 24G	./Documents/Parallels
 26G	./Documents
2.5G	./Downloads/enstrophy-big-endian
 33G	./Downloads
...
100G	.

Here’s how I find big directories greater than 100MB:


du -h | egrep "^ *([0-9][0-9][0-9][0-9.]*M)|([0-9][0-9.]*G)"

To list files, too, just add the -a flag to du like this:


du -ah | grep "^ *[0-9][0-9.]*G"

Single Image iPhone Apps

Tuesday, March 23rd, 2010

I have a new idea for minimalist applications. How about applications which are solely comprised of just one (static) image. In some sense this is treating visualization as an application. Successful manifestations of this idea have been around for ages in the form of maps.

one of ad reinhardt's 'black painting'

Wikipedia defines an application as “computer software designed to help the user to perform a singular or multiple related specific tasks.” So it seems to me obvious that a simple image explaining the conversion of fahrenheit to celsius is just as much as an application that prompts the user to type in “65 degrees fahrenheit to celsius”.

See my growing list of single image applications for the iPhone.

Burt-Adelson spline image blending

Thursday, March 18th, 2010

Using the matlabPyrTools library to build Laplacian and Gaussian pyramids of images, I’ve implemented the blending technique described in section 3.2 of A Multiresolution Spline With Application to Image Mosaics by Peter J. Burt and Edward H. Adelson. The idea is fairly simple and well explained in their article. Here are some of my results:

Standard facial feature blended onto hand

hand mouth spline blend comparison
hand mouth spline blend result

The Burt-Adelson Burt-Adelson blend

burt adelson face spline blend comparison
burt adelson face spline blend result

A portrait of the artist Nixon as a young man

nixon colin face spline blend comparison
nixon colin face spline blend result
Download the zipped folder of my source.

Vim applescript application

Sunday, March 14th, 2010

I wanted a quick way to open up files from finder in vim so I wrote a little applescript application. I use Script Editor.app to save this as an Application in a file called Vim:


on open (these_files)
  set names to ""
  repeat with this_file in these_files
    set names to names & (quoted form of POSIX path of this_file) & " "
  end repeat
  tell application "Terminal"
    activate
    do script "vim " & names
  end tell
end open

Download the vim applescript app

I would like to know how to make this application come up as a right-click, open with... option for every file type, but I haven't figured that out yet...

Bash keyboard shortcuts on Mac OS X

Sunday, March 14th, 2010

Found this list of Bash keyboard shortcuts on Mac OS X. Here are my favorites that I want to remember:

Say you have typed ( where the pipe, “|”, represents where your cursor is):


mv foo bar|

Then if you hit CTRL+[ then B you will move back one word:


mv foo |bar

To go forward again hit CTRL+[ then F:


mv foo bar|

Now the coolest one, to swap the last two words hit CTRL+[ then T:


mv bar foo|

iPhone stuck zoomed in

Friday, March 12th, 2010

I took my iPhone out of my pocket and the “slide to unlock” screen was so zoomed in that I could barely do anything. To zoom back out (I now know) just do a three-finger double tap anywhere on the screen.

To turn zooming off so this never happens again go to settings > general > acessibility > zoom OFF.

Compiling MATLAB engine demo on Mac OS X with gcc

Friday, March 12th, 2010

I followed the MATLAB instructions on compiling a C program that uses the matlab engine to call matlab functions. The works find when I run the commands from MATLAB (with the exception that I must use !./engdemo with the ./ to make the thing run). But if I try to compile the program on the command line using gcc, I get this error:


Undefined symbols:
  "_mxCreateDoubleMatrix_730", referenced from:
      _main in ccpVU28R.o
  "_engOutputBuffer", referenced from:
...
ld: symbol(s) not found
collect2: ld returned 1 exit status

After much searching around I have found a solution to this problem. Not sure how good it is since it involves messing with DYLD_LIBRARY_PATH and I’ve been warned never to mess with that. None the less here’s what I did:

First in your ~/.profile add (or just type into the shell):


export MATLAB="/Applications/MATLAB_R2009aSV.app/"

You may have to change MATLAB_R2009aSV.app to the name of the MATLAB program folder on your computer.

Then in the shell (you will have to do this everytime you compile or add this to your ~/.profile):


export DYLD_LIBRARY_PATH=$MATLAB/bin/maci/:$MATLAB/sys/os/maci/:DYLD_LIBRARY_PATH

64-bitters may need to change the maci to maci-64 or something.

Finally compile using all these flags and parameters:


g++ -o engdemo engdemo.cpp -I$MATLAB/extern/include/ -L$MATLAB/bin/maci/ -leng -lm -lmat -lmx -lut 

or


gcc -o engdemo engdemo.c -I$MATLAB/extern/include/ -L$MATLAB/bin/maci/ -leng -lm -lmat -lmx -lut 

A similar solution for linux

Update: If you run into an error that goes something like this:


ImportError: dlopen([your library], 2): Library not loaded: @loader_path/libeng.dylib

Then you need to change your DYLD_LIBRARY_PATH as mentioned above.

Although then in a different library I get a new error:


ImportError: dlopen(lib/_Drawers.so, 2): Library not loaded: /opt/local/lib/libmpfr.1.dylib
  Referenced from: [your other library]
  Reason: Incompatible library version:  [your other library] requires version 4.0.0 or later, but libmpfr.1.dylib provides version 3.0.0

Which seems to be because MATLAB has its own out of date libmpfr.1.dylib which causes CGAL to belch. Haven’t come upon a solution for this yet but will post if I do.

List all installed python modules (or determine bad module versions)

Thursday, March 11th, 2010

Here’s a simple python script to list all installed python modules:


python -c "help('modules')"

Only problem is that when I run this I see:



Please wait a moment while I gather a list of all available modules...

Fatal Python error: Interpreter not initialized (version mismatch?)
Abort trap

This error message is not helpful because it does not tell me which Python module caused the error. So, to determine which module is actually compiled with the wrong python version I run this command with the verbose flag instead:


python -vc "help('modules')"