<?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>Fri, 03 Feb 2012 19:34:35 UTC</pubDate>
  <link>http://borkware.com</link>

<item>
  <title>Triggering a low-memory warning on the device (Debugging-&gt;General)</title>
  <pubDate>Fri, 03 Feb 2012 19:34:35 UTC</pubDate>
  <description>
     You can trigger a low-memory warning in the simulator, but sometimes you use one of the myriad of APIs that aren&#39;t supported in the simulator, but you still need to track down something ultimately triggered by a low-memory warning.&lt;br&gt;&lt;br&gt;
&lt;p&gt;

Put this somewhere convenient to trigger  - in a timer, under a button, or something.  Obviously, you don&#39;t want to ship with it.

&lt;pre&gt;[[UIApplication sharedApplication] performSelector: @selector(_performMemoryWarning)];&lt;/pre&gt;&lt;br&gt;
  </description>
  <guid isPermaLink='false'>http://borkware.com/quickies/single?id=514</guid>
</item>

<item>
  <title>Using a nib for a tableview cell (UITableView-&gt;General)</title>
  <pubDate>Sat, 28 Jan 2012 02:01:55 UTC</pubDate>
  <description>
     You can use a nib file for table view cells pretty easily in iOS5.&lt;br&gt;&lt;br&gt;
&lt;p&gt;

1) Make a nib with a single object at the top, a &lt;code&gt;UITableViewCell&lt;/code&gt;.  Lay it out as you wish.  I use view tags to get to the objects contained therein.

&lt;pre&gt;
enum {
    kTermLabelTag = 1,
    kDetailLabelTag = 2
};
&lt;/pre&gt;

&lt;p&gt;

2) Register the nib for a cell reuse identifier.  I do it in my &lt;code&gt;-viewDidLoad&lt;/code&gt;.

&lt;pre&gt;
static NSString *g_cellReuseIdentifier = @&#34;BWLookupCellReuseIdentifier&#34;; // file global

...

    UINib *nib = [UINib nibWithNibName: @&#34;BWLookupTableViewCell&#34;  bundle: nil];
    [self.resultsView registerNib: nib
         forCellReuseIdentifier: g_cellReuseIdentifier];
&lt;/pre&gt;

3) Dequeue the cell as usual

&lt;pre&gt;
    UITableViewCell *cell =
        [tableView dequeueReusableCellWithIdentifier: g_cellReuseIdentifier];

    if (!cell) {
        cell = [[UITableViewCell alloc]
                   initWithStyle: UITableViewCellStyleSubtitle
                   reuseIdentifier: g_cellReuseIdentifier];
    }
&lt;/pre&gt;

4) Dig into the cell with the tags, and go nuts

&lt;pre&gt;
    UILabel *termLabel = (UILabel *)[cell viewWithTag: kTermLabelTag];
    UILabel *detailLabel = (UILabel *)[cell viewWithTag: kDetailLabelTag];

    termLabel.text = termString;
    detailLabel.text = definition;
&lt;/pre&gt;&lt;br&gt;
  </description>
  <guid isPermaLink='false'>http://borkware.com/quickies/single?id=513</guid>
</item>

<item>
  <title>Converting degrees to radians and back (Graphics-&gt;General)</title>
  <pubDate>Thu, 29 Dec 2011 23:31:44 UTC</pubDate>
  <description>
     Most programming interfaces that deal with angles talk in radians (2 pi radians in a circle), like &lt;code&gt;CGAffineTransformRotate&lt;/code&gt;.  I personally think better in degrees (360 degrees in a circle).&lt;br&gt;&lt;br&gt;&lt;p&gt;

Convert degrees to radians by multiplying by &lt;code&gt;180 / pi&lt;/code&gt;.
&lt;p&gt;
Convert radians to degrees by multiplying by &lt;code&gt;pi / 180&lt;/code&gt;
&lt;p&gt;

I have a couple of #defines I stick into a common header for projects that need it;
&lt;pre&gt;#define BWDegToRad(d)   ((d) * M_PI / 180.0)
#define BWRadToDeg(r)   ((r) * 180 / M_PI)
&lt;/pre&gt;&lt;br&gt;
  </description>
  <guid isPermaLink='false'>http://borkware.com/quickies/single?id=512</guid>
</item>

