Archive for July, 2012

Download high definition images from christies

Saturday, July 14th, 2012

Place this in


id=`echo "$1" | sed -e "s/.*ObjectID=\([0-9]*\)&.*/d\1/g"`
final=`echo "$1" | sed -e "s/.*lotfinder\\/[^\\/]*\\/\(.*\)-[0-9]*-details.*/\1/g"`
echo $id
echo $final

echo $URL

# Explicitly declare integers
typeset -i i j k max_i max_j max_k tile_x tile_y

if [ $2 ]; then
  let max_i=$2
  #Try to find biggest zoom size
  let i=0
  while true; do
    if wget $URL/$i-0-0.jpg --spider -v -O/dev/null 2>&1 | grep "Remote file exists\." 1> /dev/null
      echo "$i-0-0.jpg exists"
    let i++

#let max_i=4

#Try to find biggest first index
let j=0 max_j=0
while true; do
  if wget $URL/$max_i-$j-0.jpg -v 2>&1 | grep "image/jpeg" 1> /dev/null
    echo "$max_i-$j-0.jpg exists"
    # clean up
    rm -f $max_i-$j-0.jpg
  let j++

#let max_j=12

#Try to find biggest second index
let k=1 max_k=0
while true; do
  if wget $URL/$max_i-0-$k.jpg -v 2>&1 | grep "image/jpeg" 1> /dev/null
    echo "$max_i-0-$k.jpg exists"
    # clean up
    rm -f $max_i-0-$k.jpg
  let k++

#let max_k=8

let j=1
while ((j<=max_j)); do
  let k=1
  while ((k<=max_k)); do
    if wget $URL/$max_i-$j-$k.jpg -v 2>&1 | grep "image/jpeg" 1> /dev/null
      echo "$max_i-$j-$k.jpg exists"
      echo "$max_i-$j-$k.jpg not found!"
    let k++
  let j++

# get list of images in an order that montage will understand
let k=0
while ((k<=max_k)); do
  let j=0
  while ((j<=max_j)); do
    list="$list $max_i-$j-$k.jpg"
    let j++
  let k++

let tile_y=max_j+1
let tile_x=max_k+1

montage $list -tile ${tile_y}x${tile_x} -geometry +0+0 -quality 100 $final.jpg
# clean up
rm -f $list

Then you can issue:

./christies ""

Just be sure to put quotes around the url.

Renamed /usr on Mac OS X —> panic

Friday, July 13th, 2012

I recently got a new mac and issued (like a baboon):

sudo mv /usr /usr_off

I immediately noticed that nearly everything in my computed stopped working. I could cd around but even ls produced:

Illegal instruction 4

errors. Of course I tried renaming the folder back but sudo and mv also produced this error.

I started freaking out when I tried to connect to a different mac and the whole thing froze. When I restarted I immediately got a kernel panic:

... Process 1 exec of /sbin/launchd failed ...

Booting in “Safe mode” (holding SHIFT) did not work.

The solution was to boot holding ALT and choose Recovery HD (luckily this exists because my MacBook Air has no DVD drive). After choosing the language and choosing Reinstall Mac Os X I was able to choose Terminal from the top menu bar. Here I could (scarily) issue:

cd /Volumes/Macintosh\ HD
mv /usr_off /usr

without ever giving a password.

I restarted and everything is back to normal.

High quality desktop backgrounds script

Tuesday, July 10th, 2012

Here’s a script I use to create 2560xx1440 high quality backgrounds from images:

mkdir -p output
mogrify -fuzz 25% -trim -resize 2560x1440 -background white -gravity center -extent 2560x1440 -format jpg -quality 100 -path output *.jpg

It first creates the output directory than converts all jpgs in the directory to be 2560 by 1440 images trimmed of their borders then padded with white.

Fast, sparse kronecker product with identity in MATLAB

Friday, July 6th, 2012

I needed to compute:

  K = kron(A,speye(n,n));

but was a little dismayed at the speed. Here’s how I get about a 6x speed up:

  % Compute kron(speye(n,n),A) in a fast way       
  C = cell(n,1);                                   
  [C{:}] = deal(A);                                
  K = blkdiag(C{:});                               
  % Rearrange rows and columns                     
  I = reshape(reshape(1:(size(A,1)*n),size(A,1),n)',size(A,1)*n,1);
  J = reshape(reshape(1:(size(A,2)*n),size(A,2),n)',size(A,2)*n,1);
  K = K(I,J);

Title with hidden axis in matlab figure

Thursday, July 5th, 2012

I often hide the current axis in a matlab plot figure using:

set(gca, 'visible', 'off');

But then if I call


The title is not visible (as it is a child object of a hidden axis).
The fix is simple:


Full high resolution images from

Wednesday, July 4th, 2012

Click on the image to see a full resolution version (it’ll be in a <canvas> broken apart into pieces. Use Safari web inspector to find the URL of one of the pieces:

Delete the last half:


Ffmpeg to wmv bitrate parameter order gotcha

Tuesday, July 3rd, 2012

I had been using:

ffmpeg -pass 1 -passlogfile ffmpeg2pass -g 1 -b 16000k -i output.wmv
ffmpeg -pass 2 -passlogfile ffmpeg2pass -g 1 -b 16000k -i output.wmv

which at one point gave me an error on the second pass:

[msmpeg4 @ 0x7fde41844e00] requested bitrate is too low

I tried increasing 16000k to 32000k, but this did not make the error go away. Turns out I just needed to switch the order of the parameters:

ffmpeg -pass 1 -passlogfile ffmpeg2pass -g 1 -i  -b 16000k output.wmv
ffmpeg -pass 2 -passlogfile ffmpeg2pass -g 1 -i  -b 16000k output.wmv

After Effects preserve correct colors on export

Tuesday, July 3rd, 2012

The preview in after effects was showing me the correct colors I wanted to see, but then when I exported (even using Quicktime Animation) the colors became a bit faded and washed out. To fix this I went to File > Project Settings … and set Depth to 32 bits per channel and Working Space to Apple RGB.


After effects with default color settings


After effects with good color settings

Casting bug in g++ llvm 4.2 int to double

Monday, July 2nd, 2012

The following code seems to compile incorrectly using g++, llvm version 4.3 with -O3:

#include <iostream>

int main(int argc,char * argv[])
  using namespace std;
  // loop over canonical view quaternions
  for(int sign = -1;sign<=1;sign+=2)
    std::cout<<sign<<" --> "<<(double)sign<<std::endl;
    // Necessary to reproduce bug
    for(int i = 0; i<1; i++)
      for(int j = 0;j<1;j++)
  return 0;

For some reason it is not casting the int, rather it seems to be just reinterpreting the bits as a double.

Switching off compile optimization, switching to plain old g++ or switching to float instead of double works, but are not helpful in my case. Instead I did something that works, but is likely non-optimal, I replaced the double cast with a float cast followed by a double cast.