Archive for July, 2011

Find files from the future and touch them

Friday, July 29th, 2011

Moving files off my old laptop I somehow managed to corrupt the Last Modified dates. Many had their dates set to Epoch, but others were set to May 2021. This was very annoying. When I would sort by Last Modified I would get all these bogus files coming up on time. So, here’s a simple bash script to find all files with last modified date’s greater than the current time and touch them so that their last modified date is rest to the current time.


USAGE="Usage: find_and_touch_future_files [directory]"
if test -z "$1" 
  echo "$USAGE"
  exit 1

if [ ! -d $1 ]; then
  echo "find_and_touch_future_files: $1 is not a directory"
  echo "$USAGE"
  exit 1

# make a temporary file (timestamped with right now)
touch $tmp
# find all files modified after temp file (right now) and touch them 
find $1 -newer $tmp -exec touch {} \;
# clean up temp file
rm $tmp

Downgrade iPhone from 4.3.5 to 4.3.3

Thursday, July 28th, 2011

I upgraded to ios 4.3.4 and then 4.3.5 and finally wanted to go back to 4.3.3. At this point I tried to download the ipsw of 4.3.3 and restore with it via itunes. But I get the error:

The iPhone could not be restored . This device isn’t eligible for the requested build.
  1. Upgrade to 4.3.5 OOOOOPssss
  2. Add

    to the end of /private/etc/hosts

  3. Download the 4.3.3 ipsw
  4. Use Pwnagetool in expert mode, giving it the 4.3.3 ipsw, this creates a custom ipsw
  5. In Itunes option+restore using the custom ipsw
  6. After that restore is done, RE-option+restore in iTunes, this time with the regular 4.3.3 ipsw

Share internet (via wifi Airport) applescript

Sunday, July 17th, 2011

Here’s an applescript we’ve been using at home to share the ethernet internet connection between our two laptops. The computer with the ethernet cord plugged in runs this script, then the other computer can connect to the wireless network of that computer’s name and share its internet connection.

tell application "System Preferences"
end tell

tell application "System Events"
	tell process "System Preferences"
		click menu item "Sharing" of menu "View" of menu bar 1
		delay 2
		tell window "Sharing"
			if value of checkbox 1 of row 11 of table 1 of scroll area 1 of group 1 is 1 then
				click checkbox 1 of row 11 of table 1 of scroll area 1 of group 1
				click checkbox 1 of row 11 of table 1 of scroll area 1 of group 1
			end if
			click checkbox 1 of row 11 of table 1 of scroll area 1 of group 1
			delay 1
			if (exists sheet 1) then
				if (exists button "Turn AirPort On" of sheet 1) then
					click button "Turn AirPort On" of sheet 1
					delay 1
				end if
				click button "Start" of sheet 1
			end if
		end tell
	end tell
	tell application "System Preferences" to quit
end tell

Downloads (zip) Here’s a version wrapped into an app with a nice little icon so you can put it on your dock.

Making ==

Wednesday, July 13th, 2011

At some point youtube wasn’t letting me link to I guess because it was too long. So I made a symbolic link on my server:

ln -s weblog blog

This worked OK, until my friend realized that when you accessed my blog through all the links wordpress made were getting screwed up.

At first when I tried to tackle this with .htaccess Apache directives, I came up with:

RewriteEngine on
RewriteBase /
RewriteRule blog/(.*) weblog/$1

But then wordpress was still constructing the urls wrong (sometimes putting weblog/blog/… instead of just weblog/… in links), so I had to have:

RewriteEngine on
RewriteBase /
RewriteRule blog/(.*) weblog/$1
RewriteRule weblog/blog/(.*) weblog/$1

But then this is annoying, although the page works, you could have every page with weblog/blog/… instead of just weblog/… It’s kind of ugly. So, I found this very simple solution instead:

Redirect /blog /weblog

Now blog/something just redirects to weblog/something. The redirect costs the view an extra network back and forth but oh well.

Super resolution from many small images

Wednesday, July 13th, 2011

nude in a white dress many lo res to single hi res

Searching for large, high resolution images of famous artwork I’m often frustrated. There are so many small, low resolution images. Many are different resizes of the same image, but there are still many totally different images of the same thing: photographs various tourists have taken, scans from different galleries or museums. What I always end up wishing for is a way to combine all of these low resolution images into one super-resolution image. In this specific case of famous artwork, the problem should be rather simplified from the general problem of super-resolution. The images are of the exact same object. And the object more or less doesn’t change over time. There are lighting differences, but we can assume that since the work is famous there will be enough “correct” images to uncover the true colors. The images will be different scales, and perhaps taken from slightly different camera orientations or projections. But since artwork is mostly photographed head on with little to no perspective projection, I think these will be easy to cope with.

