Alex Beutel's Blog

Ubiquity Scripts

July 30th, 2009 · No Comments

After playing with the Jetpack API and having an increasing desire to procrastinate my Spanish homework, I decided to give the Ubiquity API a shot too and make a few small scripts just to make my life easier.  The first extension I made was a script to do look ups of IP addresses and get more information about them.  This is useful mainly if you are looking at raw logs from a web server.  After realizing how easy it was to make these scripts, I made two more for bit.ly links which I frequently come across on Twitter.  The first can get more info and stats about a link (the number of clicks) and easily send you to the bit.ly info page for that link.  The second script can be used to quickly expand the links from their compressed bit.ly form to their original form.  I know there are other scripts that can do this across an entire page, but felt I’d rather keep short links with a quick and easy way to find out what the link contains.  If any of these sound interesting/useful or if you just want to see some simple examples of how to code Ubiquity extensions, you can check the scripts out here.  I have also included screenshots for each of these scripts below.

→ No CommentsTags: Javascript · Twitter

Image Aliasing of Plane Propellers in Photos and Video

July 23rd, 2009 · 13 Comments

Recently, while flying between Durham and New York, I decided to take a picture of the propeller during take off.  I don’t know what prompted to me to do this, but when I pointed my iPhone camera at the propeller out my window I noticed very odd pattens.  I took multiple pictures throughout the flight with my iPhone, and in some cases at the same time took pictures/video with my Canon camera.  To clarify the specs of the two cameras: I have an iPhone 3G (8 GB) and a Canon SD700 IS.  As you will see in the pictures below, the iPhone’s picture simply makes no sense with the blades appearing to be disconnected vertical lines.  The photo from the Canon seems reasonable, but as you will see in the video the propeller appears to be going fairly slowly, when in real life all I could see was a blur because of how fast it was moving.

Plane Propeller Photo from iPhone 3G

Plane Propeller Photo from iPhone 3G

Canon SD700 IS Plane Propeller Photo

Canon SD700 IS Plane Propeller Photo

Update: here is a video taken from my iPhone 3G of the propeller.
This got me thinking about why the images looked the way they did. I assumed they were related to frame rate and as a result wondered if I could work backwards to find the speed of the propeller. When I got back to Duke, I talked it over with some of my friends. We discussed one theory that explained the slow spinning in the video from my Canon. I later found out is similar to the Wagon-wheel effect, and will go into more detail on this later. We also discussed possible distortions and other possible causes but couldn’t figure out exactly what was causing the odd pattern in the iPhone photo. Eventually, I decided to search around the internet and found that I was not the only one to notice this oddity. I also stumbled upon this great post explaining clearly and graphically why the iPhone photo looks the way it does. In short, most cameras save pixels from all parts of the lens at once, while the iPhone camera goes through the lens saving pixels linearly over time, similar to watching a scanner save the page of a book. (If anyone has an iPhone 3GS and can snap a picture and/or video of a propeller, please let me know. I’m very intrested to see if Apple’s upgraded camera still behaves this way. Please let me know if you find out.) The writer of the post also demonstrated this in a cool video made from a Matlab script:
Personally, I think this is really cool so I decided to play around with it some more. As I mentioned earlier, my friends and I had discussed the wagon-wheel effect or the stroboscopic effect, so I thought I’d modify his script to demonstrate it more clearly since the Wikipedia pages on the two topics both seemed a bit lacking. First, it is necessary to explain the general concept. The stroboscopic effect explains if you only see flashes or quick individual frames of a moving object at regular intervals you can get a distorted view of the motion, especially if the motion of the object that is being watched is cyclic or has a frequency. The relationship between the frequency of the flashes or frames and the frequency of the motion is what determines the perceived motion. The most common case of this is seeing a wheel which you know to be rolling forward, but it looks to be spinning backwards slowly. I modified the previous Matlab code to create a basic example of this with the propeller (download the code here). As you will see, the propeller on the left will spin counterclockwise at a moderate speed and every 8 frames the image on the right will update with a copy of the image on the left. This out of sync updating will make the propeller on the right appear to rotate clockwise.
Click the image to view the video

Click the image to view the video