<item>
  <title>Push/pop CGContext state (Graphics-&gt;General)</title>
  <pubDate>Thu, 29 Dec 2011 02:56:29 UTC</pubDate>
  <description>
     &lt;pre&gt;CGContextRef context = ...;&lt;br&gt;&lt;br&gt;...
CGContextSaveGState (context); {
    [drawable drawWithContext: context
              inRect: bounds
              withMetrics: self.metrics]; // or whatever drawing you&#39;re doing
} CGContextRestoreGState (context);
&lt;/pre&gt;

Edit: Gus Meuller of &lt;a href=&#34;http://flyingmeat.com&#34;&gt;Flying Meat&lt;/a&gt; fame has a block-based utility that does this:


&lt;pre&gt;void FMCGContextHoldGState (CGContextRef context, void (^block)()) {
    CGContextSaveGState(context); {
        block ();
    } CGContextRestoreGState(context);
}
&lt;/pre&gt;

and if you&#39;re wanting to do something similar with &lt;code&gt;NSGraphicsContext&lt;/code&gt;s:

&lt;pre&gt;void FMNSContextHoldGState (void (^block)()) {
    [NSGraphicsContext saveGraphicsState]; {
        block ();
    } [NSGraphicsContext restoreGraphicsState];
}
&lt;/pre&gt;&lt;br&gt;
  </description>
  <guid isPermaLink='false'>http://borkware.com/quickies/single?id=511</guid>
</item>

<item>
  <title>Sort case-insensitive (emacs-&gt;General)</title>
  <pubDate>Mon, 26 Dec 2011 03:42:07 UTC</pubDate>
  <description>
     &lt;code&gt;M-x sort-lines&lt;/code&gt; uses a case-sensitive search.   When that sucks, you can tell emacs to be case insensitive (globally) by doing &lt;code&gt;M-x set-variable RET sort-fold-case RET t&lt;/code&gt;&lt;br&gt;
  </description>
  <guid isPermaLink='false'>http://borkware.com/quickies/single?id=510</guid>
</item>

<item>
  <title>UITableView section header titles (UITableView-&gt;General)</title>
  <pubDate>Mon, 26 Dec 2011 01:45:23 UTC</pubDate>
  <description>
     UITableView won&#39;t display its groovy section headers (or footers) until you supply them via the datasource:&lt;br&gt;&lt;br&gt;
&lt;pre&gt;
- (NSString *) tableView: (UITableView *) tableview
 titleForHeaderInSection: (NSInteger) section {
    NSArray *sections = [BWTermStorage sections];
    return [sections objectAtIndex: section];
} // titleForHeaderInSection
&lt;/pre&gt;

You can return a title for a footer.  

&lt;p&gt;

You can also return a view:

&lt;pre&gt;
- (UIView *) tableView: (UITableView *) tableView 
    viewForHeaderInSection: (NSInteger) section;
&lt;/pre&gt;&lt;br&gt;
  </description>
  <guid isPermaLink='false'>http://borkware.com/quickies/single?id=509</guid>
</item>

<item>
  <title>Filter a table view selection (UITableView-&gt;General)</title>
  <pubDate>Sun, 18 Dec 2011 00:37:17 UTC</pubDate>
  <description>
     You might have some rows in a UITableView you don&#39;t want to be selected.  Override &lt;code&gt;willSelectRowAtIndexPath&lt;/code&gt;, return nil to reject the selection, return the passed-in indexPath to use as-is, or return your choice of selected cells.&lt;br&gt;&lt;br&gt;
&lt;pre&gt;
- (NSIndexPath *) tableView: (UITableView *) tableView
   willSelectRowAtIndexPath: (NSIndexPath *) indexPath {
    // don&#39;t select the top row sort control.
    if (indexPath.row == 0) return nil;
    else return indexPath;
} // willSelectRowAtIndexPath
&lt;/pre&gt;&lt;br&gt;
  </description>
  <guid isPermaLink='false'>http://borkware.com/quickies/single?id=508</guid>
</item>

<item>
  <title>Prevent editing / deleting of table rows (UITableView-&gt;General)</title>
  <pubDate>Sat, 17 Dec 2011 23:58:18 UTC</pubDate>
  <description>
     To prevent a row from being deleted in a UITableView (say a header with sorting controls), override &lt;code&gt;-canEditRowAtIndexPath:&lt;/code&gt;&lt;br&gt;&lt;br&gt;
