<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"><channel><atom:link rel="hub" href="http://tumblr.superfeedr.com/" xmlns:atom="http://www.w3.org/2005/Atom"/><description>I live in San Francisco. I like to build things and want to learn about everything. I have great friends who inspire me and push me beyond my comfort zone. These posts are a collection of lessons learned, stories and my reflections. 
Follow @DJCHUNG</description><title>DJ Chung: Always Learning</title><generator>Tumblr (3.0; @djchung)</generator><link>http://djchung.tumblr.com/</link><item><title>My First Fork: facebook-ios-sdk</title><description>&lt;p&gt;&lt;span&gt;Recently, I&amp;#8217;ve been making a more concerted effort to contribute to open source software. As someone who recently picked up &lt;a href="http://djchung.tumblr.com/post/38674745881/lifted" target="_blank"&gt;programming&lt;/a&gt;, besides my friends, OSS has been my best teacher. I can&amp;#8217;t tell you how many tutorials I&amp;#8217;ve gone through, how many hours I&amp;#8217;ve spent on &lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;a href="http://www.stackoverflow.com" target="_blank"&gt;StackOverflow&lt;/a&gt;&lt;span&gt; or how many libraries I&amp;#8217;ve used on my own projects I found on &lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;a href="http://www.github.com"&gt;Github&lt;/a&gt;&lt;span&gt;. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;On to my first fork. My friend &lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;a href="https://twitter.com/jordanmessina" target="_blank"&gt;Jordan&lt;/a&gt;&lt;span&gt; and I were talking about OSS and even though I&amp;#8217;ve open sourced some of my own software, I&amp;#8217;ve never contributed to a project. I told him I didn&amp;#8217;t even know where to start, or even how to do it. So we just searched &amp;#8220;iOS&amp;#8221; on Github and facebook&amp;#8217;s &lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;a href="http://github.com/facebook/facebook-ios-sdk" target="_blank"&gt;sdk&lt;/a&gt;&lt;span&gt; popped up. Jordan suggested contributing to facebook&amp;#8217;s iOS sdk. My response was, &amp;#8220;How the hell can I contrib&amp;#8230;wait.&amp;#8221;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;I had been playing around with the sdk last week and I had extended one of their samples - Facebook gives you some great examples and very detailed installation instructions on their &lt;a href="http://www.developers.facebook.com" target="_blank"&gt;developer site&lt;/a&gt;.&lt;span&gt; I wanted to include a search feature for &lt;/span&gt;&lt;span&gt;FriendPickerSample, a way to list all of your Facebook friends and select them to be used for invites, tagging, etc&lt;/span&gt;&lt;span&gt;. Interestingly enough, Facebook gives you a &lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;a href="http://developers.facebook.com/docs/howtos/add-search-to-friend-picker-using-ios-sdk/" target="_blank"&gt;tutorial&lt;/a&gt;&lt;span&gt; just for that. However, I wanted instant search, I wanted the search to update every time I typed in a letter. So I built it. It was actually very little code, I just had to implement one UISearchBarDelegate method and it worked! &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;I told Jordan about this and he thought this would be a good feature to add to the FriendPickerSample. I was a little hesitant because I was intimidated by the thought of trying to contribute to Facebook&amp;#8217;s sdk. Jordan suggested I email the maintainer and ask if he&amp;#8217;d be open to this contribution, &amp;#8220;they&amp;#8217;re people too.&amp;#8221; So I emailed &lt;a href="https://github.com/onebit" target="_blank"&gt;onebit&lt;/a&gt; about the feature and asked what his thoughts were - just a shot in the dark. Then, an hour later, I got a reply! It was probably the best email I could have received in that situation. He thought that the feature was &amp;#8220;Cool!&amp;#8221; and that it &amp;#8220;sounds like an improvement.&amp;#8221; He was very supportive and of course, he couldn&amp;#8217;t promise that the change would be accepted, but encouraged me to fork the repo and submit a pull request. &lt;/p&gt;
&lt;p&gt;I had never forked a repo in my life. It&amp;#8217;s not hard at all, but I just had never done it and I didn&amp;#8217;t know what the etiquette was for submitting a pull request. With Jordan&amp;#8217;s help, I forked the &lt;a href="https://github.com/djchung/facebook-ios-sdk" target="_blank"&gt;repo&lt;/a&gt;, added my feature and submitted a &lt;a href="https://github.com/facebook/facebook-ios-sdk/pull/521" target="_blank"&gt;pull request&lt;/a&gt;. My first fork and pull request! &lt;/p&gt;
&lt;p&gt;The combination of contributing to such a widely used sdk, onebits&amp;#8217; response and my first time contributing to another project was a rush. It felt like a blur, but I did learn a few things. &lt;span&gt;Jordan advised me to look at how Facebook&amp;#8217;s commit messages were structured so that I could format mine accordingly. This will help the maintainer easily understand what&amp;#8217;s going on. But I think the biggest lesson I learned was through a fear that I overcame. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;span&gt;&amp;#8220;They&amp;#8217;re people too.&amp;#8221; &lt;/span&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Jordan&amp;#8217;s comment resonated with me. I was really intimidated by the thought of trying to add to Facebook&amp;#8217;s sdk and emailing onebit. I haven&amp;#8217;t even been programming that long, who am I to do even try? My own insecurities about my programming skills were hindering me from even trying. But Jordan&amp;#8217;s encouragement and onebit&amp;#8217;s friendly response made me realize that I&amp;#8217;ve got nothing to lose. Maybe my pull request won&amp;#8217;t get accepted, maybe my code really isn&amp;#8217;t all that great and maybe I didn&amp;#8217;t do something correctly, but I did something I had never done before and took one more step forward in my programming journey. That&amp;#8217;s what matters. I know I have areas to work on as programmer, but I&amp;#8217;m learning and there&amp;#8217;s no reason for my own insecurities to stop me from trying something out of my comfort zone. With respect to my programming skills, I try to remind myself, it&amp;#8217;s not where you are now, but where you are going.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Notes:&lt;/p&gt;
&lt;p&gt;onebit was gracious enough to suggest that I email him with the pull request so that he&amp;#8217;d be able to look at it easily. I emailed him and though I haven&amp;#8217;t yet received a response, I&amp;#8217;m looking forward to his feedback.&lt;/p&gt;
&lt;p&gt;About the pull request, it&amp;#8217;s more than just a few lines of code than I mentioned. This is because in FriendPickerSample, the search bar isn&amp;#8217;t set up, so I had to include that per the howto I linked above. Also, I made the code iOS 4.x compatible so I couldn&amp;#8217;t take advantage of new methods available for iOS 5+, which added to the lines of code. &lt;/p&gt;
&lt;p&gt;There are so many great, free resources about programming, there are virtually no barriers if you own a computer and have internet access.&lt;span&gt; &lt;/span&gt;&lt;span&gt;It is truly the perfect time to learn how to code - just watch this&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;a href="http://www.youtube.com/watch?v=nKIu9yen5nc" target="_blank"&gt;video&lt;/a&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;from Code.org if you need any more convincing.&lt;/span&gt;&lt;span&gt; In my pursuit of programming, I have stood on the shoulders of giants and it motivates me to contribute. I think the computer science community is as close to a real life antithesis of the &lt;/span&gt;&lt;a href="http://en.wikipedia.org/wiki/Tragedy_of_the_commons" target="_blank"&gt;Tragedy of the Commons&lt;/a&gt;&lt;span&gt; as any.&lt;/span&gt;&lt;/p&gt;</description><link>http://djchung.tumblr.com/post/44155227113</link><guid>http://djchung.tumblr.com/post/44155227113</guid><pubDate>Wed, 27 Feb 2013 14:27:12 -0500</pubDate><category>open source software</category><category>facebook ios sdk</category></item><item><title>Three Pieces of Advice for Learning Algorithms for the First Time</title><description>&lt;p&gt;I just completed my &lt;a href="https://github.com/djchung/Algorithms/blob/master/inversion_count.rb" target="_blank"&gt;first programming assignment&lt;/a&gt; for my Algorithms course through &lt;a href="http://www.coursera.com" target="_blank"&gt;Coursera&lt;/a&gt; - &lt;span&gt;if you&amp;#8217;re looking to continue or supplement your education, I highly recommend Coursera, I&amp;#8217;ve been impressed with the quality of content and breadth of their course offerings.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Anyway, here are three pieces of advice if you&amp;#8217;re trying to learn algorithms for the first time like me.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;span&gt;1. Take a minute to stop and think&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;I know this sounds dumb and obvious, but since I&amp;#8217;ve been out of a school setting for about four years, I&amp;#8217;m used to just doing instead of taking a step back and deliberately planning out my next steps. Half the battle in solving a problem with algorithms is understanding the question. If you read a question and immediately race to your text editor to code up a solution, chances are, you don&amp;#8217;t fully grasp the question. More often than not, this leads to seemingly endless hours down a rabbit hole and trying to brute force your way to solve a problem. &lt;span&gt;These sorts of technical questions usually have nuances to them and these nuances are hints to solving the question. If you miss those hints, you&amp;#8217;re headed down the wrong path. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;strong&gt;2. Don&amp;#8217;t code, talk and write&lt;/strong&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Once you understand the problem, talk it out. Talking out the problem helps me be very explicit about my approach. If I start talking out my steps and get to a point where I can&amp;#8217;t even explain where to go myself, then I know I&amp;#8217;ve reached a dead end. Also, if you can, talk to another person, if someone isn&amp;#8217;t available, talk to yourself. I&amp;#8217;ve found that when I think to myself, I make connections or assumptions that glaze over details. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;When I was first trying to implement the &lt;a href="http://en.wikipedia.org/wiki/Mergesort" target="_blank"&gt;merge sort algorithm&lt;/a&gt;, I had a little trouble wrapping my head around recursion. I went to my roommate, &lt;a href="https://twitter.com/moseslee" target="_blank"&gt;Moses&lt;/a&gt;, and he was gracious enough to talk it out with me for about half an hour. We stepped through the call stack, wrote out examples and talked out different ways to view the algorithm. This was a huge help. I then wrote pseudo code of what we discussed and this helped cement what I had just learned. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;A good test to figure out if you actually understand something is if you can explain it out loud or write it down on a piece of paper. So before you start coding a solution, talk it out and write some pseudo code. You&amp;#8217;ll know if you have the solution if you can do these two things. Writing the code is the last step, the hard work of actually solving the problem is already done. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;span&gt;3. Don&amp;#8217;t plug and chug&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;When you actually get to coding the solution, check yourself that you don&amp;#8217;t get to the point where you&amp;#8217;re plugging and chugging, haphazardly coding in hopes of stumbling upon the solution. In the best case scenario, you&amp;#8217;ll use your pseudo code and it will flawlessly transfer to actual code, but this rarely happens, if ever. You&amp;#8217;ll run into snags. When you do, repeat steps one and two. Take a step back, talk and write it out. This will save time in the long run, trust me. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I fell victim of plugging and chugging when I was solving the &lt;a href="https://github.com/djchung/Algorithms/blob/master/inversion_count.rb" target="_blank"&gt;inversion count problem&lt;/a&gt; (the first programming question of Coursera&amp;#8217;s Algorithm class). I knew I had 95% of the problem figured out, but for some reason my counter was always wrong at the very last level of recursion. I printed out the counts at each iteration and everything was as expected except for the very last. Seeing the finish line, I just tried to change a few things here and there in hopes of figuring it out, I was programming by coincidence. I lost hours to this futile approach. I thought I&amp;#8217;d be able to quickly figure it out by trying a few random pieces of logic here and there instead of taking a minute and deliberately thinking about the problem. It wasn&amp;#8217;t until I stepped away from the code and talked out potential reasons why the counter screwed up at the last minute that I figured out what was wrong. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;What was wrong? One line of code. On an edge case, I mistakenly added to the counter items I had already accounted for. Once I deleted that line, my code solved the problem. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Interestingly enough, these three thoughts all apply to programming in general. When I first started to learn how to program, I thought it was all about writing code. Yes, that&amp;#8217;s a big part of it, but code itself is a tool. Programming and computer science is more about a way of thinking and an to approach to solving a problem. I&amp;#8217;d argue that real programming is the process leading up to actually writing a line of code. &lt;/span&gt;&lt;/p&gt;</description><link>http://djchung.tumblr.com/post/43162255838</link><guid>http://djchung.tumblr.com/post/43162255838</guid><pubDate>Fri, 15 Feb 2013 14:06:00 -0500</pubDate><category>algorithms</category><category>programming</category><category>coursera</category></item><item><title>Horizontal Navigation of View Controllers</title><description>&lt;p&gt;Horizontal navigation in iOS is an intuitive way to page through content, especially on a smaller screen, like the iPhone. There are some great apps out there that use it, like &lt;a href="https://itunes.apple.com/us/app/groupon/id352683833?mt=8" target="_blank"&gt;Groupon&lt;/a&gt; and &lt;a href="https://itunes.apple.com/us/app/gilt-on-the-go/id331804452?mt=8" target="_blank"&gt;Gilt&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;These apps do a great job of showing lots of great content seemingly all at once. The swipe gesture gives the user a quick and easy feeling of scanning through information. Then, once the user finds something she&amp;#8217;s interested in, she can drill down by interacting with the view displayed on the screen. This sort of navigation works great for Groupon and Gilt because their content can be categorized and each category has more granular details. &lt;/p&gt;
&lt;p&gt;I first implemented horizontal navigation when I was building &lt;a href="https://itunes.apple.com/us/app/picturemenu/id569680767?mt=8" target="_blank"&gt;PictureMenu&lt;/a&gt;. When I was doing some research, I came across Apple&amp;#8217;s example that used horizontal navigation, &lt;a href="http://developer.apple.com/library/ios/#samplecode/PageControl/Listings/Classes_iPhone_PhoneContentController_m.html" target="_blank"&gt;PageControl&lt;/a&gt;. &lt;span&gt;Basically, you create a container view controller with a scrollview and you add your page controllers&amp;#8217; views to the scrollview. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;PageControl had the navigation part down, but its pages were static view controllers and I needed to be able to implement functionalities like launching an action sheet, taking photos and pushing new view controllers. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Most of these functionalities work just fine with the PageControl example, but there are a few functions that don&amp;#8217;t. One specific instance is when you&amp;#8217;re presenting an UIImagePickerController. You may want to present this be sending a message to whatever page view controller you&amp;#8217;re currently in and while that does present the picker, it will cut off the top portion of the picker since your controller&amp;#8217;s view is a subview of the container&amp;#8217;s view. This means your container view controller must present the picker so that the picker can use the entire screen. So, I created a property that is a container view controller type in the page controller that uses the picker and set it as the original container view controller. I then use this property to present and dismiss the picker. &lt;/p&gt;
&lt;p&gt;Presenting from page view controller:&lt;/p&gt;