I also decided to show this more mathematically by plotting these movements in Mathematica. In the following examples I graph both the y-coordinate of the tip of the propeller and the angle that the blade has rotated in radians. In the graph of y the coordinate, there are three sinusoidal functions representing 3 propellers, each offset from the previous by 120 degrees (thus equally spaced). These lines and their colors correspond to the colored lines on the radian vs. time graph. The red lines mark a flash or frame and the dot on the line shows the top-most propeller. As you vary the spacing of the lines and thus change the frame rate, you can see the propeller will appear to stay still, then go backwards, then flip back and forth with no perceived motion, then go forwards, until it appears to stand still again. Below are pictures showing each of these stages, followed by a video fluidly showing these variations.
Here is the propeller appearing to stand still. This is due to the fact that the spacing of the frames is twice the period.

The graphs below show the propeller appearing to go backwards. Here we see that the frame rate is just below two periods of the propeller. The downward slope on the radian graph is a simple quick way to see the direction of the propeller rotation.

Propeller appearing to flip repeatedly:

This example shows the propeller appearing to rotate forwards. Again, the upwards slope of the points on the radian graph is an easy way to see the direction of rotation.

Last, here is the propeller appearing to stand still again. Unlike the first case of the propeller standing still, the spacing of the frames is not a multiple of the period. Rather, we see here that it is a multiple of 1/3 the period. It is only necessary that the spacing be a multiple of 1/3 the period because there are three blades and the blades are indistinguishable.

And finally, putting it all together:

The Mathematica code can be viewed here or downloaded here, and a printout of the entire Mathematica worksheet can be found here. Last, if one had a camera which could vary the frame rate just so slightly as to find two nearest frame rates to show the propeller standing still, the frequency of the propeller could be calculated as shown below.

As for the iPhone picture, a single image (and knowing the number of blades) is enough to roughly approximate the speed of the propeller as shown below.

However, just as a warning both of these are back of the envelope calculations and it is very possible I made a mistake (if so please let me know). That is all for now. Nothing ground breaking, but as the title suggests, it was a good chance for some mental masturbation, playing with Mathematica and Matlab.

→ 13 CommentsTags: iPhone · Math · Miscellanious

Duke LDAP on the iPhone

July 19th, 2009 · No Comments

I got an e-mail this morning from someone who saw my post on Twitter about using LDAP on the iPhone here at Duke.  The person said they followed the tutorial but couldn’t quite get it to work.  So I figured it may be useful to post a few quick instructions on setting it up.  As the post on Twitter explains, the basic instructions for getting to adding an LDAP account can be viewed here and Duke’s LDAP server settings can be found here.  Once you are set to add the LDAP account, simply set the server to ldap.duke.edu, no need for a username or password.  Once you click next you will want to turn off SSL and change the Search settings for duke,edu to have a base value of “ou=People,dc=duke,dc=edu” (leave the scope at subtree).  And that’s it.  To use it, which turned out to be the issue for the person emailing me, go to write a new email and start to type in the name of the person to search.  You should see a throbber show up at the top of your screen, showing that it is connecting to the server.  There is a bit of a lag but it should eventually return the contacts for people by that name.  Below are some pictures of the settings and the search.  Let me know if you run into any issues.

→ No CommentsTags: Duke · iPhone · Miscellanious

Google Reader vs. Netvibes, and Jetpack Notifications

July 18th, 2009 · No Comments

A couple of weeks ago I decided to give Google Reader a try.  I have been addicted to Netvibes for at least 2-3 years now, but I saw that Reader had a more active community around it, so I thought it was worth trying out.  Almost immediately I disliked the look and feel.  I am subscribed to over thirty fairly active RSS feeds and  in Reader it was hard to see which blogs had new posts.  The default action is to just look at a long list and viewing posts by blog is almost hard to do.  As a result “Mark[ing] all as read” for a specific blog takes many more scrolls and clicks, which had been extremely easy in Netvibes.   About this time I was giving Mozilla’s Jetpack a try and found the Google Reader Notifier, which would notify me via Growl of new posts.  So I decided to give Reader a longer try, despite some initial disappointments.

Ultimately, I became addicted to these near instant updates for new blog posts that the Jetpack extension provided.  At the same time I learned to love the fact that by default I was forced to read the title for every blog post in Reader.  Where as before in Netvibes I would never scroll through the backed up posts from Gizmodo and Engadget, Reader’s chronological ordering makes me go through each post.  Recently, this is just another case where what I think I want does not match up with what actual creates a better user experience (similar to Google’s analysis of users searching more with 10 results despite asking for as many as possible or  Dan Curtis’s explanation that we are not in control of our deicions).  Also, this reminds me of Aza Raskin‘s statement “Every time you make the user make a decision they don’t care about, you have failed as a designer.”  Interestingly, Google forced me to make a harder decision than I wanted to make; where before I could avoid deciding whether or not to remove the blog by just leaving it on my page and just easily clicking away new posts with “Marking all as read,” I now had to decide to either read the post titles or make the leap to get ride of the RSS feed all together.  While I was able to be lazy before, it made for a more concrete decision and user experience.

