<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"><channel><atom:link rel="hub" href="http://tumblr.superfeedr.com/" xmlns:atom="http://www.w3.org/2005/Atom"/><description>Student, Mac, Web, iPhone Developer</description><title>Matt Rajca</title><generator>Tumblr (3.0; @mattrajca)</generator><link>http://mattrajca.com/</link><item><title>Quickly Changing Your Mac's Startup Volume with Alfred</title><description>&lt;p&gt;As I work on projects in Snow Leopard, Lion and Windows, I constantly find myself switching my Mac&amp;#8217;s startup volume and rebooting. Utilities such as &lt;a href="http://buttered-cat.com/products/QuickBoot"&gt;QuickBoot&lt;/a&gt; can streamline this process, though they&amp;#8217;re not very accessible and often take up precious space in the menu bar. Why not leverage a keyboard-friendly launcher like &lt;a href="http://www.alfredapp.com"&gt;Alfred&lt;/a&gt; instead?&lt;/p&gt;

&lt;p&gt;Creating an Alfred extension that will change your Mac&amp;#8217;s startup volume and reboot the machine is trivial:&lt;/p&gt;

&lt;p&gt;First, open Alfred&amp;#8217;s Preferences and switch to the Extensions tab. Under &amp;#8220;Add an Extension to Alfred&amp;#8221;, select AppleScript. Enter a name for your extension (for example: &amp;#8220;Reboot into Lion&amp;#8221;), and press &amp;#8220;Create&amp;#8221;. Next, give your extension a title (which will appear in Alfred&amp;#8217;s search results), as well as a keyword like &amp;#8220;reboot&amp;#8221;.&lt;/p&gt;

&lt;p&gt;In the &amp;#8220;AppleScript&amp;#8221; text view, paste in the following script:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;on alfred_script(q)
    do shell script "bless -mount /Volumes/VOLUME_NAME/ -setBoot -nextonly" with administrator privileges
    tell application "Finder" to restart
end alfred_script
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Be sure to replace &lt;code&gt;VOLUME_NAME&lt;/code&gt; with the name of the volume you wish to reboot into (as shown in the Finder). If the volume is a Boot Camp partition, include the &lt;code&gt;-legacy&lt;/code&gt; flag as an argument to the &lt;code&gt;bless&lt;/code&gt; command. Finally, hit &amp;#8220;Save&amp;#8221; to save your new extension. Ideally, create one such extension for each volume you want to have quick access to.&lt;/p&gt;

&lt;p&gt;&lt;img src="http://farm8.staticflickr.com/7220/7162311628_2b7f60d840_b.jpg" alt="Alfred Extension"/&gt;&lt;/p&gt;

&lt;p&gt;Toggling Alfred and typing &amp;#8220;reboot&amp;#8221; will now show our extension(s) among the search results. Invoking the extension(s) will prompt you for your password and reboot your Mac into the desired volume.&lt;/p&gt;</description><link>http://mattrajca.com/post/22697427205</link><guid>http://mattrajca.com/post/22697427205</guid><pubDate>Thu, 10 May 2012 20:05:48 -0500</pubDate><category>alfred</category><category>scripting</category><category>automator</category><category>disk</category></item><item><title>Subtle Patterns Safari Extension</title><description>&lt;p&gt;I just released a Safari Extension that lets web designers preview any of the first 200&amp;#160;&lt;a href="http://subtlepatterns.com"&gt;Subtle Patterns&lt;/a&gt; as they would appear tiled across their websites&amp;#8217; background. Visit the GitHub project &lt;a href="https://github.com/mattrajca/Safari-Extensions/tree/master/SubtlePatterns"&gt;page&lt;/a&gt; to download it today!&lt;/p&gt;

&lt;p&gt;&lt;img src="http://dl.dropbox.com/u/321814/images/SubtlePatterns.png" alt="Subtle Patterns Extension Screenshot"/&gt;&lt;/p&gt;</description><link>http://mattrajca.com/post/20353364027</link><guid>http://mattrajca.com/post/20353364027</guid><pubDate>Mon, 02 Apr 2012 11:32:24 -0500</pubDate><category>subtle patterns</category><category>safari</category><category>extension</category><category>web</category></item><item><title>Batch Applying Rounded Corners to Images with Automator</title><description>&lt;p&gt;For the past few years, I have used &lt;a href="http://www.acqualia.com/picturesque/"&gt;Picturesque&lt;/a&gt; whenever I needed to apply rounded corners to batches of images for one of my web design clients. Picturesque did the job, but its lack of Automator support started getting to me. I had to resort to the &amp;#8216;Watch Me Do&amp;#8217; action just to apply a preset to an image in a larger image processing workflow.&lt;/p&gt;

&lt;p&gt;So recently, I took a day to write a &amp;#8216;Round Images&amp;#8217; Automator action. Given a set corner radius, border width, and border color, the action rounds any or all of the four corners of the images passed into it, as shown below.&lt;/p&gt;

&lt;p&gt;&lt;img src="http://farm8.staticflickr.com/7186/6866737621_34b5dcc11f_z.jpg" alt="Round Images Action"/&gt;&lt;/p&gt;