&lt;script src="https://gist.github.com/djchung/4735617.js" type="text/javascript"&gt;&lt;/script&gt;&lt;p&gt;Results in the top portion of the camera view cut off (notice the Auto button):&lt;/p&gt;
&lt;p&gt;&lt;img alt="image" src="http://media.tumblr.com/c9c57b13cf583fa97f810ecfab64f24f/tumblr_inline_mhvlxymW7A1qz4rgp.png"/&gt;&lt;/p&gt;

&lt;p&gt;Compare to presenting from the container view controller property of the page view controller:&lt;/p&gt;
&lt;script src="https://gist.github.com/djchung/54d257a4d6ff2b30edb5.js" type="text/javascript"&gt;&lt;/script&gt;&lt;p&gt;Results in using the full view:&lt;/p&gt;
&lt;p&gt;&lt;img alt="image" src="http://media.tumblr.com/3d20314dd28febf4b7550dff01d8ade9/tumblr_inline_mhvm3sfajg1qz4rgp.png"/&gt;&lt;/p&gt;
&lt;p&gt;If you&amp;#8217;re looking to use horizontal navigation and want to each page to have its own functionality, check out my implementation, &lt;a href="https://github.com/djchung/DJHorizontalNav" target="_blank"&gt;DJHorizontalNav&lt;/a&gt; and let me know what you think!&lt;/p&gt;</description><link>http://djchung.tumblr.com/post/42542208242</link><guid>http://djchung.tumblr.com/post/42542208242</guid><pubDate>Thu, 07 Feb 2013 19:48:00 -0500</pubDate><category>OSS</category><category>iOS</category><category>horizontal navigation</category></item><item><title>To Learn How to Program, It Has To Fulfill A Need</title><description>&lt;p&gt;One response from my last post about how &lt;a href="http://djchung.tumblr.com/post/39880299461/how-programming-changed-the-way-i-think"&gt;learning to program &lt;/a&gt;changed the way I think was the following:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;span&gt;Have fallen off the &amp;#8220;learn to program band-wagon&amp;#8221; many times myself, maybe due to me setting unrealistic goals for myself or learning the wrong way. Could you walk us through how you disciplined your self to stay focused and concentrate on learning how to program?&lt;/span&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;This is a great question. I have fallen off the &amp;#8220;learn to program band wagon&amp;#8221; a few times as well. What was the difference this time? Necessity. &lt;/p&gt;
&lt;p&gt;When I committed myself to learn iOS, I had recently shut down an online business I was running and was living off savings. If I couldn&amp;#8217;t learn how to program, learn how to acquire freelance clients and learn how to execute projects, I&amp;#8217;d run out of money and would have had to move on to plan B. I didn&amp;#8217;t have a plan B. In my mind, I had to make this work.&lt;/p&gt;
&lt;p&gt;This may seem dramatic and reckless, but trust me when I say that it was a calculated risk. First of all, I had enough savings to last me six months (living frugally). Second, I knew there was a big upside to learning iOS given the market demand, especially where I live, San Francisco. Third, one of my good friends, &lt;a href="https://twitter.com/stevederico"&gt;Steve&lt;/a&gt;, had already done exactly what I was trying to do and was a huge help - I was/am in the perfect environment (here&amp;#8217;s my post about my &lt;a href="http://tmblr.co/Z4MkLya1CSeP"&gt;environment&lt;/a&gt;). In my mind, the success of this new adventure was dependent on my execution. It&amp;#8217;s the type of calculated risk I will (hopefully) take 100% of the time. I will always take a chance on myself. If you don&amp;#8217;t believe in yourself, who will? Also, I knew the worst case scenario was that I&amp;#8217;d have to find something else to do and I knew I would at least pick up a new skill.&lt;/p&gt;
&lt;p&gt;I&amp;#8217;m not suggesting that you have to put all of your eggs in the programming basket to stick with it, but rather that programming has to fulfill a need. &lt;/p&gt;
&lt;p&gt;Do you need to learn how to program to make a living? &lt;/p&gt;
&lt;p&gt;Do you need to learn how to program to solve a math problem? &lt;/p&gt;
&lt;p&gt;Do you need to learn how to program to build a fun website you&amp;#8217;ve been thinking about?&lt;/p&gt;
&lt;p&gt;There are varying degrees of &amp;#8220;need&amp;#8221; and it&amp;#8217;s different for everyone, but my guess is that the stronger the need, the more pain, frustration and punches you&amp;#8217;re willing to take on the never ending journey of learning how to program. &lt;/p&gt;
&lt;p&gt;My experience with learning for the sake of learning has been miserable. When I first tried to learn how to program, I started because my close friends were programmers - I just wanted to be in the club. I did every tutorial out there on Python/Django and Ruby on Rails. They were helpful in getting a basic understanding, but I never really made much progress beyond the tutorials and fell off within a few weeks. I just didn&amp;#8217;t really need it. &lt;/p&gt;
&lt;p&gt;This may be a topic for another post, but when you&amp;#8217;re actually going through the process of learning how to program, once you&amp;#8217;ve done a few tutorials and have a basic grasp of fundamental concepts, you need a project. You have to try to build something. You have to try to get something out there, whether it&amp;#8217;s a silly website for your group of close friends (here&amp;#8217;s &lt;a href="http://www.6richards.com"&gt;mine&lt;/a&gt;) or a simple app to keep score for bar games (again, here&amp;#8217;s &lt;a href="https://itunes.apple.com/us/app/simplescore/id499664201?mt=8"&gt;mine&lt;/a&gt;). Otherwise, you just don&amp;#8217;t need to learn how to program.&lt;/p&gt;</description><link>http://djchung.tumblr.com/post/40104231149</link><guid>http://djchung.tumblr.com/post/40104231149</guid><pubDate>Wed, 09 Jan 2013 13:03:40 -0500</pubDate></item><item><title>How Learning to Program Changed the Way I Think</title><description>&lt;p&gt;I have been a full time developer (mainly iOS) for &lt;a href="http://djchung.tumblr.com/post/38674745881/lifted" target="_blank"&gt;one year&lt;/a&gt; and it has changed the way I think. &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Confidence&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;When I first started getting freelance work, my biggest fear was that I wouldn&amp;#8217;t be able to deliver technically. What if I just didn&amp;#8217;t know how to do something? As a solo developer, that thought was horrifying. When you become a developer, you realize that there is no way you&amp;#8217;ll know how to implement every technical feature, yet. However, you come to realize that you can learn how to implement every technical feature. Part of this comes from the endless resources available: documentation, Stack Overflow, forums and blogs, but the other part is the mindset you develop as you overcome technical hurdles. &lt;/p&gt;
&lt;p&gt;I remember working on &lt;a href="http://picturemenu.com/"&gt;Picturemenu&lt;/a&gt; and realizing that at the end of every week, I had implemented a feature I had no idea how to do at the beginning of the week. After a few weeks of this, I started to develop confidence in my ability to learn and figure things out. My classic response to the question, &amp;#8220;Do you know how to do it?&amp;#8221; was, &amp;#8220;Not right now, but I&amp;#8217;ll figure it out.&amp;#8221;&lt;/p&gt;
&lt;p&gt;I think this mindset has been the most positive change for me and it has carried over to all parts of my life. Knowledge is finite, but the ability to learn is infinite.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Dedication&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Programming is a craft and in order to become great, like at anything, you must have a long term perspective and dedicate yourself to becoming better each day. I realized that my failed attempts at learning to program before this past year was because I had a very myopic view of programming. I had the mindset that maybe I&amp;#8217;ll do programming here and there for a little while and then move on to something else. I thought that I could just read a book and know how to program. I was wrong. It wasn&amp;#8217;t until I committed to become an iOS developer that I saw significant strides. There&amp;#8217;s a pretty steep learning curve to programming and I&amp;#8217;ve fallen off three or four times. If you don&amp;#8217;t see yourself programming for at the minimum, the next two years of your life, you&amp;#8217;re not going to put up with all of the frustration that comes along with it - it&amp;#8217;s just not worth it. &lt;/p&gt;
&lt;p&gt;Along with dedication comes perseverance. One of the traits that I admire most of programmers and have been developing myself is persistence. Your code will always have bugs. Debugging can turn into a war of attrition. You have to be persistent when tracking down bugs and be willing to take the self inflicted punches along the way as you figure out that the reason why your code doesn&amp;#8217;t work is because you forgot to reset a boolean variable. &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Appreciation&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;As consumers, we take the process it takes to produce a product for granted. We complain about how we don&amp;#8217;t like the color of an icon, how slow an app is or how something just sucks. These can all be valid points, but when you&amp;#8217;re on the other end as a producer, you realize (usually) how much time, effort and thought goes into making a product from start to finish. It&amp;#8217;s not a trivial task. &lt;/p&gt;
&lt;p&gt;Apps range from very simple to very complex, but even the simplest app requires a certain amount of effort in making things work. You have to write the code, make the icon, submit it to the AppStore (trust me, submitting to the AppStore for the very first time can be a harrowing experience). As end users, we don&amp;#8217;t care about all of that, and we shouldn&amp;#8217;t, but as a producer, you develop a new found appreciation for great products, beautiful design and craftsmen. This way of thinking adds more depth to life. You look at things differently. Music, physical products and nature all become magical as you realize that it all came from nothing. &lt;/p&gt;</description><link>http://djchung.tumblr.com/post/39880299461</link><guid>http://djchung.tumblr.com/post/39880299461</guid><pubDate>Sun, 06 Jan 2013 18:59:00 -0500</pubDate><category>programming</category></item><item><title>Finding Primes: Sieve of Eratosthenes</title><description>&lt;p&gt;Have you ever tried finding the first n prime numbers? &lt;/p&gt;
&lt;p&gt;It&amp;#8217;s not something you think about every day, but I&amp;#8217;ve been going through some of the problems on &lt;a href="http://www.projecteuler.net"&gt;Project Euler&lt;/a&gt; and finding prime numbers seems to be a recurring exercise. &lt;/p&gt;
&lt;p&gt;In solving these problems, I ran across the ancient algorithm, &lt;a href="http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes"&gt;Sieve of Eratosthenes&lt;/a&gt;, to find prime numbers. The basic algorithm to find all prime numbers within a range is, you start with the first prime number of that range, you go through that array of numbers and divide each number by that first prime number (not including itself), if the number in the array is divisible, you throw it out of the array. You then repeat this for the next number in the array once you go through dividing and removing numbers from the array until you reach the end of the array. &lt;/p&gt;
&lt;p&gt;Here&amp;#8217;s a concrete example: Find all of the prime numbers from [2, 10]&lt;/p&gt;
&lt;p&gt;2, 3, 4, 5, 6, 7, 8, 9, 10&lt;/p&gt;
&lt;p&gt;Start with 2 and start removing all numbers divisible by two:&lt;/p&gt;
&lt;p&gt;2, 3, &lt;strike&gt;4&lt;/strike&gt;, 5, &lt;strike&gt;6&lt;/strike&gt;, 7, &lt;strike&gt;8&lt;/strike&gt;, 9, &lt;strike&gt;10&lt;/strike&gt;&lt;/p&gt;
&lt;p&gt;Do the same with the next number, 3:&lt;/p&gt;
&lt;p&gt;2, 3, 5, 7, &lt;strike&gt;9&lt;/strike&gt;&lt;/p&gt;
&lt;p&gt;As you go through with 5 and 7, there are no more numbers divisible, so you&amp;#8217;re left with an array of all primes in [2, 10]:&lt;/p&gt;
&lt;p&gt;2, 3, 5, 7&lt;/p&gt;
&lt;p&gt;Here&amp;#8217;s some code finding the sum of the primes less than 2,000,000:&lt;/p&gt;


&lt;script src="https://gist.github.com/4436313.js" type="text/javascript"&gt;&lt;/script&gt;</description><link>http://djchung.tumblr.com/post/39483568448</link><guid>http://djchung.tumblr.com/post/39483568448</guid><pubDate>Wed, 02 Jan 2013 12:30:29 -0500</pubDate></item><item><title>Lifted By Others</title><description>&lt;p&gt;                 &lt;img alt="image" src="http://media.tumblr.com/92371c0bda5785bb76de2e50f5c218ac/tumblr_inline_mfiee2p7mw1qbpa00.jpg"/&gt;&lt;/p&gt;
&lt;p&gt;I have this poster in my room at my parent&amp;#8217;s home. I love the quote by William Blake at the bottom, &amp;#8220;No bird soars too high, if he soars with his own wings.&amp;#8221;&lt;/p&gt;
&lt;p&gt;About a week ago I renewed my yearly Apple Developer&amp;#8217;s License. That means I started building iPhone apps one year ago. I distinctly remember writing my first line of Objective-C on the very desk that I am writing this post. &lt;/p&gt;
&lt;p&gt;One year ago, I committed to learn how to program and make iPhone apps. Since then, I&amp;#8217;ve launched three of my own apps into the AppStore, started an iPhone app consulting business, acquired clients and began working at a design firm as an iOS engineer staffed on projects for Fortune 500 companies. Needless to say, my life has changed. I don&amp;#8217;t think I can even begin to convey how much I&amp;#8217;ve learned in the past year, but one lesson I do want to share from the past year is the importance of being in an environment that is conducive to reaching your goals. &lt;/p&gt;
&lt;p&gt;You can only go so far on your own. I owe so much to my close friends who have challenged me, encouraged me and inspired me. Here are a few of the countless examples of the influences in my life that have pushed me to places beyond my own imagination: &lt;/p&gt;
&lt;p&gt;&lt;a href="http://twitter.com/stevederico" target="_blank"&gt;Steve Derico&lt;/a&gt;. Steve has been the most influential person in my development as an iPhone developer. He was the first one to tell me that I could become one and has spent countless hours teaching me everything from code, freelancing and design. I cannot thank him enough. Early on, I asked Steve if I could buy him dinner in exchange for an hour of his time coding, debugging and asking questions. Those were the most invaluable hours for my growth as a developer. Without him, I probably would have gotten stuck and maybe even given up, but he has always been a constant source of encouragement. Just knowing that someone believes in you goes a long way. Thank you, Steve. &lt;/p&gt;
&lt;p&gt;Hackathon guys. Even before I started doing iOS development, some of my friends and I would stay up all night, eat terrible food, drink red bull and work on side projects. This still continues today. Steve, Nick, &lt;a href="http://twitter.com/soffes" target="_blank"&gt;Sam&lt;/a&gt;, Matt and I will hack through the night together on our respective projects. By working in the same place, we push each other to be productive and help each other when we can. I&amp;#8217;ve picked up so much just having short conversations in passing, by asking, &amp;#8220;Hey Sam, how would you approach this&amp;#8230;&amp;#8221; Then, there is the 2 AM run to Safeway to get junk food - not the healthiest idea, but it&amp;#8217;s always an experience. &lt;/p&gt;
&lt;p&gt;I&amp;#8217;ve been fortunate enough to be immersed in such a great environment to learn how to become an iPhone developer. I am a testament to how valuable such a supportive environment can be. I hope that I can contribute even a fraction of the value I&amp;#8217;ve received to that community.&lt;/p&gt;
&lt;p&gt;Surround yourself with those that inspire and encourage you, and oh the places you&amp;#8217;ll go. &lt;/p&gt;
&lt;p&gt;For fun: Hackathon footage from August 19th, 2010: &lt;/p&gt;
&lt;p&gt;&lt;iframe frameborder="0" height="315" src="http://www.youtube.com/embed/rP09I0ya64c" width="420"&gt;&lt;/iframe&gt;&lt;/p&gt;</description><link>http://djchung.tumblr.com/post/38674745881</link><guid>http://djchung.tumblr.com/post/38674745881</guid><pubDate>Sun, 23 Dec 2012 20:47:00 -0500</pubDate><category>lessons</category><category>iphone development</category><category>friends</category></item><item><title>Learning algorithms: Insertion Sort</title><description>&lt;p&gt;I am an iOS engineer, but I don&amp;#8217;t have much of a computer science background. I took one intro CS course at Duke and it was pretty terrible. However, with all of the free, high quality online courses available, I can learn just about anything. I&amp;#8217;ve started taking MIT&amp;#8217;s &lt;a href="http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-046j-introduction-to-algorithms-sma-5503-fall-2005/index.htm" target="_blank"&gt;Intro to Algorithms&lt;/a&gt;. &lt;/p&gt;
&lt;p&gt;I was watching the first lecture and taking notes. This is generally how I approached school: go to lecture, take notes, read the text book, do homework. I thought that&amp;#8217;s what I would do for this online course, but I realized how much more flexibility I have with online videos and with all of the course material available at once. This means I can pause the video, skip to different lectures or try something out during the lecture. I think that last part is the way I&amp;#8217;m going to learn the most. Usually, I would just watch the lecture and just listen. Now, I&amp;#8217;m going to put more emphasis on doing some of the examples on my own. &lt;/p&gt;
&lt;p&gt;The first algorithm presented was a classic sorting algorithm, insertion sort (I had no idea what it was). Insertion sort is an algorithm that takes an array of numbers and sorts them from least to greatest. The high level overview is that you pick a number at an index&amp;#160;!= 0, which we will call &amp;#8220;key&amp;#8221; and compare it to the value at the previous index. If the key is less than the value, you &amp;#8220;insert&amp;#8221; it at the previous index and then you move onto the next index until you get to the end of the array. &lt;/p&gt;
&lt;p&gt;The lecture notes gave the pseudo code, but I wanted to code it on my own to really understand insertion sort. Here&amp;#8217;s my code (in ruby):&lt;/p&gt;




&lt;script src="https://gist.github.com/4219034.js?file=gistfile1.rb" type="text/javascript"&gt;&lt;/script&gt;</description><link>http://djchung.tumblr.com/post/37276570658</link><guid>http://djchung.tumblr.com/post/37276570658</guid><pubDate>Wed, 05 Dec 2012 15:16:19 -0500</pubDate></item><item><title>Have the Audacity to Build</title><description>&lt;p&gt;Yesterday was one of the most inspirational days I&amp;#8217;ve had in awhile and it wasn&amp;#8217;t because I read a heartwarming story, watched a compelling Youtube video or listened to uplifting music. It was because I built something. &lt;/p&gt;
&lt;p&gt;I&amp;#8217;ve been learning how to make iPhone apps for about a month and yesterday, I submitted my first two iPhone apps to the AppStore for review. I&amp;#8217;ll find out in a week if they are approved. &lt;/p&gt;
&lt;p&gt;I had been talking about learning how to program for over a year, but I haven&amp;#8217;t had much to show for it. But yesterday I shipped something I built. Is it perfect? No. Is it insanely great? Not at all. But it&amp;#8217;s a start and that&amp;#8217;s the key. &lt;/p&gt;
&lt;p&gt;Submitting to the AppStore was pretty magical. It was magical because it broke down a lot of my walls. Well, maybe it didn&amp;#8217;t break down my walls, but it did take a good chunk out of my wall of fear of failure. &lt;/p&gt;
&lt;p&gt;I&amp;#8217;ve always followed the well-worn path and have been pretty successful at it. I&amp;#8217;m pretty book smart, so I got good grades in high school, went to a prestigious college and even wrote a &lt;a href="http://www.amazon.com/Build-Like-Ant-Helped-Valedictorian/dp/1466221941/ref=sr_1_1?ie=UTF8&amp;amp;qid=1328204057&amp;amp;sr=8-1" target="_blank"&gt;book&lt;/a&gt; about it&amp;#8230;(shameless, I know). I was pretty set on continuing that theme into my professional career - whether it be medical school or a job at a large corporation - but for some personal reasons (maybe I&amp;#8217;ll share those in a future post) that was not going to be part of my journey, at least not right now. &lt;/p&gt;
&lt;p&gt;When you have continued success with a certain way of life, it&amp;#8217;s frightening to change course. This characterizes my past two years since I graduated from Duke. I was frightened by not having the safety blanket of being considered successful by association. If I told you I worked at Google, just by association you could make a lot of assumptions about my abilities, salary, stability, etc. When you don&amp;#8217;t have that association crutch you&amp;#8217;ve always had, you begin to doubt yourself. &lt;/p&gt;
&lt;p&gt;It&amp;#8217;s a continual process to overcome that doubt, but what I&amp;#8217;ve found helpful is that you have to have the audacity to build and then take one step. Whether it be deciding to learn a new language and doing one tutorial or coming up with an idea and actually starting a business entity, the mere fact that you took one small step toward building something is progress. Just keep the momentum going and take more one step, then another and another&amp;#8230;&lt;/p&gt;
&lt;p&gt;I&amp;#8217;m a sucker for inspirational things so I couldn&amp;#8217;t leave this one out. This is a gem:&lt;/p&gt;
&lt;p&gt;&lt;iframe frameborder="0" height="315" src="http://www.youtube.com/embed/8Iw_G4O8THA" width="560"&gt;&lt;/iframe&gt;&lt;/p&gt;</description><link>http://djchung.tumblr.com/post/16930666802</link><guid>http://djchung.tumblr.com/post/16930666802</guid><pubDate>Thu, 02 Feb 2012 14:42:12 -0500</pubDate></item><item><title>My Beef with Interface Builder</title><description>&lt;p&gt;I&amp;#8217;ve been generally impressed with XCode 4. I&amp;#8217;ve never used it before until about a month ago and I&amp;#8217;ve picked it up pretty quickly. I&amp;#8217;ve primarily used KomodoEdit and Textmate before I started iOS programming so the Interface Builder was something completely new. I really liked it&amp;#8230;at first. &lt;/p&gt;
&lt;p&gt;Using a GUI to hook up outlets, actions, drop in views and controllers was fun at first and very easy. However, after going deeper with iOS, using IB can be a pain because you don&amp;#8217;t have as much control over the code. &lt;/p&gt;
&lt;p&gt;For instance, today I was building a UITableView and I used IB to drop in a UITableView object. I made sure to include the UITableViewDataSource and UITableViewDelegate protocols in my ViewController and implemented the required methods. I used the Attributes inspector to set the style of my UITableView and I programmatically set the datasource and delegate to my ViewController. Build, run. Nothing.&lt;/p&gt;
&lt;p&gt;I couldn&amp;#8217;t figure out what was wrong, but I looked at my XIB file and glanced at my Connections inspector. Even though I had programmatically set my datasource and delegate, it showed that these two properties were not connected. I had to manually set these in my XIB file. This is annoying.&lt;/p&gt;
&lt;p&gt;It seems like there&amp;#8217;s a divide between using IB to build apps or actually writing code. XCode 4 seems to be riding in the middle and little details like setting the datasource and delegate slip through the cracks. I like writing the code out, you have full control and you know how everything is connected. I think I&amp;#8217;m going to try to manually program things from now on, and maybe I&amp;#8217;ll use IB to mock up prototypes quickly. But for building complicated apps, relying heavily on IB seems like a  nightmare. &lt;/p&gt;</description><link>http://djchung.tumblr.com/post/16100953812</link><guid>http://djchung.tumblr.com/post/16100953812</guid><pubDate>Wed, 18 Jan 2012 23:20:24 -0500</pubDate></item><item><title>Key Points When Setting Segues Directly</title><description>&lt;p&gt;In learning to use Storyboarding both &lt;a href="http://djchung.tumblr.com/post/15664797091/4-checkpoints-create-segues-programmatically" target="_blank"&gt;programmatically&lt;/a&gt; and directly, here are a few key points I&amp;#8217;ve found. &lt;/p&gt;
&lt;p&gt;When setting segues directly&amp;#8230;&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;If a button leads to a segue, CTRL-Drag it to the next View Controller. Distinctly name each segue in the Identifier field of the Inspector option in the Utilities tab!&lt;/li&gt;
&lt;li&gt;Each button that leads to segue will have its own ViewController that is created and pushed on top of the view stack. &lt;/li&gt;
&lt;li&gt;In your &lt;br/&gt;- (void)prepareForSegue:(UIStoryboardSegue *)&lt;span class="s1"&gt;segue&lt;/span&gt; sender:(id)&lt;span class="s1"&gt;sender implementation&lt;/span&gt;, use if statements to select the correct segue.identifier to send appropriate messages to your segue.destinationViewController object.&lt;/li&gt;
&lt;/ul&gt;&lt;p&gt;One key reason to set segues directly is if each segue has a unique UI. This way, you can fully customize each the UI of the view for each resulting segue. &lt;/p&gt;
&lt;p&gt;Also, when you set the segue directly, you do not need to call &lt;/p&gt;
&lt;p&gt;- (void)performSegueWithIdentifier:(NSString *)&lt;span class="s1"&gt;identifier&lt;/span&gt; sender:(id)&lt;span class="s1"&gt;sender&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class="s1"&gt;because this code is used when you have a button as a target-action to manually call execute the segue when pressed. However, when directly setting the segue in Storyboard, your buttons do not have target-actions, but rather direct segues (via CTRL-drag) to the next ViewController. Therefore, that connection will know to execute the segue. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class="s1"&gt;Here are all of the if statements in &lt;br/&gt;- (void)prepareForSegue:(UIStoryboardSegue *)&lt;span class="s1"&gt;segue&lt;/span&gt; sender:(id)&lt;span class="s1"&gt;sender&lt;/span&gt; I was referring to:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class="s1"&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;
&lt;script src="https://gist.github.com/1595785.js?file=gistfile1.m"&gt;&lt;/script&gt;</description><link>http://djchung.tumblr.com/post/15676190372</link><guid>http://djchung.tumblr.com/post/15676190372</guid><pubDate>Wed, 11 Jan 2012 12:38:02 -0500</pubDate></item><item><title>Four Checkpoints When Creating Segues Programmatically </title><description>&lt;p&gt;Storyboarding is a new feature in XCode 4.2 and is only compatible with iOS5. Storyboarding enables you to manage all of your views in one place and create segues (transitions between views). Segues can be created graphically through the storyboard, but you can make segues programmatically.&lt;/p&gt;
&lt;p&gt;The code is based on the &lt;a href="http://www.stanford.edu/class/cs193p/cgi-bin/drupal/" target="_blank"&gt;CS193P Lecture 6&lt;/a&gt; demo that creates segues programmatically. &lt;/p&gt;
&lt;p&gt;Here are some checkpoints when you are creating segues programmatically:&lt;/p&gt;
&lt;p&gt;1. Link the segue&lt;/p&gt;
&lt;p&gt;This one is a little tricky. Most of the time, you want to trigger a segue when you click a button. So it&amp;#8217;s natural for you to CTRL-drag from a button to another ViewController. However, if your buttons have a target-action that calls the segue in code, then it&amp;#8217;s your ViewController that triggers the segue.  So in this case, CTRL-drag from your ViewController to the next ViewController. &lt;/p&gt;
&lt;p&gt;2.  Is your segue identifier set?&lt;/p&gt;
&lt;p&gt;Highlight the connection between two views in your MainStoryboard.storyboard with your Utilities tab showing (far right tab). Look at the Attributes section, make sure you give a descriptive name for the Identifier field. This is how you are going to refer to this specific segue in your code. &lt;/p&gt;
&lt;p&gt;3. Call - (void) performSegueWithIdentifier:(NSString *)&lt;span class="s1"&gt;identifier&lt;/span&gt; sender:(id)&lt;span class="s1"&gt;sender&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Like the method name, this actually performs the segue, so call it when you actually want the segue to happen in your code. The identifier parameter is the name you set for your segue, see #2. Sender is the object that is responsible for triggering the segue, so for example, it could be a button or the ViewController itself. &lt;/p&gt;
&lt;p&gt;4. Implement - (void)prepareForSegue:(UIStoryboardSegue *)&lt;span class="s1"&gt;segue&lt;/span&gt; sender:(id)&lt;span class="s1"&gt;sender&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class="s1"&gt;When implementing, make sure you check each segue identifier so you know what segue it should perform. For instance, this is the code from the demo: &lt;/span&gt;&lt;/p&gt;
&lt;script src="https://gist.github.com/1593761.js?file=gistfile1.m"&gt;&lt;/script&gt;&lt;p&gt;Once you check for the correct identifier, you can send messages to your segue.destinationViewController, the ViewController that controls the resulting View from the segue. &lt;/p&gt;</description><link>http://djchung.tumblr.com/post/15664797091</link><guid>http://djchung.tumblr.com/post/15664797091</guid><pubDate>Wed, 11 Jan 2012 03:54:00 -0500</pubDate></item><item><title>Assignment 2 Hack (2011 Fall CS193P)</title><description>&lt;p&gt;&lt;a href="http://www.stanford.edu/class/cs193p/cgi-bin/drupal/node/265" target="_blank"&gt;Assignment 2&lt;/a&gt; requires you to create a programmable calculator where you can store values for variables. In reading over the actual question, I really had no idea where to start. I don&amp;#8217;t think the directions are all that clear, but maybe that&amp;#8217;s just me. &lt;/p&gt;
&lt;p&gt;After reading question 1, I just assumed that there needs to be some variable key on the calculator which you could set the value for and then reuse. So that&amp;#8217;s what I did. &lt;/p&gt;
&lt;p&gt;How is this a hack? Because that&amp;#8217;s not what the question asks for.  In reality, the question only asks you to be able to store variables so that you can hard code in values for those variables - not all that flexible. How do I know this? Thanks to &lt;a href="https://github.com/Agent007/Calculator" target="_blank"&gt;Jeffrey Lam&lt;/a&gt; who posted the (real) solution to his Github account. &lt;/p&gt;
&lt;p&gt;So here&amp;#8217;s my logic:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;To set the value of the variable, first I enter the numeric value, then I hit the    variable button followed by the enter key.&lt;/li&gt;
&lt;li&gt;When the variable button is pressed, the variable itself is added to the stack and its value is retrieved. &lt;/li&gt;
&lt;/ul&gt;&lt;p&gt;The hack is that when retrieving the value of a variable, the value is the second to last object in the stack that hold all operands entered because the variable is added to the same stack when its button is pressed. &lt;/p&gt;
&lt;p&gt;Here&amp;#8217;s the code:&lt;/p&gt;
&lt;p&gt;In the Controller:&lt;/p&gt;
&lt;script src="https://gist.github.com/1542600.js?file=gistfile1.m"&gt;&lt;/script&gt;&lt;p&gt;In the Model:&lt;/p&gt;
&lt;p&gt;Create public methods:&lt;/p&gt;

&lt;p class="p1"&gt;- (&lt;span class="s1"&gt;double&lt;/span&gt;)getVariableValue:(&lt;span class="s2"&gt;NSString&lt;/span&gt; *)var;&lt;/p&gt;
&lt;p class="p1"&gt;- (&lt;span class="s1"&gt;void&lt;/span&gt;)setVariable:(&lt;span class="s2"&gt;NSString&lt;/span&gt; *)var;&lt;/p&gt;
&lt;p class="p1"&gt;Implement them:&lt;/p&gt;

&lt;script src="https://gist.github.com/1542610.js?file=gistfile1.m"&gt;&lt;/script&gt;&lt;p class="p1"&gt;Update the enterPressed method:&lt;/p&gt;

&lt;script src="https://gist.github.com/1542615.js?file=gistfile1.m"&gt;&lt;/script&gt;&lt;p class="p1"&gt;Once these are set, you can store any numeric value into your variable. This isn&amp;#8217;t the intended answer of the assignment, but it was definitely a good learning experience. &lt;/p&gt;</description><link>http://djchung.tumblr.com/post/15059976546</link><guid>http://djchung.tumblr.com/post/15059976546</guid><pubDate>Fri, 30 Dec 2011 21:50:57 -0500</pubDate></item><item><title>Write Pseudo Code Before Coding</title><description>&lt;p&gt;I took one semester of Computer Science in college, second semester of my senior year. It was an intro class and I learned some Java. Of all the classes I took at Duke, it was one of the most poorly taught. Maybe it was because I had no background in CS and didn&amp;#8217;t know what to expect, but given the amount of griping I did with other classmates, I&amp;#8217;m going to stick to my statement. However, one thing I did learn and I now see great value in is writing pseudo code before actually writing a line of code. &lt;/p&gt;
&lt;p&gt;What is pseudo code? Pseudo code is just an outline of the code you want to write disregarding formal syntax. It&amp;#8217;s can be in sentence form or short hand code. Just lay out, step by step what you want your code to do.  An example is probably the best way to describe this: &lt;/p&gt;
&lt;p&gt;While working on the first homework assignment of CS 193P, I had to create a backspace button for a calculator. This is the pseudo code I wrote:&lt;/p&gt;
&lt;p&gt;Make a button that doesn&amp;#8217;t return anything (void). &lt;/p&gt;
&lt;p&gt;Implement the button with this code:&lt;/p&gt;
&lt;p&gt;&lt;span&gt; &lt;/span&gt;if user is in the middle of entering number check if there is only one number &lt;span&gt; &lt;/span&gt;entered. &lt;/p&gt;
&lt;p&gt;if so, display, &amp;#8220;Enter operand&amp;#8221; as a message to let user know there is no number  entered anymore. &lt;/p&gt;
&lt;p&gt;&lt;span&gt; &lt;/span&gt;if there is more than one digit entered, cut off the last digit and return the substring. &lt;/p&gt;
&lt;p&gt;&lt;span&gt; &lt;/span&gt;print the substring or the message on the display. &lt;/p&gt;
&lt;p&gt;Pretty simple, but it forces you to lay out a road map and consciously think about what the code you want to write. This really helps me because when I just dive into the code, I just hack away with whatever comes to my mind. I often lose sight of where I&amp;#8217;m going and can get lost on rabbit trails. &lt;/p&gt;
&lt;p&gt;Pseudo code is just for a reference, you don&amp;#8217;t necessarily have to follow it exactly. But I like having the initial plan as a starting point. &lt;/p&gt;
&lt;p&gt;I also recommend you physically writing out the pseudo code. I think it makes it more intentional. You may think it takes more time to do this and if it&amp;#8217;s a trivial method, you&amp;#8217;re probably right. But for more complicated solutions, I think this will actually save you time and headache in the long run. &lt;/p&gt;
&lt;p&gt;Oh and here&amp;#8217;s the actual code: &lt;/p&gt;
&lt;script src="https://gist.github.com/1532519.js?file=gistfile1.m"&gt;&lt;/script&gt;</description><link>http://djchung.tumblr.com/post/14964394411</link><guid>http://djchung.tumblr.com/post/14964394411</guid><pubDate>Thu, 29 Dec 2011 02:13:00 -0500</pubDate></item><item><title>Stanford CS 193P (F'11) Assignment 1 Highlights</title><description>&lt;p&gt;I finished up &lt;a href="http://www.stanford.edu/class/cs193p/cgi-bin/drupal/node/261" target="_blank"&gt;Assignment 1&lt;/a&gt; from Stanford CS 193P and put it on &lt;a href="https://github.com/djchung/CS193P_HW1/tree/master/Calculator2" target="_blank"&gt;Github&lt;/a&gt;.  The assignment is to make a calculator app with basic functionality. The first assignment was a great intro and I highly recommend reading through the &lt;a href="http://www.stanford.edu/class/cs193p/cgi-bin/drupal/node/261" target="_blank"&gt;walkthrough&lt;/a&gt; as it is very thorough. I want to highlight a one of the questions from the problem set. &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Make a clear (C) button (Problem #5)&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This task is a pretty simple one, create a clear button (C) that erases any previous input from the display screen and the historyDisplay screen.  The historyDisplay screen is from #4 - it essentially shows the history of what you typed into the calculator.&lt;/p&gt;
&lt;p&gt;This is a great task because it combines a lot of concepts and requires a pretty good understanding of how the Model, View and Controller work together.&lt;/p&gt;
&lt;p&gt;A quick note about how the calculator works. When a number is entered (touching digits and then pressing the Enter key), that number is added to an NSMutableArray. The next operand (number) is entered (adds to NSMutableArray) followed by the operator. The operator then performs the calculation with respect to the two previous number entries. For instance, 25 + 3.58 is calculated by: 25 Enter 3.58 +.&lt;/p&gt;
&lt;p&gt;Let&amp;#8217;s get back to making this Clear button. &lt;/p&gt;
&lt;p&gt;The first step is to drag a button from the Object Library onto your storyboard (View). The button needs to be able to talk to the Controller via an Action, so CTRL Click and drag the arrow into your controller (.m) file. There is no need to send an argument to this action. I named this action clearPressed. &lt;/p&gt;
&lt;p&gt;For the actual code, when C is pressed, I want to clear display and historyDisplayed, so I just my setter function and set them both to a blank:&lt;/p&gt;
&lt;script src="https://gist.github.com/1516657.js?file=gistfile1.txt"&gt;&lt;/script&gt;&lt;p&gt;I&amp;#8217;m not done because I need to now delete the number I added to the NSMutableArray in my model so that when I continue using my calculator, my discarded operand does not get used. This means I need to create a method in my model that removes the last object in my array. &lt;/p&gt;
&lt;p&gt;Because I need to use it in my controller, I need to make this model function, I called it clearAll, public. So I declared it in my model header (.h) file as:&lt;/p&gt;
&lt;p&gt;- (void)clearAll;&lt;/p&gt;
&lt;p&gt;In my model implementation file (.i), I send a message to my NSMutableArray to removeLastlObject so delete the last entered number. Here&amp;#8217;s the code:&lt;/p&gt;
&lt;script src="https://gist.github.com/1516653.js?file=gistfile1.txt"&gt;&lt;/script&gt;&lt;p&gt; Now I can use this function in my controller implementation file:&lt;/p&gt;
&lt;script src="https://gist.github.com/1516602.js?file=gistfile1.txt"&gt;&lt;/script&gt;&lt;p&gt;My model is called brain.&lt;/p&gt;
&lt;p&gt;So now when the C button is pressed, the display is cleared and the number is removed from the array and you&amp;#8217;re ready to enter another number!&lt;/p&gt;
&lt;p&gt;This was a good question that makes sure you understand how MVC work together. &lt;/p&gt;</description><link>http://djchung.tumblr.com/post/14712733404</link><guid>http://djchung.tumblr.com/post/14712733404</guid><pubDate>Sat, 24 Dec 2011 02:01:00 -0500</pubDate></item><item><title>Three iOS Concepts to Help Get You Started</title><description>&lt;p&gt;I just began iOS development and I&amp;#8217;ve come across some concepts that are mentioned over and over - I&amp;#8217;m going through &lt;a href="http://www.bignerdranch.com/book/ios_programming_the_big_nerd_ranch_guide_nd_edition_" target="_blank"&gt;iOS Programming: The Big Nerd Ranch Guide (2nd Ed.)&lt;/a&gt; and &lt;a href="http://www.stanford.edu/class/cs193p/cgi-bin/drupal/" target="_blank"&gt;Stanford CS 193P iPhone Application Development&lt;/a&gt;.  I have a hunch that these concepts will be essential as I dive deeper into iOS development.&lt;/p&gt;
&lt;p&gt;Just as a side note, I have experience developing in PHP, Python/Django and a little bit of Java, but no prior C or Objective C experience.&lt;/p&gt;
&lt;p&gt;1. Model - View - Controller (MVC)&lt;/p&gt;
&lt;p&gt;MVC is the way iOS (as well as Ruby on Rails and Python/Django) software is organized. Your code is separated up into these three parts and each part has a specific role in your software.&lt;/p&gt;
&lt;p&gt;Model:&lt;/p&gt;
&lt;p&gt;The Model holds your app&amp;#8217;s data and information or otherwise referred to as objects. In essence it is what your application is. For instance, if you&amp;#8217;re creating an app that shares photos, the model is where your array of photos are stored, where you define how big your photos can be and how many photos a user can have.&lt;/p&gt;
&lt;p&gt;Controller:&lt;/p&gt;
&lt;p&gt;The Controller is the brain of your application. It talks to the Model so that it can determine how to represent the data or objects on the screen. &lt;/p&gt;
&lt;p&gt;View:&lt;/p&gt;
&lt;p&gt;The View is what is actually displayed on your screen, like buttons, sliders and text inputs. Views are connected to the Controller so that on screen actions are linked with methods in the Controller who then accesses data in the Model to retrieve an object (ex: a photo) to be relay back to the View so that it can display it on the screen. &lt;/p&gt;
&lt;p&gt;Having distinct pieces of code allows you to manage and organize your software as it becomes more and more complex. As you write more and more code, you&amp;#8217;ll know where to write that specific piece of code and where to find it later on if you need to change it. &lt;/p&gt;
&lt;p&gt;2. Objective - C Method Syntax&lt;/p&gt;
&lt;p&gt;When I first saw an Obj. - C method declared, I was a little confused. Here is sample from the first lecture in Stanford CS 193P:&lt;/p&gt;
&lt;p&gt;- (void)orbitPlanet:(Planet *)aPlanet atAltitude:(double)km&lt;/p&gt;
&lt;p&gt;The full name of this method is orbitPlanet:atAltitude. Let&amp;#8217;s break this line of code up piece by piece.&lt;/p&gt;
&lt;p&gt;Methods start off with a - and (void) is the return type. You must specify a return type, if you are return a double float point, you would write (double). orbitPlanet is part of the name of the function and it takes in a parameter called &amp;#8220;aPlanet&amp;#8221; that is of type Planet *. The * means that it is a pointer to the object, Planet. A pointer is a reference to an object, it is a link or line to that object. &lt;/p&gt;
&lt;p&gt;atAltitude is another method pieced together to orbitPlanet that takes in a parameter, km, which is a (double). The parameter names are arbitrarily defined, you can make up any name you like. &lt;/p&gt;
&lt;p&gt;3. @property/@synthesize&lt;/p&gt;
&lt;p&gt;In Objective - C, you don&amp;#8217;t directly access instance variables, you use properties. Properties are a combination of setter and getter methods. Setter methods store values into a variable that looks like setMyValue. Getter methods retrive the value and has a name like myValue.&lt;/p&gt;
&lt;p&gt;You can defined setter and getter methods two ways:&lt;/p&gt;
&lt;p&gt;A.&lt;/p&gt;
&lt;p&gt;&lt;span&gt; &lt;/span&gt;- (void)setMyScore(double):mathTest;&lt;/p&gt;
&lt;p&gt;&lt;span&gt; &lt;/span&gt;- (double)myScore;&lt;/p&gt;
&lt;p&gt;B.&lt;/p&gt;
&lt;p&gt;&lt;span&gt; &lt;/span&gt;@property (nonatomic) double myScore;&lt;/p&gt;
&lt;p&gt;A and B are equivalent. The (nonatomic) is related to threading, a topic which I&amp;#8217;ll write about later, but here&amp;#8217;s a good &lt;a href="http://stackoverflow.com/questions/588866/atomic-vs-nonatomic-properties" target="_blank"&gt;explanation&lt;/a&gt;. &lt;/p&gt;
&lt;p&gt;If you use @property to declare getters and setters, you must use @synthesize to implement the property. Here&amp;#8217;s how you would implement @property:&lt;/p&gt;
&lt;p&gt;@synthesize myScore = _myScore&lt;/p&gt;
&lt;p&gt;@synthesize creates storage to hold the value and _myScore is the name of the storage location, it creates an instance variable. Make sure you have a different name than myScore and stick to that convention. For instance, use an underscore (_) and the property name. &lt;/p&gt;
&lt;p&gt;So these are a few basic concepts to help you get started. I&amp;#8217;ll keep the posts coming as I learn more. &lt;/p&gt;
&lt;p&gt;Let&amp;#8217;s build some cool apps!&lt;/p&gt;</description><link>http://djchung.tumblr.com/post/14502180401</link><guid>http://djchung.tumblr.com/post/14502180401</guid><pubDate>Tue, 20 Dec 2011 03:02:00 -0500</pubDate></item></channel></rss>
