May 10

If PDF documents show up funny within Preview, particularly if the fonts appear wrong, there is a simple fix. Open up a Terminal window and type

killall -u <username> ATSServer

Restart Preview and the problem should be fixed.

Mar 22

Often, you’ll have a sequence of image files from which you’d like to make a movie that plays in PowerPoint for presentations. The best way I’ve found to do this is to create Windows Media files. Here is the recipe I’ve found that works well using Windows XP. You’ll need to download ImageJ and Windows Media Encoder. Your mileage may vary.

  1. Open ImageJ (version 1.41 or above is recommended). Load the sequence (File->Import->Image Sequence…). The length of the videos you can create is limited with this method, but it works well enough for videos that are under 10 seconds long. You should be able to encode longer still frame sequences by opening the image sequence as a virtual stack.
  2. Crop the video so that the width and height of the videos are even numbers. Otherwise, Windows Media Encoder will save that the AVI is not valid.
  3. Save the image sequence as an AVI file (File->Save As->AVI…). Choose JPEG as the compression method and set the quality to 100. Set the frame rate to something reasonable (e.g. 10, 15, 30 fps).
  4. Open Windows Media Encoder. In the New Session wizard, choose “Convert a file”. Set the source file to the AVI you exported from ImageJ. Set the output file to the name you want. Click next. Choose the type of content distribution you are targeting. For playback in PowerPoint, choose “File download (computer playback)”. Click next. This will result in the highest quality video. Under encoding options, choose something suitable. I choose “High definition quality video (5 Mbps VBR)”. Click next. Name the video and click next. Under the “Settings Review” panel, uncheck the “Begin converting when I click Finish” checkbox and click Finish.
  5. Before doing anything else, we’ll change the size of the output video. Click on the “Properties” button in the toolbar at the top of the application window. Click on the “Video Size” tab. Under the “Crop” settings, choose method “Custom”. Under the “Resize” settings, choose “No resizing” unless you want the video to be resized. When finished, click “Apply”.
  6. Finally, click the “Start Encoding” button in the toolbar. You’ll see a preview of your video as the encoding proceeds.

That’s it. Now test out your video in PowerPoint and make sure it plays in presentation mode.

Feb 01

Awk makes computing the average of a column of numbers in a text file very easy. Here’s the command for computing the average of the 5th column in a text file:

cat my_file.txt | awk '{sum=sum+$5}END{print sum/NR}'

The $5 means the 5th column and the NR means the number of entries (rows) in the column.

Feb 01

The ‘cut’ utility on Linux/Unix is useful for selecting columns from a delimited text file. It’s basic usage is

cat my_file.txt | cut -d ' ' -f 2

This will select the second column from a space-delimited file. The -d option specifies the delimiter (default is tab) and the -f option specifies a comma-separated list of columns that you want to select from the file.

Dec 12

To remove CVS files from a module you have checked out from a CVS repository, you can use a simple one-line command:

find -type d -wholename '*CVS' | xargs /bin/rm -rf

Execute this from the root of the CVS module that you checked out and want to clean up.

Nov 20

Finding a common time when busy people can meet is a difficult challenge. Doodle.com makes it easy for the meeting organizer to create a list of proposed times. People attending the meeting can check off the times that work for them, making it easy to find a meeting time.

Nov 18

From time to time, you may need to interface C code with Fortran code. One way to do this is to use the utility f2c to convert Fortran 77 code to C code that can be compiled with a C compiler that compiles ANSI C. Searching online, I couldn’t find a good written guide to compiling f2c from source. I did find instructions for compiling on Mac OS X and have adapted those instructions for a linux installation.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
setenv INSTALL path/to/your/local/install/directory
curl "http://netlib.sandia.gov/cgi-bin/netlib/netlibfiles.tar?filename=netlib/f2c" -o "f2c.tar"
tar -xvf f2c.tar
gunzip -rf f2c/*
cd f2c
mkdir libf2c
mv libf2c.zip libf2c
cd libf2c
unzip libf2c.zip
cp makefile.u Makefile
make
cp f2c.h $INSTALL/include
cd ../src
cp makefile.u Makefile
make
cp f2c $INSTALL/bin

Copy the f2c executable to a local bin directory to make it available as a command. To compile C code converted from Fortran with f2c, you’ll have to link against the library libf2c.a generated during the build.

If you want to create a shared object from your converted source code on Linux, you’ll need to add the -fPIC option to the CFLAGS variable in the Makefile in the libf2c directory.

Nov 12

ImageMagick’s ‘convert’ program makes it easy to stitch together two separate images so that they appear side-by-side in another image. This can be very useful for making demo videos. The command is simple:

convert image1.png image2.png +append output.png

That’s it. The command assumes image1.png and image2.png are the same height.

To apply this command to a sequence of images and get a sequence back, it does not work to do the following:

convert image1*.png image2*.png +append output.png

This actually appends all the specified images into a single frame. Instead, you can write a simple shell script to run the command many times. This one runs in bash:

n=0;
while [ $n -lt 180 ];
do
   printf -v file1 "ModelResized/spindle-model%04d.png" "$n";
   printf -v file2 "Simulation/spindle-sim%04dG.png" "$n";
   printf -v outFile "output%04d.png" "$n";
   convert $file1 $file2 +append $outFile;
   n=$[$n+5];
done;

It’s kind of ugly, but it works. One thing to note: printf works just like the C function printf. The -v VAR option stores the formatted string output into the variable VAR.

Nov 07

LeechBlock is just the Firefox plugin I’ve been looking for to prevent me from wasting my day at school. It lets you enter which sites you want to block and when you want to block them. You can block at fixed time periods during the day or set it to limit the time you visit the sites per unit of time (5 minutes on reddit per hour, for example).

Now, back to productive work!

Oct 28

Here’s a helpful tip for redirecting visitors from your UNC CS home page URL (i.e., http://www.cs.unc.edu/~yourname/) to another directory. In my case, I wanted to redirect visitors to my WordPress installation rooted in a subdirectory.

In your public_html directory, create a file named .htaccess and add the following text to it:

redirect 301 /~cquammen/index.html http://wwwx.cs.unc.edu/~cquammen/wp/

In my case, I want to redirect visitors to my WordPress installation directory. In the UNC CS department, WordPress and other web applications can run only on the wwwx server, not the www server, so I am redirecting to that server.