&lt;p&gt;The &amp;#8216;Round Images&amp;#8217; action is freely available on &lt;a href="https://github.com/mattrajca/Automator-actions/downloads"&gt;GitHub&lt;/a&gt;, so check it out if you think it will be useful in your workflow.&lt;/p&gt;</description><link>http://mattrajca.com/post/17533842651</link><guid>http://mattrajca.com/post/17533842651</guid><pubDate>Sun, 12 Feb 2012 22:17:09 -0600</pubDate><category>automator</category><category>image processing</category><category>workflow</category><category>rounded corners</category></item><item><title>Auto-Ejecting Disc Image Files Dragged to the Trash</title><description>&lt;p&gt;Even with the growth of the Mac App Store, I still find myself constantly downloading, mounting, and eventually trashing DMGs. Almost just as frequently, I am greeted with the following dialog whenever I try to empty the Trash with mounted disc image files inside it:&lt;/p&gt;

&lt;p&gt;&lt;img src="http://farm7.static.flickr.com/6203/6114554773_7b7111aa5b_z.jpg" alt="Disc Image in Trash"/&gt;&lt;/p&gt;

&lt;p&gt;Fortunately for us, we can overcome this annoyance by creating a Folder Action in &lt;a href="http://en.wikipedia.org/wiki/Automator_(software)"&gt;Automator&lt;/a&gt;. Folder Actions run whenever the contents of a specified directory change – in this case, the current user&amp;#8217;s Trash. Any mounted disc image files found inside the Trash will get ejected automatically by our Folder Action.&lt;/p&gt;

&lt;ol&gt;&lt;li&gt;Open Automator, which can be found inside the &lt;code&gt;Applications&lt;/code&gt; directory.&lt;/li&gt;
&lt;li&gt;Create a new document and select &amp;#8216;Folder Action&amp;#8217; from the template chooser.&lt;/li&gt;
&lt;li&gt;Click on the &amp;#8216;Choose folder&amp;#8217; pop-up button and select &amp;#8216;Other…&amp;#8221; from the menu that appears.&lt;/li&gt;
&lt;li&gt;When the &amp;#8216;open&amp;#8217; panel comes up, hit &lt;em&gt;Shift+⌘+G&lt;/em&gt; and enter &lt;code&gt;~/.Trash&lt;/code&gt; in the location field; click &amp;#8216;Go&amp;#8217;, followed by &amp;#8216;Choose&amp;#8217;.&lt;/li&gt;
&lt;li&gt;Drag a new instance of the &amp;#8216;Run Shell Script&amp;#8217; action (listed under the Utilities group) from the Library into your workflow.&lt;/li&gt;
&lt;li&gt;Set the action&amp;#8217;s shell to &lt;code&gt;/usr/bin/python&lt;/code&gt; and its input type to &amp;#8216;as arguments&amp;#8217;.&lt;/li&gt;
&lt;li&gt;Finally, replace the contents of the placeholder script with the one listed below.&lt;/li&gt;
&lt;/ol&gt;&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;import string, os, sys

lines = os.popen("hdiutil info").readlines()
should_eject = False

for line in lines:
    if line.startswith("image-alias"):
        path = line.split(":")[1]
        image_path = path.lstrip().rstrip()

        if image_path in sys.argv:
            should_eject = True

    elif line.startswith("/dev/") and should_eject is True:
        os.popen("hdiutil eject %s" % line.split()[0])
        should_eject = False

    elif line.startswith("###"):
        should_eject = False
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;br/&gt;&lt;/p&gt;

&lt;p&gt;After your new Folder Action is saved, any mounted disc image files dragged to the Trash will get ejected automatically.&lt;/p&gt;</description><link>http://mattrajca.com/post/9821989578</link><guid>http://mattrajca.com/post/9821989578</guid><pubDate>Mon, 05 Sep 2011 13:48:46 -0500</pubDate><category>automator</category><category>python</category><category>scripting</category></item><item><title>Kinect Support for Extreme Tux Racer</title><description>&lt;p&gt;Recently, I took a short break from my long-term projects to play around with the official Kinect for Windows SDK. As a mini side-project, I added Kinect support to a classic open source game, &lt;a href="http://extremetuxracer.com/"&gt;Extreme Tux Racer&lt;/a&gt;. As Tux accelerates down the racetrack, the user can tilt his or her head left or right to steer the penguin, lean forward to paddle, and lean backward to brake. Tux Racer&amp;#8217;s lenient collision detection logic also tends to work in the user&amp;#8217;s favor during gameplay. If you&amp;#8217;re interested in the project, take a look at the source on &lt;a href="https://github.com/mattrajca/extremetuxracer"&gt;github&lt;/a&gt;, or check out this quick and rough &lt;a href="http://www.vimeo.com/27603312"&gt;video&lt;/a&gt; of it in action! Kinect support is only available on Windows at the moment.&lt;/p&gt;</description><link>http://mattrajca.com/post/9683546729</link><guid>http://mattrajca.com/post/9683546729</guid><pubDate>Thu, 01 Sep 2011 18:26:56 -0500</pubDate><category>kinect</category><category>game</category><category>nui</category></item><item><title>LLVM, Code Coverage, and Xcode 4</title><description>&lt;p&gt;The ability to generate code coverage reports has been one of the notable features missing from the LLVM/Clang compiler. As of June 8, 2011, the Clang frontend can finally generate code coverage reports using the same flags that were supported by GCC. At the time of this writing, these flags haven&amp;#8217;t made their way into Xcode&amp;#8217;s build settings UI. I have no doubt they will be integrated into a future release of Xcode, but until that happens, we can always compile our own build of Clang and manually pass in the compiler flags necessary to generate code coverage reports.&lt;/p&gt;

