## Running libigl-unit-tests on the dgp medusa server

October 21st, 2016

After a long battle with the development tools on the server in our lab, I can follow this to build and run the unit tests for libigl.

ssh medusa
# Only certain nodes support gcc4.8 and g++4.8
ssh snake 1-3
# use devtool set to enable gcc and g++ 4.8
source scl_source enable devtoolset-2
## Clone libigl
#git clone --recursive -b alecjacobson git@github.com:libigl/libigl.git
## Clone libigl-unit-tests __recursively__ to bring in googletest
#git clone --recursive git@github.com:libigl/libigl-unit-tests.git
mkdir -p libigl-unit-tests/build
cd libigl-unit-tests/build
# Matlab exists on this node but disagrees with g++4.8, Comiso wants nonexistent BLAS
cmake -DCMAKE_C_COMPILER=which gcc -DCMAKE_CXX_COMPILER=which g++ -DLIBIGL_WITH_COMISO=OFF -DLIBIGL_WITH_MATLAB=OFF ..
time make -j32


## Rasterize everything in pdf except text

October 19th, 2016

I had an issue including a PDF with transparency as a subfigure to another PDF. This lead me down a dark path of trying to rasterize everything in a pdf except for the text. I tried rasterizing everything and just running OCR on top of the text but OCR-ized selection is weird and the text recognition wasn’t perfect. Not to mention that would have been a really round about way to solve this.

Here’s the insane pipeline I settled on:

• open the PDF in illustrator
• save as input.svg, under options “use system fonts”,
• run ./rasterize-everything-but-text.sh input.svg output.svg (see below)
• open output.svg in illustrator, save as raster-but-text.pdf

The bash script ./rasterize-everything-but-text.sh is itself an absurd, likely very fragile text manipulation and rasterization of the .svg files:

