<?xml version='1.0' encoding='utf-8'?>

<rss version='2.0'
  xmlns:content='http://purl.org/rss/1.0/modules/content/'
  xmlns:dc='http://purl.org/dc/elements/1.1/'
>

<!--
<rdf:RDF
  xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'
  xmlns='http://purl.org/rss/1.0/'
>
-->

<channel>

  <title>Borkware Quickies</title>
  <description>
    Quickies - Little chunklets of Mac OS X and Unix Information.
  </description>
  <pubDate>Sat, 23 Aug 2008 14:27:00 UTC</pubDate>
  <link>http://borkware.com</link>

<item>
  <title>Making "edit all in scope" work (Xcode-&gt;Hacks)</title>
  <pubDate>Sat, 23 Aug 2008 14:27:00 UTC</pubDate>
  <description>
     Xcode&#39;s &#34;Edit All in Scope&#34; feature is inexplicably tied to visible syntax colorization (actually, only Edit All in Scope for object pointers is tied to this, scalar variables and pointers work fine otherwise).  So if you&#39;re not  getting the Edit All in Scope menu item to enable, make sure &#34;Color indexed Symbols&#34; is turned on in the Xcode &#34;Fonts and Colors&#34; preferences.&lt;br&gt;&lt;br&gt;
&lt;p&gt;

This advice brought to you by a DTS incident.&lt;br&gt;
  </description>
  <guid isPermaLink='false'>http://borkware.com/quickies/single?id=389</guid>
</item>

<item>
  <title>Changing __MyCompanyName__ (Xcode-&gt;Hacks)</title>
  <pubDate>Fri, 25 Jul 2008 13:16:07 UTC</pubDate>
  <description>
     You&#39;ve probably noticed that source files generated from within XCode include a comment block header:&lt;br&gt;&lt;br&gt;
&lt;pre&gt;//
//  TapDance.h
//  Groovilicous
//
//  Created by markd on 7/25/08.
//  Copyright 2008 __MyCompanyName__. All rights reserved.
//&lt;/pre&gt;