My working example will be to uncover a super-resolution version of Matisse’s “Nude in a white dress”. If you’d also like to try, here’s a zipped folder of bunch of low-res images of the painting I’ve grabbed from the web. But it’s easy to make your own dataset. Just search for images of your favorite famous painting.

Rename files with number using bash

Tuesday, July 12th, 2011

I had a bunch of jpegs:


and I want to quickly rename them to


I do this with the following small script in bash. Save this in

# USAGE: files
pad=`echo "(l($#+1)/l(10)) + 0.5" | bc -l`
for var in "$@"
  dn=`dirname $var`;
  echo $ext
  echo "mv \"$var\" \"$dn/`printf '%0'$pad'd' $x`.$ext\""
#uncomment next line to enable
#  mv "$var" "$dn/`printf '%0'$pad'd' $x`.$ext"

Then you can rename a bunch of files, like all those in a directory with:

./ path/to/dir/*

can’t artists learn to make art that fits on my computer screen

Tuesday, July 12th, 2011

can't artists learn to make art that fits on my computer screen

Extract full resolution image from PDF using Illustrator and Photoshop

Tuesday, July 12th, 2011

I had the problem that when kinkos scanned my artwork they gave me a PDF. This doesn’t make a whole lot of sense because the scan is a raster image. It’d be much better off in PNG or in many cases JPG. I tried just opening the PDF in Preview or Photoshop and saving as a PNG but when prompted for the resolution I wasn’t sure what to put. What was the resolution of the PDF? And what was the resolution of the embedded image? Then I tried opening the PDF in illustrator, selecting the image and pasting it as raw pixels into a new photoshop document. This didn’t work either since the image was embedded into the PDF in a scaled form so the copied image was too small. My final solution is as follows:

In illustrator

  1. Select the image object
  2. Open View > Document Info > Embedded Objects
  3. Record the size of the image
  4. Copy the selected image

In Photoshop

  1. Create a new document (this will be the correct dimensions of the copied object, but perhaps the wrong resolution)
  2. Paste the object, but as a Smart Object
  3. Choose Image > Image size…
  4. Enter the size of the image, previously recorded
  5. Choose Layer > Flatten Image

Update: As suggested in the comments it’s much easier to use pdfimages to extract embedded images. I made a follow up post which does this then uses imagemagick’s mogrify to convert the files to pngs.

Update: Also, (see the comments), this is not even the easiest way to a get a single image from a pdf into photoshop.

Bounded Biharmonic Weights: 2D MATLAB Demo

Monday, July 11th, 2011

woody matlab bbw demo I’ve finally released the matlab prototyping codebase for Bounded Biharmonic Weights. The code base runs without any prerequisite libraries on MATLAB 2011a or greater. With earlier versions of matlab, users should install MOSEK (which is available for free to academic users). This matlab package demos computing skinning weights automatically for a 2d shape. To start, add bbw_demo/ to your matlab path and issue:

>> bbw_demo

If you just want to start digging around in the weight computation code, look at:

  • boundary_conditions.m
  • biharmonic_bounded.m

Currently the bbw_demo.m file just shows basic weight computation and linear blend skinning deformation for point handles. The following features are supported in the codebase above, but are undocumented besides their file header comments:

  • Bone handles
  • Cage edges
  • Dual quaternion skinning
  • Automatic rotations at point handles via pseudo-edges
  • 3D weight computation over tetrahedral meshes
  • 2D/3D remeshing along bones and cage edges
  • …and more

The following things are not supported and probably never will be in the MATLAB demo. If I release the C++ demo then of course they will be available:

  • 3D interactive deformation
  • 2D texture mapping

contact me if you find any bugs or have any trouble using the code.

Update: Here’s a new C++ demo

Mac os X Screencapture loop, bash script

Monday, July 11th, 2011

Here’s a simple bash script that grabs screen captures at a specified interval and saves them to files:

# ./screencapture_loop delay_in_seconds file_name_prefix
while :
  screencapture -C -m $2-`printf "%03d" $x`.png
  x=$(( $x + 1 ));
  sleep $1