#!/bin/bash
#
# Usage:
#
#     rasterize-everything-but-text.sh input.svg output.svg
#
input="$1" output="$2"
# suck out header from svg file
header=dos2unix < $input | tr '\n' '\00' | sed 's/$$.*<svg[^<]*>$$.*/\1/' | tr '\00' '\n' # grab all text tags text=cat$input | grep     "<text.*"
# create svg file without text tags
notextsvg="no-text.svg"
notextpng="no-text.png"
cat $input | grep -v "<text.*" >$notextsvg
# convert to png
rsvg-convert -h 1000 $notextsvg >$notextpng
# convert back to svg (containing just <image> tag)
rastersvg="raster.svg"
convert $notextpng$rastersvg
# extract body (image tag)
body=dos2unix < $rastersvg | tr '\n' '\00' | sed 's/$$.*<svg[^<]*>$$$$.*$$<\/svg>/\2/' | tr '\00' '\n' # piece together original header, image tag, and text echo "$header
$body$text
</svg>" > "$output" # Fix image tag to have same size as document dim=echo "$header" | grep -o 'width=".*" height="[^"]*"' | tr '"' "'"
sed -i '' "s/$$image id=\"image0\"$$width=\".*\" height=\"[^\"]*\"/\1$dim/"$output


## Microsoft word: Accept all formatting changes, without accepting others

October 4th, 2016

I just received some feedback on a document I converted to Microsoft Word. The copy-editor diligently unified the converted formatting during editing. This created hundreds of “tracked changes” that made it very difficult to find the “real” content changes (insertions/deletions, comments, etc.).

I don’t use Word often and found it very difficult to work with so many tracked changes. The long list just ran down and off the bottom of the window with no apparent way to even scroll through them.

There is a way to show only the interesting changes. Review > Markup Options > [unselect Formatting]

Alternative to accept permanently and get rid of all of the Formatting changes. You can Review > Markup Options > [unselect all but Formatting], then Review > Accept > Accept All Changes Shown, then Review > Markup Options > [select all but Formatting], to bring back the other changes.

## Fix dyld linker errors when installing new mosek toolbox

October 3rd, 2016

Each time I upgrade my mosek library, matlab panics and can’t find it. The old solution was to monkey with the DYLD_LIBRARY_PATH in all sorts of funny places: ~/.profile, /etc/launch.d, ~/Library/LaunchAgents/environment.plist

These all worked at some point, but as far as I can tell, no longer do. They’re also the wrong way to install libraries.

Fortunately, mosek has made life easy. Just

cd /usr/local/mosek/8/tools/platform/osx64x86/bin/
python install.py


This will actually fix all of the binaries and mex files using otool and install_name_tool to find dynamic libraries in their installed locations.

## Create a “when I am busy” calendar

September 12th, 2016

Here’s how to create a public calendar on your website that shows when you are busy. For example, mine

\1. To set up sharing go to your calendar on http://calendar.google.com, select Sharing from the drop down on the left side:

\2. Make sure that it’s public but only showing busy:

\3. Then go to “Calendar Details”, copy the <iframe ... HTML tag:

\4. On your website, create a calendar.html page with the following contents (replacing the <iframe ... tag appropriately):

“

<!DOCTYPE html>
<html>
<title>Alec's Busy</title>
<style>
body { margin: 0;position:fixed; left:0; width:100%; top:0; height:100%; }
iframe { margin: 0;display: block; width:100%; height:100%; }
</style>
<body>
<iframe src="https://www.google.com/calendar/embed?title=Alec&#39;s%20Busy&showCalendars=0&mode=WEEK&src=alecjacobson%40gmail.com&ctz=local" style=" border-width:0 " width="100%" height="95%" frameborder="0" scrolling="no"></iframe>
</body>
</html>


“

Finally, if you’re logged into your google account and you visit your calendar.html page, you might be freaked out because you see all of your events (instead of busy). But to verify that it’s really hidden, use an “incognito”/private window to see that it just shows “busy”.

## Make Two-Sided Printing the default setting on mac os x

September 7th, 2016
1. In Terminal.app issue: cupsctl WebInterface=yes
2. In a browser visit http://localhost:631/printers
3. Click on the printer’s name
4. On the second drop-down list choose “Set Default Options”
5. Change “2-Sided Printing:” to “Long-Edge (Portrait)”

## (Slightly) Faster way to compute number of unique elements in matlab matrix

August 31st, 2016

The standard way to compute the number of unique entries in a matlab matrix A is:

numel(unique(A))


If our entries are positive integers, we can try to do the same thing using sparse with:

nnz(sparse(A(:),1,1,size(A,1),1))


but actually this is slower.

I don’t see a way to avoid a sort. I came up with this,

sum(diff(sort(F(:)))~=0)+1


As far as I can tell, this will work for matrices that don’t have infs and nans. It’s slightly faster than number(unique(A)). I have a feeling I’m only winning anything here because I’m avoiding overhead within unique

## Eitan Grinspun’s “How to host a visit”

August 25th, 2016

Eitan has prepared a google doc on hosting visitors to the lab that I find very useful. It contains a detailed list (some unique to Columbia) of things you should do to host a visitor and when you should do them.

## Real-time LaTeX in browser

August 23rd, 2016

A long time ago, I made a little web app that allowed you to submit Latex code to a server, the server would run pdflatex and then send back the pdf to be rendered on the page.

Nowadays MathJax can render LaTeX equations in the browser. I found http://www.texrendr.com that let’s you interactively write formulae, but it’s restricted to a single equation. There’s also the LaTeXit standalone app, but you have to keep hitting “typeset”. This isn’t so useful if you’re trying to quickly type math during a Skype call.

So I wrote a little program to run in the browser:

http://www.cs.toronto.edu/~jacobson/latex.html

You can also fork the git gist

## option click on volume menu bar item to change sound devices

August 19th, 2016

I find myself often switching the microphone and speaker devices on my mac. I usually go all the way through System Preferences > Sound, but I stumbled upon a much faster route.

Normally if you click on the volume menu item at the top of the screen you get a little volume slider:

If you hold OPTION while you click you see a device selection menu: