Radians
I never used to understand radians. Sure, I knew how to use them in typical math problems, but splitting a circle into 2π units? Who divides a circle into six point something parts? You’ve got a useless little slice left over.
Well, remember the formula to find the circumference, C, of a circle? It’s C = πd, where d is the diameter of the circle. The diameter is simply twice the radius r, so you can also define the circumference as C = 2πr.
Consider a circle whose radius is one (the unit circle). Its circumference is simply 2π:
The circumference of a circle is the the distance around its edge. If you don’t go all the way around the unit circle, the length of the arc you do traverse should be less than 2π, right? It might be ¼π, ½π or plain old π if you only go an eighth, a quarter, or a half way around the circle.
Look at the wedges created by arcs with these lengths: they describe 45, 90 and 180 degree angles. The radian equivalents of these angles are ¼π, ½π, and π.
That’s it. A radian angle measurement is the length of the biggest arc that will fit in unit pacman’s mouth!
Their close connection with the basic geometry of circles makes radians convenient for a variety of purposes. But don’t worry, degrees are cool, too: 360, that’s what, almost as many days as there are in a year? Close enough for pagan ceremonies and government work!
Posted on Thursday, February 28th, 2008.
Pascal’s Triangle
Recently I was introduced (or perhaps reintroduced) to Pascal’s Triangle, an arrangement of integers that lends itself to a variety of purposes, including binomial expansion. I’ve written a little program to explore this aspect of the idea.
Features
- Interactively adjust the degree of the expansion to see the corresponding triangle.
- Change the binomial terms for clarity or convenience.
- Show exponents of the first and zeroth power to illustrate that the total degree of each term matches the degree of the initial expression.
- Show plus symbols in the triangle to emphasize how each row is the basis for the next.
- Mouse-over highlight of corresponding terms in triangle and expansion.
- Binomial expansions to any degree can be computed (although the triangle is only displayed for small values due to limitations of the current layout spacing).
- Click and drag in triangle to scroll or drag divider to adjust size of expansion pane.
Screenshots
Download
- Mac OS X: pt.app.zip 2.5M
- Windows: pt.exe.zip 1.3M
- Other: pt.tcl.zip 2.3K or pt.kit.zip 2.8K; requires Tcl/Tk 8.5 or a corresponding Tclkit, respectively. The Mac OS X and Windows versions are self-contained (and hundreds of times larger, unfortunately).
Posted on Monday, February 25th, 2008.
The Trammel Method
A trammel is an impediment to freedom or motion. By placing some geometric restrictions on the motion of a pen or pencil, specific types of figures can be drawn. The trammel method is one of many ways to apply this principle to the construction of ellipses (circles and ovals). It’s particularly handy if you need to draw a large curve without a compass.
Draw a pair of perpendicular lines where you’d like to place an ellipse. I’ve labeled them as major (long) and minor (short) axes.
On a piece of scrap paper, mark the length of a minor radius. (Place the corner of the scrap paper at one end of the minor axis and mark where the axes cross.)
Then mark the length of half the major axis from the same corner.
Now slide the minor mark along the major axis and the major mark along the minor axis. (The marks on the scrap paper ride the opposite rails.) Make a dot at the corner of the scrap paper at any position that satisfies these conditions.
Since the marks on the scrap paper can’t leave their rails, you’ll draw a dot right at the tip of an axis whenever the corresponding mark passes through the intersection of axes.
Mark dots in each quadrant of the ellipse.
See where this is leading? The major mark is still sliding along the minor axis and the minor mark is still sliding along the major axis.
Eventually, you’ll have a series of dots describing the perimeter of the ellipse you planned. The more dots you plot, the smoother the outline.
All that’s left to do is connect the dots.
A circle is a special sort of ellipse in which the major and minor axes are simply the same length. In this example, I’ve just drawn one diameter since only one mark is really needed. (Both marks would fall at the same point, technically, anchoring the card to the center of the circle.)
This technique is often attributed to Archimedes, mover of worlds. (With a long enough lever, and a place to stand…)
Posted on Saturday, February 2nd, 2008.
Hacking Leopard Help
Update: A better way to improve the help viewer’s usability is documented here.
Mac OS X 10.5’s help viewer application is widely considered to be a piece of crap. Unlike the help viewer in previous iterations of Mac OS X, it presents no Dock icon, no proper menu bar, and exhibits an annoying tendency to obscure the application you needed help with in the first place.
So, fix it. Or at least have your vengeance by grossly disfiguring it.
Navigate to /System/Library/CoreServices
. Copy Help Viewer.app
to the Desktop, right-click the copy, and select Show Package Contents
.
Open the Contents
folder and open Info.plist
. Change the value of the LSUIElement
property to 0
:
This makes the application’s Dock icon and menu bar visible. There are definitely some quirks (keyboard shortcuts don’t seem to work as expected), but it works.
Next open the Resources
folder and the appropriate subfolder for your localization (English.lproj
in my case). Open HelpWindow.nib
with Interface Builder and select the HelpWindow
item:
Display the Inspector (from the Tools menu) if it is not already visible and display the Attributes pane. Uncheck Utility
and Non Activating
under Panel Style:
This makes the help window look and behave a bit more like a regular window. Unfortunately, I can’t figure out how to prevent it from floating above other windows (perhaps that behavior is not controlled by the nib file). However, if you check Hide On Deactivate
under Window Behavior in the same Inspector pane, the help window will at least sweep itself out of the way when you bring a different application to the front.
Clicking the help viewer’s Dock icon makes the window visible again, but also creates a new help window.
To apply your changes, save and close HelpWindow.nib
and drag your copy of Help Viewer.app
back to /System/Library/CoreServices
. You’ll need to authenticate the copy operation since you really shouldn’t be diddling around in this directory. (You did make a back up, didn’t you? Good. Neither did I.)
You can test your modified copy of Help Viewer before copying it back to CoreServices, of course, but it won’t handle requests from the Help menu until you do.
Now when you seek help, Help Viewer will actually show up in the Dock. You’ll have menus, and you can even open multiple help windows. Unfortunately, the program launches in the background, so you’ll still have to switch applications with Command-Tab or click the Dock icon to view the requested documentation.
Please share any corrections, clarifications, or further contributions to the cause! I’m no Cocoa or Interface Builder expert. Most importantly, minimize the need for constant help consultation by thinking carefully about the use and design of your application. Put reference material in a nice PDF and call it a day.
Posted on Wednesday, January 30th, 2008.
Msgcat and Mac OS X
The Tcl core library includes msgcat
, a package which facilities program localization. msgcat
provides means to define a catalog of messages in multiple languages and a procedure to retrieve messages appropriate to a specific locale, typically determined by cues from the operating system.
In general, to localize puts "Hello, world!"
, you provide equivalent strings for each supported locale and select the appropriate one at runtime by stating puts [mc "Hello, world!"]
. For example, this command might print ¡Hola, mundo!
if the locale is es
. Default strings in the programmer’s native language can usually be used as keys to the message catalog.
Anyway, msgcat
looks at a couple environment variables (or the Windows registry) to determine the proper locale. On Mac OS X, this works fine for scripts launched from the command line, but spiffy desktop applications don’t necessarily have access to the same environment variables. If no supported environment variables are available, msgcat
uses the locale implied by the “Region” setting of the “Formats” pane of Mac OS X’s “International” system preferences. You can query this string from the command line with:
defaults read 'Apple Global Domain' AppleLocale
It is also available from within Tcl as the variable ::tcl::mac::locale
.
To test localized Tcl desktop applications on Mac OS X without changing your system region, you can define the locale in ~/.MacOSX/environment.plist
. Environment variables specified in this file are available to programs launched from the Finder, so msgcat
will see these settings before resorting to the system locale. For instance, to set the locale to es
, add this property to environment.plist
:
<key>LANG</key>
<string>es</string>
See QA1067 for more information about environment.plist
, including how to create it if it does not already exist. Note that variables defined in this file will be visible to all programs, and may therefore affect other applications.
Here’s how I usually comment the code I use to initialize msgcat
:
# localization courtesy of Message Cat:
#
# |\ /|
# | \______/ |
# / _ _ \
# | <l> <l> |
# \ __ /
# ----- \/ -----
# --\__/\__/--
#
Posted on Tuesday, January 29th, 2008.
Workspaces
Amar Sagoo (author of Namely) finds that a tabletop whiteboard is a useful tool for planning and discussion:
We’ve found ourselves using it virtually every day, illustrating explanations, walking through calculations and brainstorming design ideas. Visitors will intuitively pick up a pen and start using the whiteboard when explaining things. It somehow seems to invite people to use it more than most whiteboards. However, it’s not only a collaborative tool: it also makes a great scratch-pad when you’re brainstorming on your own. To ensure that it stays useful, we make an effort to keep the board clean; nothing tends to stay on there for longer than a day or so.
I’ve got a large roll of packing paper which I use for a similar purpose at my desk. It’s great to be able to jot down a note or a doodle without pausing to search for paper or an appropriate notebook. As the sheet fills up, I pull it down to reveal a clean area. I’ve yet to devise an effective spool, but the scroll nevertheless contains an interesting record of spontaneous notes and drawings.
Now that I’m studying mechanical drawing, I’ve developed an interest in drafting equipment and techniques. Perhaps in the future my desk will receive further augmentation. In the meantime, a fine set of parallel rules can be made from surplus LEGO:
Lastly, I’ve fiddled with some of my shelving to make a nice standing work area for my laptop:
It may not be the best arrangement for long sessions, but I’ve found it surprisingly practical for many tasks. I think that standing up helps me to stay focused. When my mind wanders (as it is wont to do) it is easier to step back and tend to other things than when seated.
The kitchen table is a good place to get things done, too.
Posted on Tuesday, January 29th, 2008.
Yojimbo Tag Companions
I use this little script when I want to ensure that every Yojimbo item with a certain tag also has some other tags. For instance, to ensure that every leoben
item is also tagged cylon
, I run the script, select leoben
from the first list of tags that appears, and cylon
from the second list.
Posted on Thursday, January 17th, 2008.
An Introduction to News Feeds
Most web sites are updated from time to time. News feeds are supplementary files (in RSS or Atom format) that provide a summary or an alternative source of recent additions to such sites. These feeds are read by programs (or web-based services) known as feed readers, which provide people with an overview of what’s new at their favorite sites.
Popular feed readers include NetNewsWire and Google Reader. I use Vienna. Current browsers can display feeds, too.
Web sites that offer news feeds are usually identified by an icon in the browser tool bar. Safari displays a blue “RSS” badge when it detects an available feed; Firefox and other browsers show an orange logo. Alternatively, a link or button within the web page, labeled “RSS/Atom,” “XML,” or “feed,” may indicate that a news feed is available. In any case, clicking the icon or link will establish a subscription to that feed.
Your feed reader will periodically check to see if any of your subscriptions have been updated. If so, it will retrieve information about the new content — often including the new content itself — and display each new item in a list resembling an email inbox.
You can read new posts right in the news reader or follow a link to read them in context at the original web site. Since some news feeds provide only the title of new articles, you must visit the associated page to read the actual content in these cases.
Different feed readers provide different ways to manage your subscriptions. There are some common features, however. You can group related subscriptions, and you can save or discard items you’ve read — otherwise, they may eventually expire.
Feed readers are sometimes called news aggregators because they collect information from many sources in one convenient location. I find this service useful because it helps prevent me from wasting time online: instead of surfing from site to site and back again, I simply subscribe to sites I find interesting. It’s like receiving a newspaper instead of spending all day gathering news myself. It also helps me to keep an eye on sites I might otherwise forget to check.
Posted on Wednesday, January 16th, 2008.
Computing Power
The current Mac Pro is available with eight 3.2 GHz 64-bit cores, 32 GB of RAM, terabytes of storage, and support for up to eight 30-inch displays (eight 30-inch displays!), all in a practical form factor that runs certified UNIX.
Sure puts some of the rack-mount monstrosities I’ve met in perspective.
Anyway, perhaps you’d rather meet my calculators.
Posted on Tuesday, January 8th, 2008.
File Comparison with FileMerge
Wherein I explain the anatomy of a FileMerge window
FileMerge is a visual diff utility included with the developer tools that ship with Mac OS X. As its name suggests, it is intended to help compare and resolve differences between files. It is particularly useful for quickly and clearly reviewing changes between different revisions of a single file under version control.
You can choose which files to compare with a dialog
or via the opendiff
command:
opendiff original new
For this example, I will compare the contrived sample files used in Wikipedia’s diff article. In either use case, the files are displayed side-by-side with differences highlighted:
Blue highlights indicate changes. The regions where these changes occurred in each file are connected by gray highlights.
Scrolling is synchronized to show most unchanged areas together; as you scroll, each pane moves at variable speed to maintain this visual correspondence between reference points. It’s nice.
The relative location of each change in the file is indicated by a tick mark in the scroll bar. For long files, these marks act like a simple histogram to summarize the distribution of changes throughout the file.
A dark border surrounds the currently selected difference (number 2, in this example). The up or down arrows move the selection to the previous or next difference.
The left and right arrows keys can be used to select which version of the current region of change should take precedence if you save a merged version of the files. In this example, and by default, the arrows in the center column indicate that the file on the right always takes precedence.
The separator near the bottom of the window can be dragged up to reveal a preview of the merged file. The Actions menu offers additional ways to merge the selected change.
FileMerge can preprocess a file if a command line filter is assigned to the file’s extension. This can be used to compare dynamically-generated text representations of binary files.
Update: The new application Changes performs a similar function with the advantage of Unicode support. Might be especially useful for revising localized files like message catalogs.
Posted on Tuesday, January 1st, 2008.