The other thing I realized was that the Jetpack extension for Reader notifications was causing my browser to hang when I had a bad internet connection.  Sadly, living in an off campus apartment with spotty Internet this happens all too often, and I decided to disable Jetpack.  However, I missed the notifications and decided to fix the Jetpack extension.  I reworked the old extension to only perform asynchronous AJAX calls, getting rid of the browser hanging issue, and modified the extension to display notifications to show new posts by blog title, thus making the notifications more informative.  The status bar display and the new Growl notifications can be seen below.  Click here to install this extension or here to view the code.  Of course, let me know your thoughts or any bugs you run into.  Thanks.

Also, as some friends like Niru, DJ, and Marc have pointed out, I have somewhat decreased my blogging but have been posting a good number of posts on Twitter.  So of course, you should follow me on Twitter here.


→ No CommentsTags: Javascript · Jetpack · Musings · Web Development

Following Chromium Progress

June 4th, 2009 · No Comments

For the past few months I have been following the progress of Chromium for Mac and watching it develop and it has definitely made a lot of progress in that time. In the past few month it has received increasing press, with people asking why it is taking so long. One of the lead developers on the project responded that people need to chill out and that building a browser takes time.  So, in part to show myself and others the progress, I decided to make a little application to show this progress.  Throughout the day builds and updates of Chromium are posted to http://build.chromium.org/buildbot/snapshots/sub-rel-mac/ but to read each changelog was a pain. So, to give myself more exposure to new Python libraries and give the Twitter API a swing, I created a script to check for changes to the builds, pull log entries on the changes and post them all to a Twitter stream so there is a single source you can view updates. The script is far from perfect, as it has to be running to catch the updates and doesn’t go back and look for ones it missed. And currently I just have it running on one of Duke’s servers so it goes down occasionally. But it generally works and provides plenty of updates so you can see what is actually be worked on and updated. Check out the source code below (twitter username and password cut out).

?Download chromium.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python
# encoding: utf-8
 
import sys
import os
import urllib
import urllib2
import base64
import time
from xml.dom import minidom
 
def twitter(twitter_username, twitter_password, message):
	request = urllib2.Request('http://twitter.com/statuses/update.json')
	request.headers['Authorization'] = 'Basic %s' % ( base64.b64encode(twitter_username + ':' + twitter_password),)
	request.data = urllib.urlencode({'status': message})
	try:
		response = urllib2.urlopen(request) # The Response
	except HTTPError, e:
		print "Error posting to twitter"
		print "HTTP Error code: ", e.code
	except URLError, e:
		print "Error posting to twitter"
		print "URLError reason: ", e.reason
 
def main():
	message = ""
	last_update = "17514";
	chromium_url = "http://build.chromium.org/buildbot/snapshots/sub-rel-mac/"
	while(True):
		try:
			response = urllib2.urlopen(chromium_url + "LATEST")
		except HTTPError, e:
			print "HTTP Error code: ", e.code
		except URLError, e:
			print "URLError reason: ", e.reason
		else:
			latest = response.read()
			print "latest: ", latest
			if(latest != last_update):
				try:
					response2 = urllib2.urlopen(chromium_url + latest + "/changelog.xml")
				except HTTPError, e:
					print "HTTP Error code: ", e.code
				except URLError, e:
					print "URLError reason: ", e.reason
				else:
					html = response2.read()
					# print html
					dom = minidom.parseString(html)
					entries = dom.getElementsByTagName("logentry") #[0].childNodes
					print "entries: ", len(entries)
					for i in range(0, len(entries)):
						link = chromium_url + latest + "/ "
						msg = entries[i].getElementsByTagName("msg")[0].firstChild.nodeValue
						num = entries[i].getAttribute("revision")
						print "Revision: ", num
						twitter("USERNAME", "PASSWORD", "Chromium Revision " + num + ": " + msg)
					last_update = latest
			time.sleep((60*2))
 
 
if __name__ == '__main__':
	main()

Play with the code or follow the twitter. Also, I decided to try a new WordPress plugin for code so let me know what you think. Thanks.

→ No CommentsTags: Chromium · Programming · Python · Twitter