<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Derek Neely</title>
	<atom:link href="http://derekneely.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://derekneely.com</link>
	<description>...what I care to share...</description>
	<lastBuildDate>Thu, 06 Oct 2011 15:10:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>MJPEG to H.264 Streaming for Mobile with VLC</title>
		<link>http://derekneely.com/2011/10/mjpeg-h264-streaming-mobile-vlc/</link>
		<comments>http://derekneely.com/2011/10/mjpeg-h264-streaming-mobile-vlc/#comments</comments>
		<pubDate>Thu, 06 Oct 2011 15:10:17 +0000</pubDate>
		<dc:creator>derek</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Streaming]]></category>
		<category><![CDATA[Video]]></category>
		<category><![CDATA[cgi]]></category>
		<category><![CDATA[Encoding]]></category>
		<category><![CDATA[H.264]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[MJPEG]]></category>
		<category><![CDATA[MPMoviePlayerController]]></category>
		<category><![CDATA[Video Encoding]]></category>
		<category><![CDATA[Video Streaming]]></category>
		<category><![CDATA[VLC]]></category>
		<category><![CDATA[VLC Media Player]]></category>
		<category><![CDATA[Web Cam]]></category>

		<guid isPermaLink="false">http://derekneely.com/?p=634</guid>
		<description><![CDATA[Dang! Its been a while since I&#8217;ve been able to get out here and post something new. We&#8217;ve been busy, busy, busy here at v4 living the dream. Anyhow, as of recently its been tasked upon us to work with some streaming video. Now, the hardware we will be using for our client are some [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://derekneely.com/2011/10/mjpeg-h264-streaming-mobile-vlc/largevlc/" rel="attachment wp-att-651"><img class="alignright size-full wp-image-651" title="VLC Icon" src="http://derekneely.com/wp-content/uploads/2011/10/largeVLC.png" alt="VLC Media Player" width="168" height="168" /></a>Dang! Its been a while since I&#8217;ve been able to get out here and post something new. We&#8217;ve been busy, busy, busy here at <a title="v4 Development" href="http://v4development.com">v4</a> living the dream.</p>
<p>Anyhow, as of recently its been tasked upon us to work with some streaming video. Now, the hardware we will be using for our client are some nice IP/H.264 compatible cameras. Well, I personally do not have one but needed a solution by which I could test and work with. I have one of those little eye ball looking cameras and found some free software (<a title="WebCampXP" href="http://www.webcamxp.com/" target="_blank">WebCamXP</a>) that would run a simple MJPEG stream. (Yea, yea&#8230;its windows but who doesn&#8217;t have a windows box to hack and slash on? Ha!) After this is up and running you have a basic MJPEG stream that is running and accessible via http://10.0.0.99:8080/webcamp_1.cgi (or whatever your internal IP is and the port you configured in the software)</p>
<p><strong>** Note:</strong> This tutorial uses iPhone references as thats what I worked with first. I&#8217;ll update with the Android version later. I am also using Linux (Ubuntu) to do the encoding and serving of the new video stream. Also assuming you have Apache or another web server up and running.</p>
<p>Now, this .cgi page/script &#8216;can&#8217; be placed as the source of a UIWebview and works ok.</p>
<pre>NSString *urlAddress = @"http://10.0.0.99:8080/cam_1.cgi";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[streamWebView loadRequest:requestObj];</pre>
<p>But, ultimately this is not what we&#8217;re looking for. We need to get a nice H.264 compatible stream rolling out so that we can play this directly to the iPhone (MPMoivePlayerController) or be able to hook into a streaming server (as we&#8217;re planning on doing) so that we can re-broadcast to several devices at once.</p>
<p>So&#8230;how might we convert this MJPEG (.cgi) into an H.264 compatible stream? <a title="VideoLan (VLC Media Player)" href="http://www.videolan.org/" target="_blank">VLC Media Player</a> to the rescue.</p>
<p>On your Linux box install VLC and the x264 libraries.</p>
<pre># apt-get install vlc x264</pre>
<p>A few of the tutorials you read on this all reference using the command: <em><strong>vlc</strong></em>. However, if you don&#8217;t have X11 installed on your system (as I do not) you will run into a few errors with regards to this. But, have no fear, VLC provided a command line option: <em><strong>cvlc</strong></em>.</p>
<p>Now what we need to do is fire up VLC with a bunch of options that will read in the MJPEG (.cgi) convert it to H.264 and then provide us with a means of accessing the stream (via the Linux server &#8211; 10.0.0.69). So, on the command prompt do something like:</p>
<pre>cvlc --intf=rc http://10.0.0.99:8080/cam_1.cgi --sout '#transcode{fps=25,
vcodec=h264,venc=x264{aud,profile=baseline,level=30,keyint=30,
bframes=0,ref=1,nocabac},acodec=mp3,ab=56,audio-sync,deinterlace}
:standard{mux=ts,access=http,dst=10.0.0.69:8090/myStream.mp4}'</pre>
<p>Now, on the command prompt you&#8217;ll see a bunch of stuff start scrolling by. This is what you want. Its reading in frames from the original MJPEG stream and converting them. But, you&#8217;re not done yet. In order to get this to play via MPMoviePlayerController on the iPhone, we need to setup the .m3u8 or the playlist file.</p>
<p>In your web server directory create a file myStream.m3u8 and put the following in and save:</p>
<pre>
#EXTM3U
#EXT-X-TARGETDURATION:10
#EXT-X-MEDIA-SEQUENCE:0
#EXTINF:10, 

http://10.0.0.69:8090/myStream.mp4
</pre>
<p>Now you&#8217;re ready for some iPhone code to show the stream.</p>
<pre>NSURL *url = [NSURL URLWithString:@"http://10.0.0.69/myStream.m3u8"];
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:url];
player.controlStyle = MPMovieControlStyleNone;
[player.view setFrame:CGRectMake(0, 120, 320 , 200)];
[self.view addSubview:player.view];
[player play];</pre>
<p>This should basically do it. I don&#8217;t believe I left out any steps. I&#8217;ll update if I run across any missing steps or you guys let me know. When you run the app, it can sometimes take a few seconds before the video starts playing. At one point I set a background color to the mpmovieplayercontroller&#8217;s view so that I could tell where it was being</p>
<p>With MPMoviePlayerController there are several other options you may be interested in using/implementing.</p>
<p>When setting up the player you can have your containing view controller listen for some of the playback events (can help with some debugging) with:</p>
<pre>//Defined in the above MPMoviePlayerController allocation
[[NSNotificationCenter defaultCenter] addObserver:self  selector:@selector(moviePlayerPlaybackStateDidChange:)  name:MPMoviePlayerPlaybackStateDidChangeNotification  object:nil];</pre>
<pre>//NSNotification callback function
- (void)moviePlayerPlaybackStateDidChange:(NSNotification*)notification {
     NSLog(@"playbackDidChanged");
     MPMoviePlayerController *moviePlayer = notification.object;

     MPMoviePlaybackState playbackState = moviePlayer.playbackState;

     if(playbackState == MPMoviePlaybackStateStopped) {
          NSLog(@"MPMoviePlaybackStateStopped");
     } else if(playbackState == MPMoviePlaybackStatePlaying) {
          NSLog(@"MPMoviePlaybackStatePlaying");
     } else if(playbackState == MPMoviePlaybackStatePaused) {
          NSLog(@"MPMoviePlaybackStatePaused");
     } else if(playbackState == MPMoviePlaybackStateInterrupted) {
          NSLog(@"MPMoviePlaybackStateInterrupted");
     } else if(playbackState == MPMoviePlaybackStateSeekingForward) {
          NSLog(@"MPMoviePlaybackStateSeekingForward");
     } else if(playbackState == MPMoviePlaybackStateSeekingBackward) {
          NSLog(@"MPMoviePlaybackStateSeekingBackward");
     }
}</pre>
<p>Please <a href="mailto:feedback@derekneely.com">let me know</a> if I&#8217;ve left out any steps or you have any issues and I&#8217;ll be happy to help and work through it with you. This was a quick and dirty how-to with a ways to go before I push anything out to production. Just wanted to share my research and discovery. Good luck!</p>
<p>References:<br />
<a title="Apple - Reference:MPMoviePlayerController" href="http://developer.apple.com/LIBRARY/IOS/#documentation/MediaPlayer/Reference/MPMoviePlayerController_Class/Reference/Reference.html">Apple &#8211; Reference: MPMoviePlayerController</a><br />
<a title="StackOverflow" href="http://stackoverflow.com/questions/2663637/http-stream-without-extension-in-mpmovieplayercontroller">StackOverflow &#8211; HTTP stream without extension in MPMoviePlayerController</a></p>
]]></content:encoded>
			<wfw:commentRss>http://derekneely.com/2011/10/mjpeg-h264-streaming-mobile-vlc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Size-to-Fit Text in UITextView (iPhone)</title>
		<link>http://derekneely.com/2011/04/size-to-fit-text-in-uitextview-iphone/</link>
		<comments>http://derekneely.com/2011/04/size-to-fit-text-in-uitextview-iphone/#comments</comments>
		<pubDate>Wed, 27 Apr 2011 16:44:43 +0000</pubDate>
		<dc:creator>derek</dc:creator>
				<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Apple]]></category>
		<category><![CDATA[Fit Text]]></category>
		<category><![CDATA[Font Size]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Resize Text]]></category>
		<category><![CDATA[Text]]></category>
		<category><![CDATA[UITextView]]></category>

		<guid isPermaLink="false">http://derekneely.com/?p=615</guid>
		<description><![CDATA[The UITextView is a very useful view. You&#8217;re able to show and interact with large amounts of text. However, I recently found the need to size the UITextView in Interface Builder to fit nicely in a pre-layed out interface. Well, low-and-behold the client I was working for started sending large amounts of text that was [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://derekneely.com/wp-content/uploads/2009/11/xcode-icon.png"><img class="alignright size-full wp-image-479" title="xcode-icon" src="http://derekneely.com/wp-content/uploads/2009/11/xcode-icon.png" alt="" width="143" height="143" /></a>The UITextView is a very useful view. You&#8217;re able to show and interact with large amounts of text. However, I recently found the need to size the UITextView in Interface Builder to fit nicely in a pre-layed out interface. Well, low-and-behold the client I was working for started sending large amounts of text that was to be displayed here. We didn&#8217;t want scrolling but needed to display all the text. So, we needed to resize the text until it would fit and all would be displayed. Below is a very simple way of resizing the text in the UITextView to fit within its current bounds.</p>
<p>At some point define the max size you want the font to be. I typically put this in my .h file</p>
<p><!-- p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #7b482f} span.s1 {color: #2f2fcf} --></p>
<pre>#define kDefaultFontSize 24.0</pre>
<p>Then in your .m file where you add the text to the UITextView you would place something like:</p>
<p><!-- p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #488186} p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px} p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #008426} p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #753ea3} p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo} span.s1 {color: #000000} span.s2 {color: #753ea3} span.s3 {color: #411f7c} span.s4 {color: #d92823} span.s5 {color: #c22a9c} span.s6 {color: #488186} span.s7 {color: #2f2fcf} span.s8 {color: #7b482f} --></p>
<pre>myTextView.text = @"Some long string that will be in the UITextView";
myTextView.font = [UIFont systemFontOfSize:kDefaultFontSize];

//setup text resizing check here
if (myTextView.contentSize.height &gt; myTextView.frame.size.height) {
    int fontIncrement = 1;
    while (myTextView.contentSize.height &gt; myTextView.frame.size.height) {
        myTextView.font = [UIFont systemFontOfSize:kDefaultFontSize-fontIncrement];
        fontIncrement++;
    }
}</pre>
<p>Hope this helps! Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://derekneely.com/2011/04/size-to-fit-text-in-uitextview-iphone/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MacFUSE/Macfusion Fix for Newer Macs</title>
		<link>http://derekneely.com/2011/04/macfusemacfusion-fix-for-newer-macs/</link>
		<comments>http://derekneely.com/2011/04/macfusemacfusion-fix-for-newer-macs/#comments</comments>
		<pubDate>Wed, 06 Apr 2011 13:46:10 +0000</pubDate>
		<dc:creator>derek</dc:creator>
				<category><![CDATA[Mac]]></category>
		<category><![CDATA[64-bit]]></category>
		<category><![CDATA[64-bit kernel]]></category>
		<category><![CDATA[FTPFS]]></category>
		<category><![CDATA[MacBook]]></category>
		<category><![CDATA[MacBook Pro]]></category>
		<category><![CDATA[MacFUSE]]></category>
		<category><![CDATA[Macfusion]]></category>
		<category><![CDATA[Snow Leopard]]></category>
		<category><![CDATA[SSH Mount]]></category>
		<category><![CDATA[SSHFS]]></category>

		<guid isPermaLink="false">http://derekneely.com/?p=596</guid>
		<description><![CDATA[I recently picked  up one of the newly released MacBook Pros. If at all interested its awesome and FAST! Anyhow, I depend on MacFUSE and Macfusion daily to connect to various servers to knock out some development. Well, low and behold, mounting via SSH wasn&#8217;t working again (didn&#8217;t try FTP). Now, I have another fix [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://derekneely.com/wp-content/uploads/2009/06/apple.jpg"><img class="alignright size-full wp-image-283" title="Apple" src="http://derekneely.com/wp-content/uploads/2009/06/apple.jpg" alt="" width="119" height="135" /></a>I recently picked  up one of the newly released MacBook Pros. If at all interested its awesome and FAST! Anyhow, I depend on MacFUSE and Macfusion daily to connect to various servers to knock out some development. Well, low and behold, mounting via SSH wasn&#8217;t working again (didn&#8217;t try FTP).</p>
<p>Now, I have another fix for MacFUSE/Macfusion <a title="MacFUSE fix for Snow Leopard" href="http://derekneely.com/2009/08/macfuse-fix-for-snow-leopard/" target="_blank">here</a>, but unfortunately this did not work for the latest release of MacFUSE on the new MacBooks.</p>
<p>So, after much searching and hunting I FINALLY came across the solution. There is an unofficial release of MacFUSE that lets all the goodness of Macfusion work with SSH. Apparently, there is an issue with MacFUSE and 64-bit kernels. Links and references below:</p>
<p>Build download: <a title="MacFUSE Build Download" href="http://www.tuxera.com/mac/macfuse-core-10.5-2.1.9.dmg" target="_blank">macfuse-core-10.5-2.1.9.dmg</a><br />
Source download: <a title="MacFUSE Source Download" href="http://www.tuxera.com/mac/macfuse-rebel-2.1.9-src.tar.bz2" target="_blank">macfuse-rebel-2.1.9-src.tar.bz2</a></p>
<p>Local build download: <a title="MacFUSE Build Download" href="http://derekneely.com/Downloads/MacFUSE/macfuse-core-10.5-2.1.9.dmg" target="_blank">macfuse-core-10.5-2.1.9.dmg</a><br />
Local source download: <a title="MacFUSE Source Download" href="http://derekneely.com/Downloads/MacFUSE/macfuse-rebel-2.1.9-src.tar.bz2">macfuse-rebel-2.1.9-src.tar.bz2</a></p>
<p>Solution source: <a title="Google Groups - MacFUSE Fix" href="http://groups.google.com/group/macfuse/browse_thread/thread/f72982535ec44629" target="_blank">Google Groups</a></p>
]]></content:encoded>
			<wfw:commentRss>http://derekneely.com/2011/04/macfusemacfusion-fix-for-newer-macs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ubuntu 10.04 USB Lock-Ups</title>
		<link>http://derekneely.com/2010/07/ubuntu-10-04-usb-lock-ups/</link>
		<comments>http://derekneely.com/2010/07/ubuntu-10-04-usb-lock-ups/#comments</comments>
		<pubDate>Sat, 24 Jul 2010 17:39:18 +0000</pubDate>
		<dc:creator>derek</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Freeze]]></category>
		<category><![CDATA[Lock-up]]></category>
		<category><![CDATA[System]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[USB]]></category>

		<guid isPermaLink="false">http://derekneely.com/?p=589</guid>
		<description><![CDATA[I recently installed Ubuntu 10.04 LTS on one of my desktop PCs here at home. Love Ubuntu. Easy to use, very compatible with most devices, good plug and play. Don&#8217;t get me wrong (for those hardcore Linux folks) I like tinkering with Linux as much as anyone, but I also have work to get done. [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://derekneely.com/wp-content/uploads/2010/07/ubuntu_icon.png"><img class="alignright size-full wp-image-588" title="Ubuntu" src="http://derekneely.com/wp-content/uploads/2010/07/ubuntu_icon.png" alt="" width="143" height="143" /></a>I recently installed Ubuntu 10.04 LTS on one of my desktop PCs here at home. Love Ubuntu. Easy to use, very compatible with most devices, good plug and play. Don&#8217;t get me wrong (for those hardcore Linux folks) I like tinkering with Linux as much as anyone, but I also have work to get done. Fighting for hours getting dual monitors or the right drivers working keeps me from getting that work done. Ok, sorry for the quick rant, back to the subject.</p>
<p>I noticed after installation when I would go to start plugging in some of my external devices via USB the dang thing would lock up on me. That is, desktop completely frozen, unable to remotely ssh into the box, just plain dead.</p>
<p>So, I tried various things and what have you and nothing appeared to help.</p>
<p>My solution was:</p>
<blockquote><p>apt-get remove modemmanager</p></blockquote>
<p>Simple as that. I haven&#8217;t had any lock-ups, system has been up for several days and I&#8217;ve been able to add my alfa wireless and my magic jack to the box without any crashes. Hope this may help you too!</p>
]]></content:encoded>
			<wfw:commentRss>http://derekneely.com/2010/07/ubuntu-10-04-usb-lock-ups/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Custom User-Agent Safari</title>
		<link>http://derekneely.com/2010/06/custom-user-agent-safari/</link>
		<comments>http://derekneely.com/2010/06/custom-user-agent-safari/#comments</comments>
		<pubDate>Wed, 09 Jun 2010 18:43:12 +0000</pubDate>
		<dc:creator>derek</dc:creator>
				<category><![CDATA[Mac]]></category>
		<category><![CDATA[Google Bot]]></category>
		<category><![CDATA[Safari]]></category>
		<category><![CDATA[User-Agent]]></category>

		<guid isPermaLink="false">http://derekneely.com/?p=568</guid>
		<description><![CDATA[Safari offers a pretty nice Developer toolbar (once enabled under Safari-&#62;Preferences-&#62;Advanced-&#62;Show develop menu&#8230;). As part of the developer toolbar they offer a User-Agent switcher to allow you to seemingly be using a different browser. Now, if you&#8217;re familiar with the User-Agent Switcher on Firefox, you know you can add additional/custom user agents. However, Safari doesn&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-full wp-image-283" title="Apple" src="http://derekneely.com/wp-content/uploads/2009/06/apple.jpg" alt="Apple" width="124" height="140" />Safari offers a pretty nice Developer toolbar (once enabled under Safari-&gt;Preferences-&gt;Advanced-&gt;Show develop menu&#8230;). As part of the developer toolbar they offer a User-Agent switcher to allow you to seemingly be using a different browser. Now, if you&#8217;re familiar with the User-Agent Switcher on Firefox, you know you can add additional/custom user agents. However, Safari doesn&#8217;t make it as easy to add additional/custom agents. Rest assured, there is still away.</p>
<p>The file you will be looking for is:</p>
<blockquote><p>/Applications/Safari.app/Contents/Resources/UserAgent.plist</p></blockquote>
<p>What I have done is copy this file off to my home directory. Open the file with the Property List Editor (provided with Apple&#8217;s developer tools). I will add 2 entries into this file. One to give a nice divider for my custom agents and another for the Google Bot Agent.</p>
<p><strong>For the divider:</strong></p>
<ol>
<li>Select the last &#8216;Item&#8217; (be sure the &#8216;Item&#8217; is not expanded) and click the &#8216;+&#8217; sign to add a new &#8216;Item&#8217;</li>
<li>Change this &#8216;Item&#8217; to a &#8216;Dictionary&#8217; under the &#8216;Type&#8217; column.</li>
<li>Expand this &#8216;Item&#8217; and press the &#8216;Add sub-item button&#8217; (replaced the &#8216;+&#8217; sign after expanding)</li>
<li>Rename this sub-item&#8217;s key to &#8216;separator&#8217;, change the type to Boolean, and select the Value checkbox.</li>
</ol>
<p><img class="alignnone size-full wp-image-574" title="User-Agent Separator Config" src="http://derekneely.com/wp-content/uploads/2010/06/Screen-shot-2010-06-09-at-2.34.49-PM.png" alt="User-Agent Separator Config" width="599" height="37" /></p>
<p><strong>For the new User-Agent:</strong></p>
<ol>
<li>Add a new &#8216;Item&#8217; as you did in step 1 above.</li>
<li>Change this &#8216;Item&#8217; to a &#8216;Dictionary&#8217; under the &#8216;Type&#8217; column.</li>
<li>Expand this &#8216;Item&#8217; and press the &#8216;Add sub-item button&#8217; (replaced the &#8216;+&#8217; sign after expanding) 4 times.</li>
<li>Set the key, type, value for each as follows:</li>
</ol>
<ul>
<blockquote>
<li>name, String, Google Bot</li>
<li>version, String, 2.1</li>
<li>platform, String, Mac (not sure if this matters or not)</li>
<li>user-agent, String, Googlebot/2.1 (+http://www.google.com/bot.html)</li>
</blockquote>
</ul>
<p><img class="alignnone size-full wp-image-577" title="User-Agent Custom Config" src="http://derekneely.com/wp-content/uploads/2010/06/Screen-shot-2010-06-09-at-2.35.31-PM.png" alt="User-Agent Custom Config" width="643" height="89" /></p>
<p>Save this file. Quit Safari. Replace the original with the new one.</p>
<blockquote><p>$ sudo su -</p>
<p># rm /Applications/Safari.app/Contents/Resources/UserAgents.plist</p>
<p># cp /Users/derek/UserAgents.plist /Applications/Safari.app/Contents/Resources/</p></blockquote>
<p>Fire Safari back up and there you have it. A new custom user-agent. Repeat as necessary to add more.</p>
<p><img class="alignnone size-full wp-image-583" title="User-Agent Menu" src="http://derekneely.com/wp-content/uploads/2010/06/Screen-shot-2010-06-09-at-2.46.07-PM.png" alt="User-Agent Menu" width="545" height="551" /></p>
]]></content:encoded>
			<wfw:commentRss>http://derekneely.com/2010/06/custom-user-agent-safari/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Site Posting Hiatus</title>
		<link>http://derekneely.com/2010/05/site-posting-hiatus/</link>
		<comments>http://derekneely.com/2010/05/site-posting-hiatus/#comments</comments>
		<pubDate>Wed, 26 May 2010 15:22:31 +0000</pubDate>
		<dc:creator>derek</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://derekneely.com/?p=550</guid>
		<description><![CDATA[Wow, I made it by my own blog today and realized I haven&#8217;t been around in quite some time. I&#8217;ve been quite busy working on a startup company &#8211; Blue Shoe Mobile Solutions. Check us out! Also, since my last post I&#8217;ve had several apps go into the store. Check them out! I&#8217;ll be back soon! [...]]]></description>
			<content:encoded><![CDATA[<p>Wow, I made it by my own blog today and realized I haven&#8217;t been around in quite some time. I&#8217;ve been quite busy working on a startup company &#8211; <a title="Blue Shoe Mobile Solutions" href="http://blueshoemobile.com/" target="_blank">Blue Shoe Mobile Solutions</a>. Check us out!</p>
<p>Also, since my last post I&#8217;ve had several apps go into the store. Check them out!</p>
<p><a title="iGetloaded" href="http://itunes.apple.com/us/artist/getloaded-com/id355498190" target="_blank"><img class="alignleft size-full wp-image-555" title="Getloaded-AppIcon" src="http://derekneely.com/wp-content/uploads/2010/05/Getloaded-AppIcon.png" alt="Getloaded-AppIcon" width="72" height="71" /></a> <a title="Big-A*s Sandwiches" href="http://itunes.apple.com/us/artist/blue-shoe-mobile-solutions/id363992961" target="_blank"><img class="alignnone size-full wp-image-553" title="BigAssSandwiches-AppIcon" src="http://derekneely.com/wp-content/uploads/2010/05/BigAssSandwiches-AppIcon.png" alt="BigAssSandwiches-AppIcon" width="74" height="73" /></a> <a title="Valentino's" href="http://itunes.apple.com/us/artist/blue-shoe-mobile-solutions/id363992961" target="_blank"><img class="alignnone size-full wp-image-557" title="Valentinos-AppIcon" src="http://derekneely.com/wp-content/uploads/2010/05/Valentinos-AppIcon.png" alt="Valentinos-AppIcon" width="74" height="70" /></a> <a title="Vesuvio Bay Ridge" href="http://itunes.apple.com/us/artist/blue-shoe-mobile-solutions/id363992961" target="_blank"><img class="alignnone size-full wp-image-558" title="Vesuvio-AppIcon" src="http://derekneely.com/wp-content/uploads/2010/05/Vesuvio-AppIcon.png" alt="Vesuvio-AppIcon" width="71" height="71" /></a> <a title="Sticky Rice" href="http://itunes.apple.com/us/artist/blue-shoe-mobile-solutions/id363992961" target="_blank"><img class="alignnone size-full wp-image-556" title="StickyRice-AppIcon" src="http://derekneely.com/wp-content/uploads/2010/05/StickyRice-AppIcon.png" alt="StickyRice-AppIcon" width="68" height="71" /></a> <a title="Gator's Sports Grille" href="http://itunes.apple.com/us/artist/blue-shoe-mobile-solutions/id363992961" target="_blank"><img class="alignnone size-full wp-image-554" title="GatorsSportsBar-AppIcon" src="http://derekneely.com/wp-content/uploads/2010/05/GatorsSportsBar-AppIcon.png" alt="GatorsSportsBar-AppIcon" width="71" height="69" /></a></p>
<p>I&#8217;ll be back soon! Got a ton going on and more apps coming out daily. I&#8217;m now moving into the Android Universe as well, to port the above apps over. Feel free to contact me if you have any specific questions or inquiries at me@derekneely.com.</p>
]]></content:encoded>
			<wfw:commentRss>http://derekneely.com/2010/05/site-posting-hiatus/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone &#8211; UITableViewCell Custom Selection Style Color</title>
		<link>http://derekneely.com/2010/01/uitableviewcell-custom-selection-style-color/</link>
		<comments>http://derekneely.com/2010/01/uitableviewcell-custom-selection-style-color/#comments</comments>
		<pubDate>Fri, 15 Jan 2010 04:16:59 +0000</pubDate>
		<dc:creator>derek</dc:creator>
				<category><![CDATA[Mac]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Custom UITableView]]></category>
		<category><![CDATA[Custom UITableViewCell]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[Selection Style]]></category>
		<category><![CDATA[Selection Style Color]]></category>
		<category><![CDATA[UITableView]]></category>
		<category><![CDATA[UITableViewCell]]></category>
		<category><![CDATA[UITableViewCellSelectionStyle]]></category>

		<guid isPermaLink="false">http://derekneely.com/?p=516</guid>
		<description><![CDATA[Oddly, Apple has given you the ability to vastly customize the primary view of  a UITableViewCell. However, the selection style view is much more difficult to do such. Apple kindly gave us UITableViewSelectionStyleBlue/Gray/None. Well, that doesn&#8217;t always cut it does it? There are already some very good tutorials on revamping the whole table view.  Google [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-full wp-image-479" title="xcode-icon" src="http://derekneely.com/wp-content/uploads/2009/11/xcode-icon.png" alt="xcode-icon" width="154" height="154" />Oddly, Apple has given you the ability to vastly customize the primary view of  a UITableViewCell. However, the selection style view is much more difficult to do such. Apple kindly gave us UITableViewSelectionStyleBlue/Gray/None. Well, that doesn&#8217;t always cut it does it?</p>
<p>There are already some very good tutorials on revamping the whole table view.  <a title="Google - Custom UITableView" href="http://www.google.com/search?q=custom+uitableview&amp;ie=utf-8&amp;oe=utf-8&amp;aq=t&amp;rls=org.mozilla:en-US:official&amp;client=firefox-a" target="_blank">Google it!</a> The best I came across was from <a title="Cocoa with Love - Custom UITableView" href="http://cocoawithlove.com/2009/04/easy-custom-uitableview-drawing.html" target="_blank">Cocoa with Love &#8211; Custom UITableView</a>.</p>
<p>However, this can be a bit overkill for some situations. It can also take a good bit of time to setup all the necessary images. What I needed was a quick and easy way to &#8216;theme&#8217; the application and thus the selection style for a UITableViewCell. This needed to work with both plain and grouped table view styles and custom cells as well. You can see now why this may take  a while using the above methods.</p>
<p>Here is a quick and easy method to do just that.</p>
<p><strong>SomeViewController.h</strong></p>
<pre>#import &lt;UIKit/UIKit.h&gt;

@interface SomeViewController : UITableViewController {
     UITableViewCell *currentSelectedCell;
}

@property (nonatomic, retain) UITableViewCell *currentSelectedCell;

- (void)setSelectedCell:(UITableViewCell *)selectedCell
     deselectedCell:(UITableViewCell *)deselectedCell;

@end</pre>
<p><strong>SomeViewController.m</strong></p>
<pre>#import "SomeViewController.h"

@implementation SomeViewController

@synthesize currentSelectedCell;

- (void)setSelectedCell:(UITableViewCell *)selectedCell deselectedCell:(UITableViewCell *)deselectedCell {
     //revert deselected cell
     if (deselectedCell != nil) {
          deselectedCell.backgroundColor = [UIColor whiteColor];
          for (UIView *subView in [deselectedCell.contentView subviews]) {
               if ([subView isKindOfClass:[UILabel class]]) {
                    UILabel *label = (UILabel *)subView;
                    label.textColor = [UIColor blackColor];
               }

               if ([subView isKindOfClass:[UITextField class]]) {
                    UITextField *textField = (UITextField *)subView;
                    textField.textColor = [UIColor blackColor];
               }
          }
     }

     //setup selected cell
     selectedCell.backgroundColor = [UIColor redColor]; //Some defined UIColor
     for (UIView *subView in [selectedCell.contentView subviews]) {
          if ([subView isKindOfClass:[UILabel class]]) {
               UILabel *label = (UILabel *)subView;
               label.textColor = [UIColor whiteColor];
          }

          if ([subView isKindOfClass:[UITextField class]]) {
               UITextField *textField = (UITextField *)subView;
               textField.textColor = [UIColor whiteColor];
          }
     }
}

#pragma mark -
#pragma mark Table View Delegate Methods

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:
     (NSIndexPath *)indexPath {

     setSelectedCell:[tableView cellForRowAtIndexPath:indexPath]
          deselectedCell:currentSelectedCell];

     currentSelectedCell = [tableView cellForRowAtIndexPath:indexPath];
}

#pragma mark -
#pragma mark Table View Data Source Methods

- (UITableViewCell *)tableView:(UITableView *)tableView
     cellForRowAtIndexPath:(NSIndexPath *)indexPath {

     //........Setup UITableViewCell...........//

     cell.selectionStyle = UITableViewCellSelectionStyleNone;

     return cell;
}

- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:
     (NSInteger)section {

     return count;
}

@end</pre>
<p>Now, I&#8217;ve provided this in one class but what I&#8217;ve done is setup an &#8216;application&#8217; singleton that has this function and is called from each UITableView&#8217;s didSelectRowAtIndexPath delegate. Works great on standard, custom, plain, and grouped views.</p>
]]></content:encoded>
			<wfw:commentRss>http://derekneely.com/2010/01/uitableviewcell-custom-selection-style-color/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone Development &#8211; Continuous Picker</title>
		<link>http://derekneely.com/2009/12/iphone-development-continuous-picker/</link>
		<comments>http://derekneely.com/2009/12/iphone-development-continuous-picker/#comments</comments>
		<pubDate>Thu, 31 Dec 2009 21:42:21 +0000</pubDate>
		<dc:creator>derek</dc:creator>
				<category><![CDATA[Mac]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Continuous Picker]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Picker]]></category>

		<guid isPermaLink="false">http://derekneely.com/?p=513</guid>
		<description><![CDATA[Coming soon&#8230;been hard at work on some projects.]]></description>
			<content:encoded><![CDATA[<p>Coming soon&#8230;been hard at work on some projects.</p>
]]></content:encoded>
			<wfw:commentRss>http://derekneely.com/2009/12/iphone-development-continuous-picker/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone Development &#8211; Global Variables (Singleton)</title>
		<link>http://derekneely.com/2009/11/iphone-development-global-variables/</link>
		<comments>http://derekneely.com/2009/11/iphone-development-global-variables/#comments</comments>
		<pubDate>Fri, 06 Nov 2009 15:20:41 +0000</pubDate>
		<dc:creator>derek</dc:creator>
				<category><![CDATA[Mac]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[App Delegate]]></category>
		<category><![CDATA[Global]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[Singleton]]></category>
		<category><![CDATA[Variables]]></category>

		<guid isPermaLink="false">http://derekneely.com/?p=480</guid>
		<description><![CDATA[In iPhone development, if/when you need a single instance of a variable that can be shared and manipulated where and how should you implement this. Thus far I have found 2 ways of doing so. The first would be to add the global variables to your AppDelegate (which can be done and will be explained [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-full wp-image-479" title="xcode-icon" src="http://derekneely.com/wp-content/uploads/2009/11/xcode-icon.png" alt="xcode-icon" width="143" height="143" />In iPhone development, if/when you need a single instance of a variable that can be shared and manipulated where and how should you implement this. Thus far I have found 2 ways of doing so. The first would be to add the global variables to your AppDelegate (which can be done and will be explained but isn&#8217;t the preferred method). The second and &#8216;correct&#8217; way of going about globals is to create a Singleton.</p>
<p>For the following examples we will assume the global variable you are trying to implement is a User object.</p>
<p>User.h</p>
<blockquote>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #df0002;"><span style="color: #7d4726;">#import </span>&lt;Foundation/Foundation.h&gt;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;">
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;"><span style="color: #c900a4;">@interface</span> User : NSObject {</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #7a0eac;"><span style="color: #000000;"><span style="white-space: pre;"> </span></span>NSString<span style="color: #000000;"><span style="white-space: pre;"> </span>*</span><span style="color: #438288;">username</span><span style="color: #000000;">;</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #7a0eac;"><span style="color: #000000;"><span style="white-space: pre;"> </span></span>NSString<span style="color: #000000;"><span style="white-space: pre;"> </span>*</span><span style="color: #438288;">password</span><span style="color: #000000;">;</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #008d00;"><span style="color: #000000;"><span style="white-space: pre;"> </span></span><span style="color: #7a0eac;">NSString</span><span style="color: #000000;"><span style="white-space: pre;"> </span>*</span><span style="color: #438288;">accountType</span><span style="color: #000000;">; </span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;">}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;">
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;"><span style="color: #c900a4;">@property</span> (<span style="color: #c900a4;">nonatomic</span>, <span style="color: #c900a4;">retain</span>) NSString *username;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;"><span style="color: #c900a4;">@property</span> (<span style="color: #c900a4;">nonatomic</span>, <span style="color: #c900a4;">retain</span>) NSString *password;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;"><span style="color: #c900a4;">@property</span> (<span style="color: #c900a4;">nonatomic</span>, <span style="color: #c900a4;">retain</span>) NSString *accountType;</p>
</blockquote>
<p>User.m</p>
<blockquote>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #7d4726;">#import <span style="color: #df0002;">&#8220;User.h&#8221;</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;">
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #c900a4;">@implementation<span style="color: #000000;"> User</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;">
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #c900a4;">@synthesize<span style="color: #000000;"> username;</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #c900a4;">@synthesize<span style="color: #000000;"> password;</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;"><span style="color: #c900a4;">@synthesize</span> accountType;</p>
</blockquote>
<hr /><strong>App Delegate Method</strong></p>
<p>ApplicationAppDelegate.h</p>
<blockquote>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #7d4726;">#import <span style="color: #df0002;">&#8220;User.h&#8221;</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #7d4726;"><span style="color: #df0002;"><br />
</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;"><span style="color: #c900a4;">@interface</span> ApplicationAppDelegate : NSObject &lt;UIApplicationDelegate&gt; {</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;">
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #7a0eac;"><span style="color: #000000;"> </span>NSManagedObjectModel<span style="color: #000000;"> *</span><span style="color: #438288;">managedObjectModel</span><span style="color: #000000;">;</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #7a0eac;"><span style="color: #000000;"> </span>NSManagedObjectContext<span style="color: #000000;"> *</span><span style="color: #438288;">managedObjectContext</span><span style="color: #000000;">;<span style="white-space: pre;"> </span> </span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #7a0eac;"><span style="color: #000000;"> </span>NSPersistentStoreCoordinator<span style="color: #000000;"> *</span><span style="color: #438288;">persistentStoreCoordinator</span><span style="color: #000000;">;</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;">
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #7a0eac;"><span style="color: #000000;"> </span>UIWindow<span style="color: #000000;"> *</span><span style="color: #438288;">window</span><span style="color: #000000;">;</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #7a0eac;">
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;"><span style="color: #438288;">User</span> *user;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;">}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;">
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;"><span style="color: #c900a4;">@property</span> (<span style="color: #c900a4;">nonatomic</span>, <span style="color: #c900a4;">retain</span>, <span style="color: #c900a4;">readonly</span>) NSManagedObjectModel *managedObjectModel;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;"><span style="color: #c900a4;">@property</span> (<span style="color: #c900a4;">nonatomic</span>, <span style="color: #c900a4;">retain</span>, <span style="color: #c900a4;">readonly</span>) NSManagedObjectContext *managedObjectContext;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;"><span style="color: #c900a4;">@property</span> (<span style="color: #c900a4;">nonatomic</span>, <span style="color: #c900a4;">retain</span>, <span style="color: #c900a4;">readonly</span>) NSPersistentStoreCoordinator *persistentStoreCoordinator;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;">
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #c900a4;">@property<span style="color: #000000;"> (</span>nonatomic<span style="color: #000000;">, </span>retain<span style="color: #000000;">) </span>IBOutlet<span style="color: #000000;"> UIWindow *window;</span></p>
<div><span style="font-family: Menlo, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: small;"><span style="line-height: normal;"> </span></span></div>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #c900a4;">@property<span style="color: #000000;"> (</span>nonatomic<span style="color: #000000;">, </span>retain<span style="color: #000000;">) User *user;</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #c900a4;"><span style="color: #000000;"><br />
</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #c900a4;">
</blockquote>
<p>ApplicationAppDelegate.m</p>
<blockquote>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #df0002;"><span style="color: #7d4726;">#import </span>&#8220;ApplicationAppDelegate.h&#8221;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;">
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;"><span style="color: #c900a4;">@implementation</span> ApplicationAppDelegate</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;">
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #c900a4;">@synthesize<span style="color: #000000;"> window;</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;"><span style="color: #c900a4;">@synthesize</span> user;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;">
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #7d4726;">#pragma mark -</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #7d4726;">#pragma mark Application lifecycle</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;">
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;">- (<span style="color: #c900a4;">void</span>)applicationDidFinishLaunching:(<span style="color: #7a0eac;">UIApplication</span> *)application {</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #438288;"><span style="color: #000000;"> [</span>window<span style="color: #000000;"> </span><span style="color: #450084;">addSubview</span><span style="color: #000000;">:</span>tabBarController<span style="color: #000000;">.</span><span style="color: #450084;">view</span><span style="color: #000000;">];</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;"><span style="white-space: pre;"> </span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #008d00;"><span style="color: #000000;"> </span>// Override point for customization after app launch</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #450084;"><span style="color: #000000;"><span style="white-space: pre;"> </span>[</span><span style="color: #438288;">window</span><span style="color: #000000;"> </span>makeKeyAndVisible<span style="color: #000000;">];</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #450084;">
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;"><span style="color: #c900a4;"> </span>user = [[<span style="color: #438288;">User</span> <span style="color: #450084;">alloc</span>] <span style="color: #450084;">init</span>];</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;">}</p>
</blockquote>
<p>Then from any view controller you can access the Delegate variable as such.</p>
<p>SomeViewController.m</p>
<blockquote>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #7a0eac;">UIApplication<span style="color: #000000;"> *app = [</span>UIApplication<span style="color: #000000;"> </span><span style="color: #450084;">sharedApplication</span><span style="color: #000000;">];</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #7a0eac;"><span style="color: #000000;">app.user.username = @&#8221;Username&#8221;;</span></p>
</blockquote>
<p>While this can be done and will work. The overall use of the AppDelegate for this functionality is incorrect. The AppDelegate should be used for the following 2 reasons:</p>
<ul style="padding-left: 26px;">
<li>implemenations of the <code style="font-family: Courier, monospace; font-size: 12px;">NSApplication</code> delegate methods (including<code style="font-family: Courier, monospace; font-size: 12px;">applicationDidFinishLaunching:</code> to finalize application construction)</li>
<li>handling menu items for items that don&#8217;t exist in a window (for example, opening the application Preferences window)</li>
</ul>
<p>So, on that note, lets implement a Singleton. The &#8216;correct&#8217; way of creating a single global instance of an object that can be accessed and manipulated by the view controllers.</p>
<hr /><strong>Singleton Method</strong></p>
<p>First we need to make some changes to our User class as such:</p>
<p>User.h</p>
<blockquote>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #df0002;"><span style="color: #7d4726;">#import </span>&lt;Foundation/Foundation.h&gt;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;">
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;"><span style="color: #c900a4;">@interface</span> User : NSObject {</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #7a0eac;"><span style="color: #000000;"><span style="white-space: pre;"> </span></span>NSString<span style="color: #000000;"><span style="white-space: pre;"> </span>*</span><span style="color: #438288;">username</span><span style="color: #000000;">;</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #7a0eac;"><span style="color: #000000;"><span style="white-space: pre;"> </span></span>NSString<span style="color: #000000;"><span style="white-space: pre;"> </span>*</span><span style="color: #438288;">password</span><span style="color: #000000;">;</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #008d00;"><span style="color: #000000;"><span style="white-space: pre;"> </span></span><span style="color: #7a0eac;">NSString</span><span style="color: #000000;"><span style="white-space: pre;"> </span>*</span><span style="color: #438288;">accountType</span><span style="color: #000000;">;</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;">}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;">
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;"><span style="color: #c900a4;">@property</span> (<span style="color: #c900a4;">nonatomic</span>, <span style="color: #c900a4;">retain</span>) NSString *username;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;"><span style="color: #c900a4;">@property</span> (<span style="color: #c900a4;">nonatomic</span>, <span style="color: #c900a4;">retain</span>) NSString *password;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;"><span style="color: #c900a4;">@property</span> (<span style="color: #c900a4;">nonatomic</span>, <span style="color: #c900a4;">retain</span>) NSString *accountType;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;">
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;">+ (<span style="color: #438288;">User</span> *)sharedUser;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;">
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #c900a4;">@end</p>
</blockquote>
<p>User.m</p>
<blockquote>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #7d4726;">#import <span style="color: #df0002;">&#8220;User.h&#8221;</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;">
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;"><span style="color: #c900a4;">static</span> User *sharedUser = <span style="color: #c900a4;">nil</span>;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;">
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #c900a4;">@implementation<span style="color: #000000;"> User</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;">
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #c900a4;">@synthesize<span style="color: #000000;"> username;</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #c900a4;">@synthesize<span style="color: #000000;"> password;</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;"><span style="color: #c900a4;">@synthesize</span> accountType;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;">
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #7d4726;">#pragma mark -</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #7d4726;">#pragma mark Singleton Methods</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;">
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;">+ (<span style="color: #438288;">User</span> *)sharedUser {</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #438288;"><span style="color: #000000;"><span style="white-space: pre;"> </span></span><span style="color: #c900a4;">if</span><span style="color: #000000;">(</span>sharedUser<span style="color: #000000;"> == </span><span style="color: #c900a4;">nil</span><span style="color: #000000;">){</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #450084;"><span style="color: #000000;"><span style="white-space: pre;"> </span></span><span style="color: #438288;">sharedUser</span><span style="color: #000000;"> = [[</span><span style="color: #c900a4;">super</span><span style="color: #000000;"> </span>allocWithZone<span style="color: #000000;">:</span><span style="color: #c900a4;">NULL</span><span style="color: #000000;">] </span>init<span style="color: #000000;">];</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;"><span style="white-space: pre;"> </span>}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;">
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #438288;"><span style="color: #000000;"><span style="white-space: pre;"> </span></span><span style="color: #c900a4;">return</span><span style="color: #000000;"> </span>sharedUser<span style="color: #000000;">;</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;">}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;">
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;">+ (<span style="color: #c900a4;">id</span>)allocWithZone:(<span style="color: #7a0eac;">NSZone</span> *)zone {</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #275a5e;"><span style="color: #000000;"><span style="white-space: pre;"> </span></span><span style="color: #c900a4;">return</span><span style="color: #000000;"> [[</span><span style="color: #c900a4;">self</span><span style="color: #000000;"> </span>sharedManager<span style="color: #000000;">] </span><span style="color: #450084;">retain</span><span style="color: #000000;">];</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;">}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;">
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;">- (<span style="color: #c900a4;">id</span>)copyWithZone:(<span style="color: #7a0eac;">NSZone</span> *)zone {</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #c900a4;"><span style="color: #000000;"><span style="white-space: pre;"> </span></span>return<span style="color: #000000;"> </span>self<span style="color: #000000;">;</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;">}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;">
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;">- (<span style="color: #c900a4;">id</span>)retain {</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #c900a4;"><span style="color: #000000;"><span style="white-space: pre;"> </span></span>return<span style="color: #000000;"> </span>self<span style="color: #000000;">;</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;">}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;">
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;">- (<span style="color: #c900a4;">unsigned</span>)retainCount {</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #7d4726;"><span style="color: #c900a4;"> return</span><span style="color: #000000;"> </span>NSUIntegerMax<span style="color: #000000;">;</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;">}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;">
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;">- (<span style="color: #c900a4;">void</span>)release {</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #008d00;">//do nothing</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;">}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;">
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;">- (<span style="color: #c900a4;">id</span>)autorelease {</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #c900a4;"><span style="color: #000000;"><span style="white-space: pre;"> </span></span>return<span style="color: #000000;"> </span>self<span style="color: #000000;">;</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;">}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;">
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #c900a4;">@end</p>
</blockquote>
<p>Now, in any view controller we need to access/manipulate the &#8216;global&#8217; user we can do:</p>
<p>SomeViewController.m</p>
<blockquote>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #df0002;"><span style="color: #7d4726;">#import </span>&#8220;SomeViewController.h&#8221;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #7d4726;">#import <span style="color: #df0002;">&#8220;User.h&#8221;</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;">
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #c900a4;">@implementation<span style="color: #000000;"> SomeViewController</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;">
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;">- (<span style="color: #c900a4;">void</span>)someFunction{</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #438288;"><span style="color: #000000;"><span style="white-space: pre;"> </span></span>User<span style="color: #000000;"> *</span>user<span style="color: #000000;"> = [</span>User<span style="color: #000000;"> </span><span style="color: #275a5e;">sharedUser</span><span style="color: #000000;">];</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #438288;"><span style="color: #000000;"><span style="white-space: pre;"> </span></span>user<span style="color: #000000;">.</span>username<span style="color: #000000;"> = </span><span style="color: #df0002;">@&#8221;Username&#8221;</span><span style="color: #000000;">;</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;">}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;">
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #c900a4;">@end</p>
</blockquote>
<p>References and resources that made this post and my learning possible.</p>
<ul>
<li><a title="Cocoa Fundamentals Guide" href="http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/CocoaFundamentals/CocoaObjects/CocoaObjects.html" target="_blank">Cocoa&#8217;s Fundamentals Guide</a> (by Apple)</li>
<li><a title="Cocoa With Love" href="http://cocoawithlove.com/2008/11/singletons-appdelegates-and-top-level.html" target="_blank">Cocoa With Love</a></li>
<li><a title="Matt Galloway" href="http://iphone.galloway.me.uk/iphone-sdktutorials/singleton-classes/" target="_blank">Matt Galloway</a></li>
<li><a title="Stack Overflow" href="http://stackoverflow.com/questions/338734/iphone-proper-usage-of-application-delegate" target="_blank">Stack Overflow</a></li>
</ul>
<p>- Updated: 11.17.09 &#8211; Reviewed Apple&#8217;s documentation on singletons and made the proper changes. <a title="Apple's Singleton Documentation" href="http://developer.apple.com/iphone/library/DOCUMENTATION/General/Conceptual/DevPedia-CocoaCore/Singleton.html" target="_blank">Apple&#8217;s Singleton Documentation</a></p>
]]></content:encoded>
			<wfw:commentRss>http://derekneely.com/2009/11/iphone-development-global-variables/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nginx (Mini How-to)</title>
		<link>http://derekneely.com/2009/10/nginx-mini-how-to/</link>
		<comments>http://derekneely.com/2009/10/nginx-mini-how-to/#comments</comments>
		<pubDate>Fri, 30 Oct 2009 19:40:02 +0000</pubDate>
		<dc:creator>derek</dc:creator>
				<category><![CDATA[Networking]]></category>
		<category><![CDATA[Unix]]></category>
		<category><![CDATA[How-to]]></category>
		<category><![CDATA[Load balancer]]></category>
		<category><![CDATA[Nginx]]></category>

		<guid isPermaLink="false">http://derekneely.com/?p=440</guid>
		<description><![CDATA[Nginx (Engine-X) is a very light-weight powerful web proxy server and load balancer. This is a quick how-to on configuring a weighted load balancer using Nginx. I&#8217;ll skip past the installation on your system. Mine is currently running on an OpenBSD firewall using Packet Filter, and is how I will be covering the configuration. Nginx [...]]]></description>
			<content:encoded><![CDATA[<p><a title="Nginx Home Page" href="http://wiki.nginx.org/Main" target="_blank"><img class="alignright size-full wp-image-311" title="Nginx" src="http://derekneely.com/wp-content/uploads/2009/06/nginx-logo.png" alt="Nginx" width="245" height="63" />Nginx</a> (Engine-X) is a very light-weight powerful web proxy server and load balancer. This is a quick how-to on configuring a weighted load balancer using Nginx. I&#8217;ll skip past the installation on your system. Mine is currently running on an OpenBSD firewall using Packet Filter, and is how I will be covering the configuration. Nginx is available and work on both Unix and Linux.</p>
<p>Configuring Nginx to start on system boot:</p>
<blockquote><p># vi /etc/rc.local</p>
<pre># start nginx
if [ -x /usr/local/sbin/nginx ]; then
   echo -n ' nginx'; /usr/local/sbin/nginx
fi</pre>
</blockquote>
<p>Load balance configuration (one public ip -&gt; 3 private servers):</p>
<blockquote><p># vi /etc/nginx/nginx.conf</p>
<pre>user  nobody;
worker_processes  2;
worker_rlimit_nofile 10240;

error_log  /var/log/nginx/error.log;

events {
   worker_connections  8192;
}

http {

   upstream  site {
        server 192.168.1.100:80 max_fails=2 fail_timeout=15 weight=3;
        server 192.168.1.101:80 max_fails=2 fail_timeout=15 weight=3;
        server 192.168.1.102:80 max_fails=2 fail_timeout=15 weight=1;
   }

   upstream  site_ssl {
        server 192.168.1.100:443 max_fails=2 fail_timeout=15 weight=3;
        server 192.168.1.101:443 max_fails=2 fail_timeout=15 weight=3;
        server 192.168.1.102:443 max_fails=2 fail_timeout=15 weight=1;
   }

   server {
        listen  AAA.BBB.CCC.DDD:80;

        location / {
             access_log off;
             proxy_connect_timeout 15;
             proxy_set_header Host $host;
             proxy_set_header X-Real-IP $remote_addr;
             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
             proxy_pass http://site;
        }
   }

   server {
        listen  AAA.BBB.CCC.DDD:443;

        ssl on;
        ssl_certificate /etc/ssl/ssl.cert/site.com.crt;
        ssl_certificate_key /etc/ssl/ssl.key/site.com.key;

        server_name site.com;

        location / {
             access_log off;
             proxy_connect_timeout 15;
             proxy_set_header Host $host;
             proxy_set_header X-Real-IP $remote_addr;
             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
             proxy_set_header X_FORWARDED_PROTO https;
             proxy_pass http://site_ssl;
        }
   }
}</pre>
</blockquote>
<p>Should you have a chain file you need to add it to the end of the certificate file as such:</p>
<blockquote><p># cat /path/to/chain.file &gt;&gt; /etc/ssl/ssl.cert/site.com.crt</p></blockquote>
<p>Packet Filter Firewall Rules:</p>
<blockquote><p># vi /etc/pf.conf</p>
<pre>site_ext="AAA.BBB.CCC.DDD"
site_int1="192.168.1.100"
site_int2="192.168.1.101"
site_int3="192.168.1.102"

pass in quick log on $ext_if inet proto tcp from any to $site_ext port 80 keep state
pass in quick log on $ext_if inet proto tcp from any to $corp_ext port 443 keep state
pass out quick log on $int_if inet proto tcp from any to $site_int1 port 80 keep state
pass out quick log on $int_if inet proto tcp from any to $site_int1 port 443 keep state
pass out quick log on $int_if inet proto tcp from any to $site_int2 port 80 keep state
pass out quick log on $int_if inet proto tcp from any to $site_int2 port 443 keep state
pass out quick log on $int_if inet proto tcp from any to $site_int3 port 80 keep state
pass out quick log on $int_if inet proto tcp from any to $site_int3 port 443 keep state</pre>
</blockquote>
<p>Helpful Nginx server management commands:</p>
<p>Test Nginx Config file:</p>
<blockquote><p># nginx -t -c /etc/nginx/nginx.conf</p></blockquote>
<p>Restart Nginx server:</p>
<blockquote><p># kill -HUP `cat /var/run/nginx.pid`</p></blockquote>
<p>Stop Nginx server:</p>
<blockquote><p># kill -QUIT `cat /var/run/nginx.pid`</p></blockquote>
<p>If your like me and want to keep tabs on the load balancing (as in ipvsadm for Linux ldirectord) you can add a label to the end of each of your firewall rules:</p>
<blockquote><p>label &#8220;[some unique label for this rule]&#8221; (i.e. label &#8220;site-ext&#8221;)</p></blockquote>
<p>Then using pftop -v label you will see:</p>
<blockquote>
<pre>RULE LABEL           PKTS     BYTES     STATES MAX  ACTION   DIR
....
16   site-ext        867991   630495K   11833       Pass     In  ...
17   site-ext-ssl    29427    13315230  847         Pass     In  ...
18   site-int-1      13761450 6842062   813483      Pass     Out ...
19   site-int-1-ssl  234678   12345     12344       Pass     Out ...
....</pre>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://derekneely.com/2009/10/nginx-mini-how-to/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