&lt;p&gt;Below are the steps required to check out, compile, and install the tip-of-tree build of LLVM/Clang.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;# check out the source to LLVM
svn co &lt;a href="http://llvm.org/svn/llvm-project/llvm/trunk"&gt;http://llvm.org/svn/llvm-project/llvm/trunk&lt;/a&gt; llvm

# check out the source to Clang
cd llvm/tools
svn co &lt;a href="http://llvm.org/svn/llvm-project/cfe/trunk"&gt;http://llvm.org/svn/llvm-project/cfe/trunk&lt;/a&gt; clang

# configure the project for compilation
cd..
./configure --prefix=/opt --enable-optimized
make -j8           # build with 8 threads
sudo make install  # install to /opt
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;If all goes well, a new binary of the Clang compiler should now reside in &lt;code&gt;/opt/bin/&lt;/code&gt;. Next, we need to tell Xcode to use our newly-built compiler instead of the build it ships with. This should be done for each target you want to generate code coverage reports, or at the project level. In Xcode, open the Build Settings pane of the desired target and choose &amp;#8216;Add Build Setting&amp;#8217; from the bottom toolbar; select &amp;#8216;Add User-Defined Setting&amp;#8217; from the pop-up menu that appears. Enter &lt;code&gt;CC&lt;/code&gt; for the setting name and &lt;code&gt;/opt/bin/clang&lt;/code&gt; as its value. Xcode will now build the target using our custom-built compiler.&lt;/p&gt;

&lt;p&gt;&lt;img src="http://farm7.static.flickr.com/6018/5952710328_f684d5a4c7_b.jpg" alt="Xcode 4 CC Setting"/&gt;&lt;/p&gt;

&lt;p&gt;While we&amp;#8217;re in the Build Settings pane, find the &lt;code&gt;Other C Flags&lt;/code&gt; setting and add &lt;code&gt;-fprofile-arcs&lt;/code&gt; and &lt;code&gt;-ftest-coverage&lt;/code&gt; on to the list. These flags will tell Clang to generate &lt;code&gt;gcov&lt;/code&gt; files for each class in our target.&lt;/p&gt;

&lt;p&gt;Lastly, we have to link against &lt;code&gt;libprofile_rt.a&lt;/code&gt; (instead of &lt;code&gt;libgcov.a&lt;/code&gt;, which was required by GCC). In Xcode 4, switch to your target&amp;#8217;s Build Phases pane and expand the &amp;#8216;Link Binary With Libraries&amp;#8217; section. Click on the &amp;#8216;Plus&amp;#8217; button, choose &amp;#8216;Add Other&amp;#8217;, and navigate to &lt;code&gt;/opt/lib&lt;/code&gt;. Select &lt;code&gt;libprofile_rt.dylib&lt;/code&gt; from the list of files.&lt;/p&gt;

&lt;p&gt;And that&amp;#8217;s it! If you build and run your target, Xcode will now output &lt;code&gt;gcda&lt;/code&gt; and &lt;code&gt;gcov&lt;/code&gt; files to a well-hidden path inside the &lt;code&gt;DerivedData&lt;/code&gt; directory. To find it, right click on your target in Xcode&amp;#8217;s Products group, and select &amp;#8216;Show in Finder&amp;#8217;. Navigate up the path hierarchy to the &lt;code&gt;Build&lt;/code&gt; folder, as shown below.&lt;/p&gt;

&lt;p&gt;&lt;img src="http://farm7.static.flickr.com/6204/6030613078_076c9ab8c7_b.jpg" alt="Target Build Folder"/&gt;&lt;/p&gt;

&lt;p&gt;Finally, open up the &lt;code&gt;Intermediates/$TARGET.build/$CONFIG/$TARGET.build/Objects-normal/$ARCH&lt;/code&gt; subfolder. Inside, you&amp;#8217;ll find the aforementioned &lt;code&gt;gcda&lt;/code&gt; and &lt;code&gt;gcov&lt;/code&gt; files. Since Clang outputs these files in the same format as GCC, they are compatible with tools such as &lt;a href="http://code.google.com/p/coverstory/"&gt;CoverStory&lt;/a&gt;.&lt;/p&gt;</description><link>http://mattrajca.com/post/8749868513</link><guid>http://mattrajca.com/post/8749868513</guid><pubDate>Sun, 14 Aug 2011 20:30:41 -0500</pubDate><category>llvm</category><category>clang</category><category>code coverage</category><category>xcode</category><category>tools</category></item><item><title>Adding Code Completion Support to TextMate Bundles</title><description>&lt;p&gt;Code completion isn&amp;#8217;t a prominent feature in &lt;a href="http://macromates.com/"&gt;TextMate&lt;/a&gt;, but it exists. If you enter some text and hit &amp;#8216;Escape&amp;#8217; repeatedly, TextMate will cycle through any available code completions. Unfortunately, this only works with the Objective-C and PHP bundles, and all functions and methods suggested exclude parameter lists. Compared to the code completion system in Xcode 4, this isn&amp;#8217;t very impressive.&lt;/p&gt;

&lt;p&gt;After searching around, I discovered that the PHP bundle does something clever: if you hit &amp;#8216;Option+Escape&amp;#8217; or select the &amp;#8216;Completions for Word&amp;#8230;&amp;#8217; menu item from the bundle&amp;#8217;s action pop-up, TextMate will present a menu of available code completions.&lt;/p&gt;