&lt;pre&gt;
- (BOOL) tableView: (UITableView *) tableView
    canEditRowAtIndexPath: (NSIndexPath *) indexPath {
    if (indexPath.row == 0) return NO;
    else return YES;
} // canEditRowAtIndexPath

&lt;/pre&gt;&lt;br&gt;
  </description>
  <guid isPermaLink='false'>http://borkware.com/quickies/single?id=507</guid>
</item>

<item>
  <title>Clipping to a CGPath (Graphics-&gt;General)</title>
  <pubDate>Sat, 26 Nov 2011 00:27:40 UTC</pubDate>
  <description>
     &lt;pre&gt;    CGPathRef border = ... get a path from somewhere;&lt;br&gt;&lt;br&gt;
    CGContextRef context = UIGraphicsGetCurrentContext ();

    CGContextSaveGState (context); {
        CGContextAddPath (context, border);
        CGContextClip (context);

        // draw draw draw

    } CGContextRestoreGState (context);
&lt;/pre&gt;&lt;br&gt;
  </description>
  <guid isPermaLink='false'>http://borkware.com/quickies/single?id=506</guid>
</item>

<item>
  <title>Using Changes.app for hg's diffing (Mercurial-&gt;General)</title>
  <pubDate>Wed, 23 Nov 2011 20:40:00 UTC</pubDate>
  <description>
     Add this to your &lt;code&gt;~/.hgrc&lt;/code&gt;&lt;br&gt;&lt;br&gt;
&lt;pre&gt;
[extensions]
extdiff =

[extdiff]
cmd.chdiff = /Local/Apps/Changes.app/Contents/Resources/chdiff
opts.chdiff = --wait
&lt;/pre&gt;

Your Changes.app path is probably different, so be sure to change it.  Or add the &lt;code&gt;chdiff&lt;/code&gt;&#39;s directory to your shell path.
&lt;p&gt;
Now you can&lt;br&gt;
&lt;code&gt;% hg chdiff&lt;/code&gt;&lt;br&gt;
And get pretty diffing.&lt;br&gt;
  </description>
  <guid isPermaLink='false'>http://borkware.com/quickies/single?id=505</guid>
</item>

<item>
  <title>Register a notification with a block (Notifications-&gt;Blocks)</title>
  <pubDate>Mon, 21 Nov 2011 20:04:40 UTC</pubDate>
  <description>
     &lt;pre&gt;        [center addObserverForName: kGRZoneSystem_ZoneSystemChangedNotification&lt;br&gt;&lt;br&gt;                object: nil
                queue: [NSOperationQueue mainQueue]
                usingBlock: ^(NSNotification *notification) {
                [self adaptToZoneChange];
            }];
&lt;/pre&gt;&lt;br&gt;
  </description>
  <guid isPermaLink='false'>http://borkware.com/quickies/single?id=504</guid>
</item>

