<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
 
 <title>!!!</title>
 <link href="http://blog.stuntaz.org/atom.xml" rel="self"/>
 <link href="http://blog.stuntaz.org/"/>
 <updated>2009-11-29T19:50:19-08:00</updated>
 <id>http://blog.stuntaz.org/</id>
 <author>
   <name>Jon Nall</name>
   <email>nall@stuntaz.org</email>
 </author>
 
 
 <entry>
   <title>Useful GBD user-defined commands for Objective-C</title>
   <link href="http://blog.stuntaz.org/2009/11/29/objective-c-gdb-commands.html"/>
   <updated>2009-11-29T00:00:00-08:00</updated>
   <id>http://tom.preston-werner.com/2009/11/29/objective-c-gdb-commands</id>
   <content type="html">&lt;p&gt;I&amp;#8217;ve been putting together some gdb commands to aid gdb debugging. Here&amp;#8217;s my current list:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;My application has a number of threads and when one asserts it&amp;#8217;s not obvious which is the culprit. I got pretty tired of typing &amp;#8220;thread apply all bt&amp;#8221; all the time, so this is just an alias for that.&lt;/li&gt;
&lt;/ul&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;span class='cp'&gt;    define tbt&lt;/span&gt;
        thread apply all bt
    end

    document tbt
        Issues &lt;span class='s2'&gt;&amp;quot;thread apply all bt&amp;quot;&lt;/span&gt;, thus showing the backtraces &lt;span class='k'&gt;for &lt;/span&gt;all threads
    end
&lt;/pre&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;It&amp;#8217;s also useful to know the true class of an instance. Simply printing the variable prints its declared type. Since Objective-C is dynamic this may or may not be the actual type of the instance. This sends a class message to the object and prints that.&lt;/li&gt;
&lt;/ul&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;span class='cp'&gt;    define pc&lt;/span&gt;
        po &lt;span class='o'&gt;[&lt;/span&gt;&lt;span class='nv'&gt;$arg0&lt;/span&gt; class&lt;span class='o'&gt;]&lt;/span&gt;
    end

    document pc
        Takes one argument and prints its class by sending it the class message.
    end
&lt;/pre&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;I find the NSDate compare: method a constant headache. For some reason my brain just hates converting comparison operators into NSComparsionResult values. Worse, in gdb they&amp;#8217;re just integer literals. This helps a bit. It takes two dates and prints the symbolic NSComparisonResult.&lt;/li&gt;
&lt;/ul&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;span class='cp'&gt;    define cdate&lt;/span&gt;
        &lt;span class='nb'&gt;set&lt;/span&gt; &lt;span class='nv'&gt;$cdate_result&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='o'&gt;(&lt;/span&gt;int&lt;span class='o'&gt;)[&lt;/span&gt;&lt;span class='nv'&gt;$arg0&lt;/span&gt; compare:&lt;span class='nv'&gt;$arg1&lt;/span&gt;&lt;span class='o'&gt;]&lt;/span&gt;
        &lt;span class='k'&gt;if&lt;/span&gt;&lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='nv'&gt;$cdate_result&lt;/span&gt; &lt;span class='o'&gt;==&lt;/span&gt; NSOrderedAscending&lt;span class='o'&gt;)&lt;/span&gt;
            &lt;span class='nb'&gt;printf&lt;/span&gt; &lt;span class='s2'&gt;&amp;quot;NSOrderedAscending\n&amp;quot;&lt;/span&gt;
        end
        &lt;span class='k'&gt;if&lt;/span&gt;&lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='nv'&gt;$cdate_result&lt;/span&gt; &lt;span class='o'&gt;==&lt;/span&gt; NSOrderedSame&lt;span class='o'&gt;)&lt;/span&gt;
            &lt;span class='nb'&gt;printf&lt;/span&gt; &lt;span class='s2'&gt;&amp;quot;NSOrderedSame\n&amp;quot;&lt;/span&gt;
        end
        &lt;span class='k'&gt;if&lt;/span&gt;&lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='nv'&gt;$cdate_result&lt;/span&gt; &lt;span class='o'&gt;==&lt;/span&gt; NSOrderedDescending&lt;span class='o'&gt;)&lt;/span&gt;
            &lt;span class='nb'&gt;printf&lt;/span&gt; &lt;span class='s2'&gt;&amp;quot;NSOrderedDescending\n&amp;quot;&lt;/span&gt;
        end
    end

    document cdate
        Sends a compare: message to arg0 with arg1 as the argument and prints the
        symbolic result
    end