&lt;p&gt;&lt;img src="http://s3.amazonaws.com/ember/tHdxjonPkUgKo3N3bvq4DnjUBSLtR0ej_o.png" alt="TextMate code completion"/&gt;&lt;/p&gt;

&lt;p&gt;What&amp;#8217;s more is, once a completion is accepted, the name of the function along with any parameters will be inserted. You can even tab through each parameter, just like in Xcode! After digging around in TextMate&amp;#8217;s Bundle Editor, I was surprised to find that the code to make all of this happen is only 5 lines long:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;#!/usr/bin/env ruby -wKU
require ENV['TM_SUPPORT_PATH'] + '/lib/osx/plist'
require ENV['TM_SUPPORT_PATH'] + '/lib/ui'

choices = OSX::PropertyList.load(File.read(ENV['TM_BUNDLE_SUPPORT'] + '/functions.plist'))
TextMate::UI.complete(choices, :initial_filter =&amp;gt; ENV['TM_CURRENT_WORD'], :extra_chars =&amp;gt; '_')
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;It turns out TextMate has built-in support for this menu-based code completion UI in its &lt;code&gt;ui.rb&lt;/code&gt; support file &amp;#8212; and it works pretty darn well. The completions are stored in the referenced &lt;a href="http://en.wikipedia.org/wiki/Property_list"&gt;plist&lt;/a&gt; file, whose structure is pretty self-explanatory:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&amp;gt;
&amp;lt;plist version="1.0"&amp;gt;
&amp;lt;array&amp;gt;
    &amp;lt;dict&amp;gt;
        &amp;lt;key&amp;gt;display&amp;lt;/key&amp;gt;
        &amp;lt;string&amp;gt;ArrayMin&amp;lt;/string&amp;gt;
        &amp;lt;key&amp;gt;insert&amp;lt;/key&amp;gt;
        &amp;lt;string&amp;gt;(${1:const variant &amp;amp;amp; src[]}, ${2:unsigned int idx}, ${3:unsigned int len})&amp;lt;/string&amp;gt;
    &amp;lt;/dict&amp;gt;
&amp;lt;/array&amp;gt;
&amp;lt;/plist&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The value of the &lt;code&gt;display&lt;/code&gt; key contains the name of the code completion item as it will appear in the list. Additionally, the value of the &lt;code&gt;insert&lt;/code&gt; key contains an ordered list of parameters, which will be inserted whenever a code completion is accepted.&lt;/p&gt;

&lt;p&gt;By leveraging this, I managed to add menu-based code completion support to a NXC bundle I&amp;#8217;m working on, all in a matter of minutes. It&amp;#8217;s a shame that so few TextMate bundles utilize this hidden gem.&lt;/p&gt;</description><link>http://mattrajca.com/post/4736147739</link><guid>http://mattrajca.com/post/4736147739</guid><pubDate>Sat, 09 Jul 2011 21:29:16 -0500</pubDate><category>textmate</category><category>bundles</category></item><item><title>AppKit Quick Tip: Populating the 'Open Recent' Menu in Non-Document-based Applications</title><description>&lt;p&gt;While writing &lt;a href="http://github.com/mattrajca/Nibble"&gt;Nibble&lt;/a&gt;, my native Apple I emulator for Mac OS X and iOS, I realized an &lt;code&gt;Open Recent&lt;/code&gt; menu would be beneficial to users who want to quickly open recently-loaded memory dumps. In standard Document-based applications, AppKit automatically registers newly-opened files as recents. Unfortunately, it doesn&amp;#8217;t make much sense to make an emulator a Document-based application.&lt;/p&gt;

&lt;p&gt;Luckily, even Non-Document-based applications contain an &lt;code&gt;Open Recent&lt;/code&gt; menu, ready to be populated. Moreover, &lt;code&gt;NSDocumentController&lt;/code&gt; makes it extremely easy to register recently-accessed files through its &lt;code&gt;noteNewRecentDocumentURL:&lt;/code&gt; method. AppKit will magically append the file at the passed URL to the &lt;code&gt;Open Recent&lt;/code&gt; menu; it will even enable the &lt;code&gt;Clear Menu&lt;/code&gt; item when necessary! When the user selects a recent file, AppKit will invoke the &lt;code&gt;application:openFile:&lt;/code&gt; method on &lt;code&gt;NSApplication&lt;/code&gt;&amp;#8217;s delegate object.&lt;/p&gt;

&lt;p&gt;The complete code listing can be found below:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;NSDocumentController *dc = [NSDocumentController sharedDocumentController];
[dc noteNewRecentDocumentURL:[NSURL fileURLWithPath:somePath]];


- (BOOL)application:(NSApplication *)sender
           openFile:(NSString *)filename {

    // load the file

    return YES;
}
&lt;/code&gt;&lt;/pre&gt;</description><link>http://mattrajca.com/post/5678833327</link><guid>http://mattrajca.com/post/5678833327</guid><pubDate>Sat, 09 Jul 2011 17:17:59 -0500</pubDate><category>development</category><category>appkit</category><category>nsdocument</category></item><item><title>Enabling VNC on a Mac with a Broken Display</title><description>&lt;p&gt;Around two weeks ago, my iMac&amp;#8217;s display started turning itself off at random times. I thought this was a software bug as I was running the latest beta of Mac OS X, so I ignored the issue. Doing a quick restart always restored everything to normal. A few days later, the display wouldn&amp;#8217;t turn on at all. The Mac would still run and I could hear &lt;a href="http://www.apple.com/accessibility/macosx/vision.html"&gt;Alex&lt;/a&gt; &lt;a href="http://www.apple.com/pro/tips/text_speech.html"&gt;speak the time&lt;/a&gt; every half hour. I ended up ordering one of the latest quad-core, 27&amp;#8221; iMacs, but I still wanted to get some work done before it arrived.&lt;/p&gt;