<item>
  <title>Moving archived apps from one machine to another (Xcode-&gt;General)</title>
  <pubDate>Sat, 05 Nov 2011 17:46:37 UTC</pubDate>
  <description>
     To move your archived apps from one machine to another (say you&#39;re upgrading to some shinier hardware or doing a nuke-and-pave install), you can find your old archived apps at:&lt;br&gt;&lt;br&gt;&lt;pre&gt;~/Library/Developer/Xcode/Archives&lt;/pre&gt;&lt;br&gt;
  </description>
  <guid isPermaLink='false'>http://borkware.com/quickies/single?id=503</guid>
</item>

<item>
  <title>Control + trackpad zoom in Lion (Random-&gt;Random)</title>
  <pubDate>Fri, 23 Sep 2011 13:52:10 UTC</pubDate>
  <description>
     It took awhile to find where to enable the &#34;zoom into the screen with control+scrollwheel&#34;:&lt;br&gt;&lt;br&gt;

System Preferences &amp;gt; Universal Access &amp;gt; Seeing &amp;gt; Zoom in window &amp;gt; Options &amp;gt; Use scroll wheel with modifier keys to zoom&lt;br&gt;
  </description>
  <guid isPermaLink='false'>http://borkware.com/quickies/single?id=502</guid>
</item>

<item>
  <title>Unicode characters in C strings (General-&gt;General)</title>
  <pubDate>Mon, 19 Sep 2011 17:11:29 UTC</pubDate>
  <description>
     C strings (and Objective-C @&#34;Strings&#34;) are ascii by default, so to include unicode characters, you need to escape-U them:&lt;br&gt;&lt;br&gt;
&lt;pre&gt;
printf (&#34;\u3232_\u3232\u2122\n&#34;);
&lt;/pre&gt;&lt;br&gt;
  </description>
  <guid isPermaLink='false'>http://borkware.com/quickies/single?id=501</guid>
</item>

<item>
  <title>Determining current localization you're running in. (Random-&gt;General)</title>
  <pubDate>Thu, 15 Sep 2011 01:16:50 UTC</pubDate>
  <description>
     You can use this to find which of the user&#39;s preferred localizations/locales that is also supported by your app.  (translation, what localization you&#39;re currently running in)&lt;br&gt;&lt;br&gt;
&lt;pre&gt;NSString *languageused = [[[NSBundle mainBundle] preferredLocalizations] objectAtIndex: 0];&lt;/pre&gt;
(thanks to Glenn Fawcett for this one!)&lt;br&gt;
  </description>
  <guid isPermaLink='false'>http://borkware.com/quickies/single?id=500</guid>
</item>

<item>
  <title>Finding the path corresponding to an open file descriptor (Unix-&gt;General)</title>
  <pubDate>Wed, 14 Sep 2011 21:30:57 UTC</pubDate>
  <description>
     With &lt;code&gt;fcntl&lt;/code&gt;, all things are possible.&lt;br&gt;&lt;br&gt;
&lt;pre&gt;
char pathbuf[PATH_MAX];

if (fcntl(fd, F_GETPATH, pathbuf) &gt;= 0) {
    printf (&#34;wow: %s\n&#34;, pathbuf);
} else {
    printf (&#34;oops %s\n&#34;, strerror(errno));
}
&lt;/pre&gt;

Finding this feature was a surprise, having lived under the assumption that you can&#39;t map from a file descriptor to a path in the file system.  Obviously things like sockets and pipes will return an error, but it actually seems to work.&lt;br&gt;
  </description>
  <guid isPermaLink='false'>http://borkware.com/quickies/single?id=499</guid>
</item>

<item>
  <title>Setting iPhone status bar to black (General-&gt;General)</title>
  <pubDate>Mon, 12 Sep 2011 16:11:00 UTC</pubDate>
  <description>
     In the app&#39;s info.plist, set &lt;code&gt;UIStatusBarStyle&lt;/code&gt; to &lt;code&gt;UIStatusBarStyleOpaqueBlack&lt;/code&gt;&lt;br&gt;
  </description>
  <guid isPermaLink='false'>http://borkware.com/quickies/single?id=498</guid>
</item>

<item>
  <title>Turn off the Lion window animation (General-&gt;General)</title>
  <pubDate>Mon, 12 Sep 2011 00:52:18 UTC</pubDate>
  <description>
     &lt;pre&gt;defaults write NSGlobalDomain NSAutomaticWindowAnimationsEnabled -bool NO&lt;/pre&gt;&lt;br&gt;
  </description>
  <guid isPermaLink='false'>http://borkware.com/quickies/single?id=497</guid>
</item>

<item>
  <title>Adding a decimal point to the numeric keyboard (UITextField-&gt;General)</title>
  <pubDate>Mon, 05 Sep 2011 14:42:58 UTC</pubDate>
  <description>
     Apple added a decimal pad keyboard type.  As of Xcode 4.1, not exported in the UI, so you have to set it in code:&lt;br&gt;&lt;br&gt;&lt;pre&gt;
textField.keyboardType = UIKeyboardTypeDecimalPad;
&lt;/pre&gt;&lt;br&gt;
  </description>
  <guid isPermaLink='false'>http://borkware.com/quickies/single?id=496</guid>
</item>

<item>
  <title>Dismissing the on-screen keyboard (UITextField-&gt;General)</title>
  <pubDate>Mon, 05 Sep 2011 14:41:25 UTC</pubDate>
  <description>
     If you know the text field that is being edited, you can tell it to resign first responder:&lt;br&gt;&lt;br&gt;&lt;pre&gt;
[textField resignFirstResponder];
&lt;/pre&gt;
Otherwise, you can tell the enclosing view to end editing, and it&#39;ll figure out who is editing and tell them to resign:
&lt;pre&gt;
[self.view endEditing: YES];
&lt;/pre&gt;&lt;br&gt;
  </description>
  <guid isPermaLink='false'>http://borkware.com/quickies/single?id=495</guid>
</item>

</channel>
</rss>