&lt;/pre&gt;
&lt;/div&gt;</content>
 </entry>
 
 <entry>
   <title>Finally getting Google Voice to do my bidding</title>
   <link href="http://blog.stuntaz.org/2009/11/04/google-voice.html"/>
   <updated>2009-11-04T00:00:00-08:00</updated>
   <id>http://tom.preston-werner.com/2009/11/04/google-voice</id>
   <content type="html">&lt;p&gt;After reading some posts about getting &lt;a href='http://google.com/voice'&gt;Google Voice&amp;#8217;s&lt;/a&gt; voicemail transcription abilities from your regular cell phone number, I decided to play around with it. &lt;a href='http://lukabodrozic.net'&gt;Luka&lt;/a&gt; summarized exactly what I wanted to do:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;so what i really want is my gv number to fwd as i set it up, but my fwd&amp;#8217;d cell phone vm to just hit gv and transcribe&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It turns out Google Voice allows you to do this exactly. From your Google Voice settings do the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Phones: Enable your mobile phone here as a forwarding number. Then activate Google voicemail on the phone. This will require you to type in a GSM number on your phone which will forward callers to your Google voicemail instead of the AT&amp;amp;T voicemail system.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Voicemail &amp;amp; SMS: Make sure you have a greeting set and check &amp;#8216;Transcribe Voicemails&amp;#8217;&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Calls: These settings are up to you. I have:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&amp;#8216;Call Screening&amp;#8217; off&lt;/li&gt;

&lt;li&gt;&amp;#8216;Call Presentation&amp;#8217; off&lt;/li&gt;

&lt;li&gt;&amp;#8216;Caller ID&amp;#8217; set to display the caller&amp;#39;s number&lt;/li&gt;

&lt;li&gt;&amp;#8216;Do Not Disturb&amp;#8217; unchecked.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The downside of all of this is that you lose visual voicemail. However, I find getting voicemail transcriptions via SMS is worth that tradeoff.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>So you want to lay an NSView over your entire NSWindow?</title>
   <link href="http://blog.stuntaz.org/cocoa/2009/11/03/nswindow-overlay.html"/>
   <updated>2009-11-03T00:00:00-08:00</updated>
   <id>http://tom.preston-werner.com/cocoa/2009/11/03/nswindow-overlay</id>
   <content type="html">&lt;p&gt;As part of my current Cocoa project I have a window hierarchy like: &lt;pre&gt;
    NSWindow
        |
        +---Content View
                |
                +---NSSplitView
                |       |
                |       +---Custom NSView
                |       +---Custom NSView
                |           ...
                |
                +---Custom NSView
&lt;/pre&gt;&lt;/p&gt;

&lt;p&gt;When populating all of those custom views I need to fetch some data from the network. This can take quite a bit of time and I&amp;#8217;d like to give the user some visual cue that I&amp;#8217;m not just sitting around drinking beer, but am vigilently trying to get their data.&lt;/p&gt;