&lt;p&gt;If I could enable screen sharing, I would be able to work from my Ubuntu box via VNC. So I hit &lt;strong&gt;⌘-Space bar&lt;/strong&gt; to bring up the Spotlight search box on the iMac. I typed &lt;strong&gt;Terminal&lt;/strong&gt; and hit &amp;#8216;Return&amp;#8217;, all while staring at a pitch-black screen. To check on the state of things, I would periodically pipe the output of commands to the &lt;code&gt;say&lt;/code&gt; command, which would in turn speak the input. For example,&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;pwd | say
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;would speak the path of the current working directory. Next, I enabled &lt;code&gt;ARDAgent&lt;/code&gt; to start the screen sharing agent (normally enabled in System Preferences):&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;cd /System/Library/CoreServices/RemoteManagement
sudo ./ARDAgent.app/Contents/Resources/kickstart \
-activate -configure -access -on -clientopts -setvnclegacy -vnclegacy yes \
-clientopts -setvncpw -vncpw PASSWORD -restart -agent -privs -all
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;After a quick reboot, I was able to start a VNC connection from Ubuntu 10.10 to Snow Leopard. Of course, if you have another Intel Mac and a spare FireWire cable in the house, you can always boot up the defective Mac using &lt;a href="http://support.apple.com/kb/ht1661"&gt;Target Disk Mode&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;All in all, I still managed to crank out a few more Xcode builds of some of the projects I&amp;#8217;m working on, until my new iMac arrived.&lt;/p&gt;</description><link>http://mattrajca.com/post/2446617165</link><guid>http://mattrajca.com/post/2446617165</guid><pubDate>Sat, 09 Jul 2011 13:17:51 -0500</pubDate><category>os x</category><category>unix</category><category>vnc</category></item><item><title>AppKit Quick Tip: Highlighting an Entire NSTableView When Dragged Over</title><description>&lt;p&gt;When a user drags any form of data onto a &lt;code&gt;NSTableView&lt;/code&gt; configured as a drop destination, the data can be dropped above or on top of any row. Sometimes, it may be preferable to highlight the entire table when a drag enters its bounds, as shown below.&lt;/p&gt;

&lt;p&gt;&lt;img src="http://emberapp.com/mattrajca/images/tableview-drop/sizes/m.png" alt="NSTableView Drag and Drop"/&gt;&lt;/p&gt;

&lt;p&gt;To accomplish this, set your drop row to &lt;code&gt;-1&lt;/code&gt; in the &lt;code&gt;tableView:validateDrop:proposedRow:proposedDropOperation:&lt;/code&gt; method, which is a part of the &lt;code&gt;NSTableViewDataSource&lt;/code&gt; protocol.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;- (NSDragOperation)tableView:(NSTableView *)tableView
                validateDrop:(id &amp;lt; NSDraggingInfo &amp;gt;)info
                 proposedRow:(NSInteger)row
       proposedDropOperation:(NSTableViewDropOperation)dropOperation {

    [tableView setDropRow:-1 dropOperation:NSTableViewDropOn];

    return NSDragOperationEvery;
}
&lt;/code&gt;&lt;/pre&gt;</description><link>http://mattrajca.com/post/1276425751</link><guid>http://mattrajca.com/post/1276425751</guid><pubDate>Fri, 01 Jul 2011 22:06:15 -0500</pubDate><category>development</category><category>appkit</category><category>nstableview</category></item><item><title>App Engine Notes</title><description>&lt;p&gt;Earlier today, I released &lt;a href="https://fb2cal.appspot.com/"&gt;fb2cal&lt;/a&gt;, a web app that lets users view their Facebook friends&amp;#8217; birthdays right from a native calendaring client. Coming from a desktop development background, writing a web app on top of App Engine was a new experience for me. Some points to take away:&lt;/p&gt;

&lt;ul&gt;&lt;li&gt;Extend templates to reuse large parts of common HTML code; think inheritance&lt;/li&gt;
&lt;li&gt;Leverage the &lt;a href="http://code.google.com/appengine/docs/python/memcache/"&gt;memcache&lt;/a&gt; when making large data store queries or performing network requests&lt;/li&gt;
&lt;li&gt;To serve parts of a web app using HTTPS, add &lt;code&gt;secure: always&lt;/code&gt; to the script handler in &lt;code&gt;app.yaml&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;p&gt;And lastly, to handle basic authentication in a subclass of &lt;code&gt;RequestHandler&lt;/code&gt;:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;auth = self.request.headers.get('Authorization')

if not auth:
    self.response.set_status(401, message="Authorization Required")
    self.response.headers['WWW-Authenticate'] = 'Basic realm="Secure Area"'
    return None

parts = auth.split(' ')
username_pass = base64.b64decode(parts[1]).split(':')

username = username_pass[0]
password = username_pass[1]