With the __MyCompanyName__ placeholder.  There is no UI to change this, for obvious reasons.  (Why would &lt;b&gt;anyone&lt;/b&gt; want to easily and conveniently change something they&#39;ll otherwise need to edit in each and every source file they create.  That&#39;s unpossible).  The obvious solution is to drop to the terminal and run the straightforward command:

&lt;pre&gt;% defaults write com.apple.Xcode PBXCustomTemplateMacroDefinitions &#39;{&#34;ORGANIZATIONNAME&#34; = &#34;Borkware&#34;;}&#39;&lt;/pre&gt;

Seemple, no?  Zee trick, she is doone.&lt;br&gt;
  </description>
  <guid isPermaLink='false'>http://borkware.com/quickies/single?id=388</guid>
</item>

<item>
  <title>Seeing extended attributes with 'ls' (Unix-&gt;General)</title>
  <pubDate>Fri, 25 Jul 2008 00:54:04 UTC</pubDate>
  <description>
     Sometimes you see an @ after the directory permissions in an &lt;code&gt;ls -l&lt;/code&gt;:&lt;br&gt;&lt;br&gt;
&lt;pre&gt;% ls -l ~/junk/SnapshotRepository.sparseimage
-rw-r--r--@ 1 markd  markd  135270400 Jul 24 20:38 /Users/markd/junk/SnapshotRepository.sparseimage&lt;/pre&gt;

That means there&#39;s some extended attributes.  use &lt;code&gt;ls -l@ to see them&lt;/code&gt;:

&lt;pre&gt;% ls -l@ ~/junk/SnapshotRepository.sparseimage
-rw-r--r--@ 1 markd  markd  135270400 Jul 24 20:38 /Users/markd/junk/SnapshotRepository.sparseimage
	com.apple.diskimages.fsck	       20 &lt;/pre&gt;&lt;br&gt;
  </description>
  <guid isPermaLink='false'>http://borkware.com/quickies/single?id=387</guid>
</item>

<item>
  <title>Turning off Xcode's "Undo past save" warning (Xcode-&gt;General)</title>
  <pubDate>Mon, 14 Jul 2008 00:46:58 UTC</pubDate>
  <description>
     For some reason, Xcode thinks that an undo past the last save is something horrible that you need to be warned about.  After living with unstable software, cmd-S is a habit, and undoing past it is No Big Deal.  Really.  Here&#39;s how to turn it off:&lt;br&gt;&lt;br&gt;
&lt;pre&gt;% defaults write com.apple.Xcode XCShowUndoPastSaveWarning NO&lt;/pre&gt;&lt;br&gt;
  </description>
  <guid isPermaLink='false'>http://borkware.com/quickies/single?id=386</guid>
</item>

<item>
  <title>Making naked memory autoreleased (General-&gt;General)</title>
  <pubDate>Tue, 03 Jun 2008 15:52:30 UTC</pubDate>
  <description>
     (courtesy of Godfrey van der Linden, two ways of having autoreleased memory but not making the user of that memory be aware of ObjC objects)&lt;br&gt;&lt;br&gt;&lt;p&gt;

&lt;pre&gt;static void *tempCopyOf(void *data, UInt32 size) {
   void *buffer = NULL;
   if (data) {
       buffer = malloc(size);
       if (buffer) {
           bcopy(data, buffer, size);
           [NSData dataWithBytesNoCopy: buffer  length: size  freeWhenDone: YES];
       }
   }
   return (buffer);
}&lt;/pre&gt;

This works in a AutoReleased environment but it is long winded.

&lt;pre&gt;static void *tempCopyOf(void *data, NSUInteger size)
{
   void *buffer = NULL;
   if (data) {
       buffer = [[NSMutableData dataWithCapacity: size] mutableData];
       bcopy(data, buffer, size);
   }
   return buffer;
}&lt;/pre&gt;

You can choose to check the buffer is not null but this avoids the more complicated malloc then alloc call of earlier.&lt;br&gt;
  </description>
  <guid isPermaLink='false'>http://borkware.com/quickies/single?id=385</guid>
</item>

<item>
  <title>Toggle 'screen's visible bell on and off (Unix-&gt;General)</title>
  <pubDate>Tue, 27 May 2008 19:48:58 UTC</pubDate>
  <description>
     Assuming &lt;code&gt;^t&lt;/code&gt; is the hotkey, doing &lt;code&gt;^t ^g&lt;/code&gt; will toggle the visible bell on and off.&lt;br&gt;
  </description>
  <guid isPermaLink='false'>http://borkware.com/quickies/single?id=384</guid>
</item>

<item>
  <title>Multiple Objects in one document (Photoshop-&gt;General)</title>
  <pubDate>Sat, 10 May 2008 00:58:01 UTC</pubDate>
  <description>
     Say you have two Smart Objects from ACR or something, and now you want them into one document so you can do some layer mask nonsense.  To get them into one file do this:&lt;br&gt;&lt;br&gt;
&lt;ul&gt;
  &lt;li&gt; Open up both files
  &lt;li&gt; Bring the source file up, shift-drag the layer from the palette
  &lt;li&gt; Drag into the image area of the target document
&lt;/ul&gt;&lt;br&gt;
  </description>
  <guid isPermaLink='false'>http://borkware.com/quickies/single?id=383</guid>
</item>

<item>
  <title>Opening webview links in the user's default browser. (WebKit-&gt;General)</title>
  <pubDate>Fri, 09 May 2008 17:46:49 UTC</pubDate>
  <description>
     &lt;pre&gt;&lt;br&gt;&lt;br&gt;...
  [someWebView setPolicyDelegate: self];
...

- (void) webView:(WebView *)webView
decidePolicyForNavigationAction:(NSDictionary *)actionInformation
         request:(NSURLRequest *)request
           frame:(WebFrame *)frame
decisionListener:(id&lt;WebPolicyDecisionListener&gt;)listener {
    NSURL *url = [request URL];
    if (url != nil) {
        [[NSWorkspace sharedWorkspace] openURL:url];
    }

}  // decidePolicyForNavigationAction

&lt;/pre&gt;&lt;br&gt;
  </description>
  <guid isPermaLink='false'>http://borkware.com/quickies/single?id=382</guid>
</item>

<item>
  <title>Reverting opened, but unedited files (Perforce-&gt;General)</title>
  <pubDate>Tue, 29 Apr 2008 17:50:44 UTC</pubDate>
  <description>
     &lt;pre&gt;&lt;br&gt;&lt;br&gt; p4 revert -a
&lt;/pre&gt;

will revert all files that haven&#39;t actually be edited, leaving the edited opened.  

&lt;p&gt;

(Thanks to TVL for this one)&lt;br&gt;
  </description>
  <guid isPermaLink='false'>http://borkware.com/quickies/single?id=381</guid>
</item>

<item>
  <title>Turning off the executable bit in Perforce (Perforce-&gt;General)</title>
  <pubDate>Tue, 29 Apr 2008 17:47:31 UTC</pubDate>
  <description>
     &lt;pre&gt;&lt;br&gt;&lt;br&gt;p4 edit -t text [file_list] 
p4 submit
&lt;/pre&gt;

(Thanks to TVL for this one)&lt;br&gt;
  </description>
  <guid isPermaLink='false'>http://borkware.com/quickies/single?id=380</guid>
</item>

<item>
  <title>Printing network traffic (Unix-&gt;Hacks)</title>
  <pubDate>Thu, 13 Mar 2008 21:42:09 UTC</pubDate>
  <description>
     &lt;pre&gt;% sudo tcpdump -Atq -s 0 -i en1&lt;/pre&gt;&lt;br&gt;&lt;br&gt;
&lt;code&gt;-i en1&lt;/code&gt; will display traffic on your airport card.  Use &lt;code&gt;en0&lt;/code&gt; (or nothing, for most systems) for built-in ethernettage.

&lt;p&gt;

You can add a host line to limit output to a particular host
&lt;pre&gt;% sudo tcpdump -Atq -s 0 -i en1 host zombo.com&lt;/pre&gt;

(thanks to Dan Jalkut for this one)&lt;br&gt;
  </description>
  <guid isPermaLink='false'>http://borkware.com/quickies/single?id=379</guid>
</item>

<item>
  <title>Eating Brains (Debugging-&gt;gdb)</title>
  <pubDate>Tue, 11 Mar 2008 19:54:13 UTC</pubDate>
  <description>
     You can turn on Zombies to catch uses of objects after they have been released.  Here&#39;s an easy way to do it in the gdb console:&lt;br&gt;&lt;br&gt;
&lt;pre&gt;
  % gdb build/Debug/Snorkfizzle.app/Contents/MacOS/Snorkfizzle
  (gdb) set env NSZombieEnabled=YES
  (gdb) fb -[_NSZombie methodSignatureForSelector:]
  (gdb) run
&lt;/pre&gt;

Then exercise your app and trip the error.&lt;br&gt;
  </description>
  <guid isPermaLink='false'>http://borkware.com/quickies/single?id=378</guid>
</item>

<item>
  <title>Running a window modally (NSWindow-&gt;General)</title>
  <pubDate>Sun, 02 Mar 2008 23:54:36 UTC</pubDate>
  <description>
     &lt;pre&gt;  // I am the very modal of a modern major general.&lt;br&gt;&lt;br&gt;  int blah = [NSApp runModalForWindow:[self window]];
&lt;/pre&gt;

and then elsewhere, like in your OK or cancel button

&lt;pre&gt;  [NSApp stopModalWithCode:NSOKButton];&lt;/pre&gt;&lt;br&gt;
  </description>
  <guid isPermaLink='false'>http://borkware.com/quickies/single?id=377</guid>
</item>

<item>
  <title>Getting OS version from the command line (Unix-&gt;Random)</title>
  <pubDate>Mon, 11 Feb 2008 20:37:36 UTC</pubDate>
  <description>
     &lt;pre&gt;&lt;b&gt;% sw_vers -productVersion&lt;/b&gt;&lt;br&gt;&lt;br&gt;10.5.1
&lt;/pre&gt;&lt;br&gt;
  </description>
  <guid isPermaLink='false'>http://borkware.com/quickies/single?id=376</guid>
</item>

<item>
  <title>Varargs in Objective-C (General-&gt;Random)</title>
  <pubDate>Sun, 27 Jan 2008 22:54:55 UTC</pubDate>
  <description>
     This processes a nil-terminated sequence of strings:&lt;br&gt;&lt;br&gt;
&lt;pre&gt;- (void) snorgWaffle: (NSString *) start, ... {

    va_list argList;
    va_start (argList, start);

    NSString *string = start;

    while (string != nil) {
        NSLog (@&#34;Done did saw string &#39;%@&#39;&#34;, string);

        string = va_arg (argList, NSString *);
    }

    va_end (argList);

} // snorgWaffle&lt;/pre&gt;

and can be called like

&lt;pre&gt;[self snorgWaffle:@&#34;red&#34;, @&#34;planet&#34;, @&#34;zeitgeist&#34;, nil];&lt;/pre&gt;&lt;br&gt;
  </description>
  <guid isPermaLink='false'>http://borkware.com/quickies/single?id=375</guid>
</item>

<item>
  <title>Launch Services admin tool (Random-&gt;Random)</title>
  <pubDate>Thu, 20 Dec 2007 19:44:38 UTC</pubDate>
  <description>
     If you need to poke around &lt;strike&gt;Lunch&lt;/strike&gt; Launch Services, use the &lt;code&gt;lsregister&lt;/code&gt; tool that lives in &lt;code&gt;/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support&lt;/code&gt;&lt;br&gt;
  </description>
  <guid isPermaLink='false'>http://borkware.com/quickies/single?id=374</guid>
</item>

<item>
  <title>Today's date as a string (NSString-&gt;General)</title>
  <pubDate>Tue, 04 Dec 2007 16:00:26 UTC</pubDate>
  <description>
     The general solution for converting a date to a string is NSDateFormatter.  Sometimes you need to generate a date string in a particular format easily.  For instance if you need &#34;December 4, 2007&#34;, you can use:&lt;br&gt;&lt;br&gt;&lt;pre&gt;[[NSDate date] descriptionWithCalendarFormat: @&#34;%B %e, %Y&#34; timeZone: nil locale: nil]&lt;/pre&gt;
(Thanks to Mike Morton for this one)&lt;br&gt;
  </description>
  <guid isPermaLink='false'>http://borkware.com/quickies/single?id=373</guid>
</item>

<item>
  <title>Binary Searching in a sorted NSArray (NSArray-&gt;General)</title>
  <pubDate>Fri, 23 Nov 2007 03:10:00 UTC</pubDate>
  <description>
     How do you binary search a sorted NSArray? Use toll free bridging to CFArray which actually has a binary search function:&lt;br&gt;&lt;br&gt;&lt;pre&gt;
    NSMutableArray *sortedArray = [NSMutableArray arrayWithObjects: @&#34;Alice&#34;, @&#34;Beth&#34;, @&#34;Carol&#34;,@&#34;Ellen&#34;,nil];
    
    //Where is &#34;Beth&#34;?
    unsigned index = (unsigned)CFArrayBSearchValues((CFArrayRef)sortedArray,
                                                    CFRangeMake(0, CFArrayGetCount((CFArrayRef)sortedArray)),
                                                    (CFStringRef)@&#34;Beth&#34;,
                                                    (CFComparatorFunction)CFStringCompare,
                                                    NULL);
    if (index &amp;lt; [sortedArray count])
    {
        NSLog(@&#34;Beth was found at index %u&#34;, index);
    } else {
        NSLog(@&#34;Beth was not found (index is beyond the bounds of sortedArray)&#34;);
    }
    
    //Where should we insert &#34;Debra&#34;?
    unsigned insertIndex = (unsigned)CFArrayBSearchValues((CFArrayRef)sortedArray,
                                                          CFRangeMake(0, CFArrayGetCount((CFArrayRef)sortedArray)),
                                                          (CFStringRef)@&#34;Debra&#34;,
                                                          (CFComparatorFunction)CFStringCompare,
                                                          NULL);
    [sortedArray insertObject:@&#34;Debra&#34; atIndex:insertIndex];
    NSLog([sortedArray description]);

    //note: NSArray indices and counts were typed as unsigned.  With the move to 64-bit, they are NSUInteger.
    //CFArray indices and counts are CFIndex, which was SInt32 but also will move to 64-bit?
    //Why was it ever signed and will it remain so?
&lt;/pre&gt;

Muchos Thankos to James Hober for this one.
&lt;p&gt;
Gus Mueller chimed in saying that if you use &lt;code&gt;CFArrayBSearchValues&lt;/code&gt;, be sure to sort with &lt;code&gt;CFArraySortValues&lt;/code&gt; rather than using the Cocoa sorting routines (or at least the comparison) - they treat diacritic marks differently, leading to strange errors.  From Gus, a quick objc addition to NSMutableArray:
&lt;pre&gt;
- (void) cfStringSort {
   CFArraySortValues((CFMutableArrayRef)self, CFRangeMake(0, [self count]), (CFComparatorFunction)CFStringCompare, NULL);
}
&lt;/pre&gt;&lt;br&gt;
  </description>
  <guid isPermaLink='false'>http://borkware.com/quickies/single?id=372</guid>
</item>

<item>
  <title>Making a Cocoa moby file (General-&gt;Random)</title>
  <pubDate>Sat, 29 Sep 2007 20:40:36 UTC</pubDate>
  <description>
     &lt;pre&gt;% cat /System/Library/Frameworks/Foundation.framework/Headers/*.h &gt; ~/moby&lt;br&gt;&lt;br&gt;% cat /System/Library/Frameworks/AppKit.framework/Headers/*.h &gt;&gt; ~/moby
% chmod 444 ~/moby&lt;/pre&gt;&lt;br&gt;
  </description>
  <guid isPermaLink='false'>http://borkware.com/quickies/single?id=371</guid>
</item>

<item>
  <title>Sorting with Selectors (NSObject-&gt;General)</title>
  <pubDate>Sun, 02 Sep 2007 23:34:45 UTC</pubDate>
  <description>
     You can sort mutable arrays by providing a selector that is invoked on each of the elements of the array.  I always get confused about NSOrderedAscending / NSOrderedDescending (I think they&#39;re actually backwards, but that&#39;s just me).  Here it is in a nutcase:&lt;br&gt;&lt;br&gt;
Given this sort command: &lt;pre&gt;
    [themStitches sortUsingSelector: @selector(compareByRowLocation:)];
&lt;/pre&gt;

And this selector on the BWCrossStitch class:

&lt;pre&gt;
  - (NSComparisonResult) compareByRowLocation: (BWCrossStitch *) thing2;
&lt;/pre&gt;

Figure out which is lesser or greater, and return one of these.  Note that &lt;code&gt;self&lt;/code&gt; is the object&#39;s logical value, not the actual value of the &lt;code&gt;self&lt;/code&gt; pointer.

&lt;ul&gt;
  &lt;lI&gt; &lt;b&gt;&lt;code&gt;NSOrderedAsending&lt;/code&gt;&lt;/b&gt; if &lt;code&gt;self&lt;/code&gt;  &amp;lt; &lt;code&gt;thing2&lt;/code&gt;
  &lt;lI&gt; &lt;b&gt;&lt;code&gt;NSOrderedDescending&lt;/code&gt;&lt;/b&gt; if &lt;code&gt;self&lt;/code&gt;  &amp;gt; &lt;code&gt;thing2&lt;/code&gt;
   &lt;li&gt; &lt;b&gt;&lt;code&gt;NSOrderedSame&lt;/code&gt;&lt;/b&gt; if &lt;code&gt;self&lt;/code&gt; == &lt;code&gt;thing2&lt;/code&gt;
&lt;/ul&gt;&lt;br&gt;
  </description>
  <guid isPermaLink='false'>http://borkware.com/quickies/single?id=370</guid>
</item>

</channel>
</rss>