&lt;p&gt;I settled on graying out the entire window&amp;#8217;s contents and using a label and progress bar to clue the user in on how things were moving along. The first thing I did was whip up an NSView with a black background and an alpha of 0.5 to get the translucent grayed out effect. I then added some custom drawn text in the view&amp;#8217;s drawRect: method and a &lt;a href='http://www.binarymethod.com/binarymethod/bghudappkit/'&gt;BGHUDProgressIndicator&lt;/a&gt; (because it looks sexy on the grayed out layer and I&amp;#8217;ve never been a fan of the blue in the regular NSProgressBar). It looked great. Really.&lt;/p&gt;

&lt;p&gt;Then I realized, where does this go?&lt;/p&gt;

&lt;p&gt;Sibling NSViews that overlap one another have undefined behavior in Cocoa, so it&amp;#8217;s not as simple as overlapping the NSWindow&amp;#8217;s entire content view (I tried this and it kind of worked, but the progress bar didn&amp;#8217;t update as it should have). I had a few ideas of how I might get around this, but decided I&amp;#8217;d solicit some advice from people much smarter than me. So I asked &lt;a href='http://stackoverflow.com/questions/1656049/graying-out-an-nswindows-content'&gt;StackOverflow.com&lt;/a&gt;. As it turns out &lt;a href='http://boredzo.org/'&gt;Peter Hosey&lt;/a&gt; knew exactly what was up and suggested adding a child window. So I went to read up on NSWindow&amp;#8217;s &lt;a href='http://developer.apple.com/mac/library/documentation/Cocoa/Reference/ApplicationKit/Classes/NSWindow_Class/Reference/Reference.html#//apple_ref/doc/uid/20000013-BCIBCGJE'&gt;addChildWindow:ordered:&lt;/a&gt; method.&lt;/p&gt;

&lt;p&gt;It turns out this solution works very well. I subclassed NSWindow to generate a window that could become key. It also observes notifications of the parent window moving or resizing and updates its frame accordingly. This means adding the child window consists of exactly one line in my NSWindowController subclass:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;    &lt;span class='n'&gt;overlayWindow&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='p'&gt;[[&lt;/span&gt;&lt;span class='n'&gt;SZOverlayWindow&lt;/span&gt; &lt;span class='n'&gt;alloc&lt;/span&gt;&lt;span class='p'&gt;]&lt;/span&gt; &lt;span class='nl'&gt;initWithParentWindow:&lt;/span&gt;&lt;span class='n'&gt;self&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;window&lt;/span&gt;
                                                         &lt;span class='nl'&gt;withView:&lt;/span&gt;&lt;span class='n'&gt;subview&lt;/span&gt;&lt;span class='p'&gt;];&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;I decided to keep the SZOverlayWindow class very sparse so as to make it reusable as possible. I did all of the heavy lifting in the subview passed to it. That&amp;#8217;s where the custom text is drawn and the progress bar is updated.&lt;/p&gt;

&lt;p&gt;I&amp;#8217;m very happy with this solution and think it would also lend itself to other situations. For instance, a crosshair that is coherent across multiple subviews of an NSSplitView. Without this technique each subview would have to be able to draw its small piece of the crosshair.&lt;/p&gt;

&lt;p&gt;The code is &lt;a href='http://github.com/nall/SZUtilities'&gt;available&lt;/a&gt;. There is still a bit too much knowledge in the window (mainly regarding the translucent nature), but it&amp;#8217;s a good start for anyone tackling a similar problem.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>First Post</title>
   <link href="http://blog.stuntaz.org/2009/10/31/first-post.html"/>
   <updated>2009-10-31T00:00:00-07:00</updated>
   <id>http://tom.preston-werner.com/2009/10/31/first-post</id>
   <content type="html">&lt;p&gt;I&amp;#8217;ve decided that sometimes I want to write about things in more than &lt;a href='http://twitter.com/stuntaz'&gt;140 characters&lt;/a&gt;, but I don&amp;#8217;t want all the guilt that comes with a normal blog, so I&amp;#8217;m going to use my github pages for this. I hope to post something about once a month.&lt;/p&gt;</content>
 </entry>
 
 
</feed>