# validate username and password...
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Overall, I was extremely pleased with how fast, easy, and inexpensive it is to host a fully-functional web app on App Engine.&lt;/p&gt;</description><link>http://mattrajca.com/post/1499698990</link><guid>http://mattrajca.com/post/1499698990</guid><pubDate>Fri, 01 Jul 2011 20:27:19 -0500</pubDate><category>app engine</category><category>web</category><category>development</category></item><item><title>Quick and Dirty Profiling with Blocks</title><description>&lt;p&gt;Instruments is an amazing tool for finding all sorts of performance issues in your applications, but sometimes, all you want to do is log a quick and dirty timing of a snippet of code.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://borkware.com"&gt;Mark Darlymple&lt;/a&gt; once posted a &lt;a href="http://borkware.com/quickies/one?topic=Unix%20API"&gt;quickie&lt;/a&gt; that does just this. Unfortunately, the code isn&amp;#8217;t very reusable. Each time you want to profile a chunk of code, you need to wrap it in nearly 8 lines of boilerplate code.&lt;/p&gt;

&lt;p&gt;By writing a &lt;code&gt;profile&lt;/code&gt; function that takes a block of work as an argument, this problem becomes trivial.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;void profile (const char *name, void (^work) (void)) {
    struct timeval start, end;
    gettimeofday (&amp;amp;start, NULL);

    work();

    gettimeofday (&amp;amp;end, NULL);

    double fstart = (start.tv_sec * 1000000.0 + start.tv_usec) / 1000000.0;
    double fend = (end.tv_sec * 1000000.0 + end.tv_usec) / 1000000.0;

    printf("%s took %f seconds", name, fend - fstart);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;To profile some code, all we now have to do is call &lt;code&gt;profile&lt;/code&gt; and pass our worker block; the timing will get logged to standard out.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;profile("Long Task", ^{ performLongTask() } );
&lt;/code&gt;&lt;/pre&gt;</description><link>http://mattrajca.com/post/1182203489</link><guid>http://mattrajca.com/post/1182203489</guid><pubDate>Fri, 01 Jul 2011 20:21:59 -0500</pubDate><category>os x</category><category>development</category><category>blocks</category><category>performance</category></item><item><title>App Store Review Guidelines</title><description>&lt;a href="http://www.apple.com/pr/library/2010/09/09statement.html"&gt;App Store Review Guidelines&lt;/a&gt;: &lt;p&gt;The App Store Review Guidelines and the newly-established App Review Board are huge steps in the right direction. Thank you, Apple.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Update:&lt;/strong&gt; The introduction seems to be written by Steve Jobs himself, as others already pointed out.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;We have over 250,000 apps in the App Store. We don’t need any more Fart apps. If your app doesn’t do something useful or provide some form of lasting entertainment, it may not be accepted.&lt;/p&gt;
&lt;/blockquote&gt;</description><link>http://mattrajca.com/post/1094180251</link><guid>http://mattrajca.com/post/1094180251</guid><pubDate>Fri, 01 Jul 2011 20:18:04 -0500</pubDate><category>ios</category><category>development</category><category>apple</category></item><item><title>Writing a Bouncing Ball Physics Simulation for iOS</title><description>&lt;p&gt;Recently, I have been doing some iOS game development on top of the Chipmunk physics engine. Chipmunk is an exceptionally well-designed library which makes coding some basic physics simulations really fun. The goal of this article is to introduce you to the basics of Chipmunk while creating a bouncing ball physics simulation for iOS. When you tap on your device&amp;#8217;s screen, a new ball will be added to the scene. As you tilt your device, all of the balls will fall in respect to the new gravitational field, reported by the accelerometer.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Getting Started&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To get started, create a new Xcode project based off of the &amp;#8216;View-based Application&amp;#8217; template. Select &amp;#8216;iPad&amp;#8217; for the target device to get the greatest amount screen real estate. Name the new project &amp;#8220;BounceyBalls&amp;#8221;.&lt;/p&gt;

&lt;p&gt;&lt;img src="http://emberapp.com/mattrajca/images/bb-xcode/sizes/m.png" alt="Xcode Project"/&gt;&lt;/p&gt;

&lt;p&gt;Next, we need to download the latest release of the Chipmunk physics library, found &lt;a href="http://code.google.com/p/chipmunk-physics/"&gt;here&lt;/a&gt;. Extract the downloaded archive and drag the &lt;code&gt;src&lt;/code&gt; and &lt;code&gt;include&lt;/code&gt; subfolders into the &lt;code&gt;Classes&lt;/code&gt; group of your Xcode project. Select &amp;#8220;Copy items into destination group&amp;#8217;s folder (if needed)&amp;#8221; if it is unchecked and hit &amp;#8220;Add&amp;#8221;.&lt;/p&gt;

&lt;p&gt;If we were to build the project, we would get a ton of build errors at this point. We need to tell Xcode where Chipmunk&amp;#8217;s include files reside. To do so, select the Xcode project in the file navigator. Click on the &amp;#8216;BounceyBalls&amp;#8217; target and switch to the &amp;#8216;Build Settings&amp;#8217; tab. Find the &amp;#8216;Header Search Paths&amp;#8217; setting and edit its value to include the path &lt;code&gt;Classes/include/chipmunk&lt;/code&gt;. Compiling the Xcode project should now yield no build errors or warnings.&lt;/p&gt;

&lt;p&gt;Since we will be using Core Animation in this project, we also need to make sure the product gets linked against the &lt;code&gt;QuartzCore&lt;/code&gt; framework. Right-click on the &lt;code&gt;Frameworks&lt;/code&gt; group, select &lt;code&gt;Add &amp;gt; Existing Framework&lt;/code&gt;, and choose &lt;code&gt;QuartzCore.framework&lt;/code&gt; from the list.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Chipmunk Overview&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Before we dive into the code, let&amp;#8217;s review some basic information about Chipmunk. Chipmunk is a fast and portable 2D physics engine written in C and distributed under the MIT license. It is a nice and lightweight alternative to the heftier Box2D library (written in C++). Even though the Chipmunk library comes with a simple API, it also includes support for advanced features such as joints, collision detection handlers, and queries. While I don&amp;#8217;t cover them in this article, they are well-documented on the Chipmunk &lt;a href="http://files.slembcke.net/chipmunk/release/ChipmunkLatest-Docs/"&gt;website&lt;/a&gt;. Chipmunk also includes functions for performing common operations with vectors.&lt;/p&gt;

&lt;p&gt;The three fundamental concepts used in Chipmunk are spaces, bodies, and shapes.&lt;/p&gt;

&lt;ul&gt;&lt;li&gt;A &lt;strong&gt;space&lt;/strong&gt; is the &amp;#8220;world&amp;#8221; in which the physics simulation takes place - it serves as the container for bodies and shapes.&lt;/li&gt;
&lt;li&gt;A &lt;strong&gt;body&lt;/strong&gt; is any object that has a mass and a position in space. Chipmunk supports both dynamic bodies and static bodies. As their names imply, dynamic bodies are capable of movement while static bodies, such as the ground, are not.&lt;/li&gt;
&lt;li&gt;A &lt;strong&gt;shape&lt;/strong&gt; defines how a body interacts with other bodies, especially during collisions. It can take the form of a circle, segment, or polygon.&lt;/li&gt;
&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;Writing the Simulation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let&amp;#8217;s dive into the code. Replace the contents of the &lt;code&gt;BounceyBallsViewController.h&lt;/code&gt; file with the code below.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;#import "chipmunk.h"
#import &amp;lt;QuartzCore/QuartzCore.h&amp;gt;

@interface BounceyBallsViewController : UIViewController
            &amp;lt; UIAccelerometerDelegate &amp;gt; {

    cpSpace *space;
}

@end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The code above should be fairly straightforward. We import the necessary header files, configure our view controller so it conforms to the &lt;code&gt;UIAccelerometerDelegate&lt;/code&gt; protocol, and declare a pointer to a &lt;code&gt;cpSpace&lt;/code&gt;, which serves as the container for all of the objects in the simulation.&lt;/p&gt;

&lt;p&gt;Now, let&amp;#8217;s switch over to the &lt;code&gt;BouncingBallsViewController.m&lt;/code&gt; file. We will define a method, &lt;code&gt;setupSpace&lt;/code&gt;, which configures the &amp;#8220;world&amp;#8221; for our physics simulation.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;#define GRAVITY 400.0f

- (void)setupSpace {
    cpInitChipmunk();

    space = cpSpaceNew();
    space-&amp;gt;elasticIterations = space-&amp;gt;iterations;
    space-&amp;gt;gravity = cpv(0.0f, GRAVITY);

    CGSize size = [[self view] bounds].size;

    cpBody *edge = cpBodyNewStatic();
    cpShape *shape = NULL;

    // left
    shape = cpSegmentShapeNew(edge, cpvzero, cpv(0.0f, size.height), 0.0f);
    shape-&amp;gt;u = 0.1f;
    shape-&amp;gt;e = 0.7f;
    cpSpaceAddStaticShape(space, shape);

    // top
    shape = cpSegmentShapeNew(edge, cpvzero, cpv(size.width, 0.0f), 0.0f);
    shape-&amp;gt;u = 0.1f;
    shape-&amp;gt;e = 0.7f;
    cpSpaceAddStaticShape(space, shape);

    // right
    shape = cpSegmentShapeNew(edge, cpv(size.width, 0.0f),
                              cpv(size.width, size.height), 0.0f);
    shape-&amp;gt;u = 0.1f;
    shape-&amp;gt;e = 0.7f;
    cpSpaceAddStaticShape(space, shape);

    // bottom
    shape = cpSegmentShapeNew(edge, cpv(0.0f, size.height),
                                    cpv(size.width, size.height), 0.0f);
    shape-&amp;gt;u = 0.1f;
    shape-&amp;gt;e = 0.7f;
    cpSpaceAddStaticShape(space, shape);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;First, we initialize the Chipmunk library. Without this, Chipmunk will, quite simply, crash. Then we initialize our simulation&amp;#8217;s space and set its initial gravitational vector. Next, we need to define the &amp;#8220;edges&amp;#8221; of our viewport to prevent objects from moving off-screen. We create a new static body as well as four segment shapes, which correspond to the four edges of the screen. The &lt;code&gt;u&lt;/code&gt; field of the shape structure defines the friction coefficient (which ranges from 0.0 to 1.0). The &lt;code&gt;e&lt;/code&gt; field defines the coefficient of restitution (or quite simply, bounciness, between 0.0 to 1.0). It is best to experiment with these values to find one which feels natural. Once each static shape is set up, we add it to our space.&lt;/p&gt;

&lt;p&gt;While we&amp;#8217;re at it, let&amp;#8217;s also implement &lt;code&gt;dealloc&lt;/code&gt; before we forget:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;- (void)dealloc {
    cpSpaceFree(space);
    [super dealloc];
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Next, we will implement the &lt;code&gt;viewDidLoad&lt;/code&gt; method and override &lt;code&gt;shouldAutorotateToInterfaceOrientation&lt;/code&gt; to return &lt;code&gt;NO&lt;/code&gt;, like so:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupSpace];

    UITapGestureRecognizer *gr = [[UITapGestureRecognizer alloc] initWithTarget:self
                                                                         action:@selector(tap:)];

    [self.view addGestureRecognizer:gr];
    [gr release];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation {
    return NO;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;In the code above, we setup our Chipmunk world and attach a gesture recognizer to our view. When a tap occurs, we will add a new ball to the simulation. Since we initially set up the gravitational vector, the ball will drop to the ground and bounce off of one of the four edges we defined. To learn more about gesture recognizers, consult Apple&amp;#8217;s &lt;a href="http://developer.apple.com/library/ios/#documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/GestureRecognizers/GestureRecognizers.html"&gt;documentation&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Now, let&amp;#8217;s implement the &lt;code&gt;dropBallAtPoint:&lt;/code&gt; method, which will get called whenever the user taps on the screen.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;#define RADIUS 32.0f

- (void)dropBallAtPoint:(CGPoint)pt {
    CALayer *layer = [CALayer layer];
    layer.position = pt;
    layer.bounds = CGRectMake(0.0f, 0.0f, RADIUS*2, RADIUS*2);
    layer.cornerRadius = RADIUS;
    layer.backgroundColor = [UIColor purpleColor].CGColor;

    [[self.view layer] addSublayer:layer];

    cpBody *body = cpBodyNew(1.0f, INFINITY);
    body-&amp;gt;p = pt;
    cpSpaceAddBody(space, body);

    cpShape *ball = cpCircleShapeNew(body, RADIUS, cpvzero);
    ball-&amp;gt;data = layer;
    ball-&amp;gt;e = 0.7f;
    cpSpaceAddShape(space, ball);
}

- (void)tap:(UITapGestureRecognizer *)gr {
    CGPoint pt = [gr locationInView:self.view];
    [self dropBallAtPoint:pt];
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;We create a new Core Animation layer, which will represent our ball. Note that setting &lt;code&gt;cornerRadius&lt;/code&gt; to half of the layer&amp;#8217;s width will result in a circle shape. Next, we create a new dynamic body which will define the mass and position of the ball in space. Its center position corresponds to the layer&amp;#8217;s center position. We also create a circle shape model object which corresponds to our layer&amp;#8217;s shape. This will allow Chipumunk to perform collision detection against any other object in space. Finally, we associate the Core Animation layer with the shape for future reference, give the ball some bounciness, and add the shape to our space.&lt;/p&gt;

&lt;p&gt;In order to run the actual simulation, we need to set up a timer which will periodically tell Chipmunk to update its bodies&amp;#8217; positions in space. We also configure the accelerometer in the &lt;code&gt;viewDidAppear:&lt;/code&gt; method:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;#define STEP_INTERVAL 1/60.0f

- (void)viewDidAppear:(BOOL)animated {
    [NSTimer scheduledTimerWithTimeInterval:STEP_INTERVAL
                                     target:self
                                   selector:@selector(step)
                                   userInfo:nil
                                    repeats:YES];

    [UIAccelerometer sharedAccelerometer].updateInterval = 1/30.0f;
    [UIAccelerometer sharedAccelerometer].delegate = self;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;In the &lt;code&gt;step&lt;/code&gt; method which we will implement next, we tell Chipmunk to step the simulation forward in time. It is optimal to use a fixed interval here. We also loop through every active shape in space by calling &lt;code&gt;cpSpaceHashEach&lt;/code&gt; and update each ball&amp;#8217;s position. Note that we disable the default Core Animation actions beforehand.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;- (void)step {
    cpSpaceStep(space, STEP_INTERVAL);

    [CATransaction setDisableActions:YES];
    cpSpaceHashEach(space-&amp;gt;activeShapes, &amp;amp;updateSpace, self);
    [CATransaction setDisableActions:NO];
}

static void updateSpace (void *obj, void *data) {
    cpShape *shape = (cpShape *) obj;
    CALayer *layer = shape-&amp;gt;data;

    if (!layer)
        return;

    layer.position = shape-&amp;gt;body-&amp;gt;p;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Lastly, we will implement our accelerometer&amp;#8217;s delegate method and adjust the gravitational field of our space. A low-pass filter is used to filter out random jerks.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;#define FILTER_FACTOR 0.05f

- (void)accelerometer:(UIAccelerometer *)accelerometer
        didAccelerate:(UIAcceleration *)acceleration {

    static float prevX = 0.0f, prevY = 0.0f;

    prevX = (float) acceleration.x * FILTER_FACTOR + (1-FILTER_FACTOR) * prevX;
    prevY = (float) acceleration.y * FILTER_FACTOR + (1-FILTER_FACTOR) * prevY;

    space-&amp;gt;gravity = cpv(prevX * GRAVITY, -prevY * GRAVITY);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;That&amp;#8217;s it! If you run the app on your iPad and add a few balls, you will notice they fall to the ground and bounce off. If you tilt the device, the balls will move since the gravitational field is adjusted.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The completed Xcode project can be found on &lt;a href="https://github.com/mattrajca/Physics-Demos/tree/master/BounceyBalls"&gt;github (updated)&lt;/a&gt;.&lt;/strong&gt;&lt;/p&gt;</description><link>http://mattrajca.com/post/3393477103</link><guid>http://mattrajca.com/post/3393477103</guid><pubDate>Sat, 21 May 2011 12:53:00 -0500</pubDate><category>ios</category><category>physics</category><category>chipmunk</category></item></channel></rss>

