<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-1454751069877021109</id><updated>2014-10-05T00:52:41.073-07:00</updated><title type='text'>i cans code</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://icanscode.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1454751069877021109/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://icanscode.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Henry C.</name><uri>http://www.blogger.com/profile/09769937758968410789</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/-sH5RRR6IjbA/TWdSTtB9mVI/AAAAAAAAABA/OsdAg7HXVzg/s220/profilepic.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>2</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-1454751069877021109.post-7280943127755438731</id><published>2011-02-25T00:20:00.000-08:00</published><updated>2011-02-25T00:23:10.889-08:00</updated><title type='text'>Creating a Body-for-Life App (part 2)</title><content type='html'>In my &lt;a href=&quot;http://icanscode.blogspot.com/2011/02/creating-body-for-life-app.html&quot;&gt;last post&lt;/a&gt; I explained what the Body-For-Life cardio workout was and why I needed an app to help me do the work out.&amp;nbsp; Ok I don&#39;t &quot;NEED&quot; it, I just prefer to have something to look at... and this is a good chance to get my feet wet with some of this Phone Gap business.&lt;br /&gt;&lt;br /&gt;So first we need to create the webpage.&amp;nbsp; Fire up your favorite text editor and put in your html header and body tags.&lt;br /&gt;&lt;br /&gt;Now we know that to do a counter we need to have some sort of timer mechanism.&amp;nbsp; I&#39;ve been looking to jQuery recently, so I did a search of &quot;jquery timers&quot; and came across the jQuery plugin page for timers.&lt;br /&gt;&lt;br /&gt;I downloaded this one &lt;a href=&quot;http://plugins.jquery.com/files/jquery.timers-1.2.js.txt&quot;&gt;http://plugins.jquery.com/files/jquery.timers-1.2.js.txt&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;In the documentation on this page: &lt;a href=&quot;http://plugins.jquery.com/project/timers&quot;&gt;http://plugins.jquery.com/project/timers&lt;/a&gt;, it says that you can use something called &quot;Limited Timers&quot; in order to do something repeatedly for a set number of repetitions.&lt;br /&gt;&lt;blockquote style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;code&gt;var times = 10;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;$(document).everyTime(1000, function(i) {&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&amp;nbsp; doSomething(i);&lt;/code&gt;&lt;br /&gt;&lt;code&gt;}, times);&lt;/code&gt;&lt;/blockquote&gt;The above snippet will call doSomething() function 10 times, with a frequency of once a second.&amp;nbsp; That&#39;s perfect for the cardio routine because we want to have a total duration of 20 minutes.&amp;nbsp; 20 minutes * 60 seconds per minute gives us 1200 seconds total.&lt;br /&gt;&lt;br /&gt;In place of doSomething(), we will use jQuery to update the display to show the minute:second just like a stop watch.&amp;nbsp; We will update a &quot;seconds&quot; variable to count up the seconds as our application is running.&amp;nbsp; Then we will use seconds mod 60 to determine when 60 seconds have passed and increment a minutes variable.&amp;nbsp; Finally we will increase intensity at the same time minutes are incremented with a rule that when minutes get to 9, we reset to 5 in the next minute.&lt;br /&gt;&lt;br /&gt;Not too complicated right?&lt;br /&gt;&lt;br /&gt;Here is my first version of the code.&amp;nbsp; I included the javascript sources for jQuery and jquery timer, as well as put in a function to pad-with-zeros the counter output so it looks like a real stop watch.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional //EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&amp;gt;&lt;br /&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;head&amp;gt;&lt;br /&gt;&amp;lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=UTF-8&quot; /&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&amp;lt;!--&amp;lt;p&amp;gt;Total Seconds&amp;lt;/p&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;lt;div id=&quot;message&quot;&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;lt;/div&amp;gt;--&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;lt;div style=&quot;font-size:100px;&quot; align=&quot;center&quot;&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;lt;div&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;lt;span id=&quot;minutes&quot;&amp;gt;00&amp;lt;/span&amp;gt;:&amp;lt;span id=&quot;seconds&quot;&amp;gt;00&amp;lt;/span&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;lt;p&amp;gt;Intensity:&amp;lt;/p&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;lt;div style=&quot;font-size:200px;&quot; id=&quot;intensity&quot;&amp;gt;&lt;br /&gt;&amp;nbsp;5&lt;br /&gt;&amp;nbsp;&amp;lt;/div&amp;gt; &lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;script type=&quot;text/JavaScript&quot; src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js&quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&amp;lt;script type=&quot;text/JavaScript&quot; src=&quot;jquery_timers.js&quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&amp;lt;!--&lt;br /&gt;&amp;lt;pre&amp;gt;&lt;br /&gt;work out is 20 min&lt;br /&gt;each min is 60 sec x 20 min = 1200 sec duration in total&lt;br /&gt;each full minute show the intensity&lt;br /&gt;intensity starts at 5&lt;br /&gt;increments each full minute, until 9&lt;br /&gt;then reset to 5&lt;br /&gt;&lt;br /&gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;--&amp;gt;&lt;br /&gt;&amp;lt;script type=&quot;text/JavaScript&quot;&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;function zeroPad(num,count)&lt;br /&gt;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var numZeropad = num + &#39;&#39;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; while(numZeropad.length &amp;lt; count) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; numZeropad = &quot;0&quot; + numZeropad;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return numZeropad;&lt;br /&gt;&amp;nbsp;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp; $(document).ready(function() {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; minute = 0;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; intensity = 5;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; seconds = 0;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $(document).everyTime(1000, function(i) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; seconds++;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (seconds &amp;gt; 59) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; seconds = 0;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $(&#39;#seconds&#39;).html(zeroPad(seconds,2));&lt;br /&gt;&amp;nbsp;//&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $(&#39;div#message&#39;).html(i);&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (i % 60 == 0) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; minute++;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; intensity++;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (intensity &amp;gt; 9 &amp;amp;&amp;amp; minute &amp;lt; 20) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; intensity = 5;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $(&#39;#minutes&#39;).html(zeroPad(minute,2));&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $(&#39;div#intensity&#39;).html(intensity);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }, 1200);&lt;br /&gt;&amp;nbsp; });&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;So there you have it.&amp;nbsp; Save this to an index.html file and open this in your javascript enabled browser and you should see a counter counting up the minutes and seconds and also the intensity number that you should be at.&amp;nbsp;&amp;nbsp; Not too bad.&lt;br /&gt;&lt;br /&gt;But there are couple of limitations to this app.&amp;nbsp; You can&#39;t start or stop it interactively.&amp;nbsp; The timer starts as soon as the page is loaded and there is no stopping it or pausing it.&amp;nbsp; Also, this isn&#39;t much of an iphone app yet.&amp;nbsp; If you&#39;re on a mac computer like I am, you can throw this webpage&amp;nbsp; into your home ~/Sites directory (you need to enable Sharing &amp;gt; WebSharing) so that the page is served up by your computer&#39;s web server.&amp;nbsp; Then you can point your iphone&#39;s safari browser at your computer&#39;s ip address with address of the index.html page and you will see the timer on your iphone.&amp;nbsp; Not very distributable at this point.&lt;br /&gt;&lt;br /&gt;So what we really want to do is make this app a little nicer and covert it into a native app on the iphone with Phone Gap which we will get into next time.</content><link rel='replies' type='application/atom+xml' href='http://icanscode.blogspot.com/feeds/7280943127755438731/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://icanscode.blogspot.com/2011/02/creating-body-for-life-app-part-2.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1454751069877021109/posts/default/7280943127755438731'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1454751069877021109/posts/default/7280943127755438731'/><link rel='alternate' type='text/html' href='http://icanscode.blogspot.com/2011/02/creating-body-for-life-app-part-2.html' title='Creating a Body-for-Life App (part 2)'/><author><name>Henry C.</name><uri>http://www.blogger.com/profile/09769937758968410789</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/-sH5RRR6IjbA/TWdSTtB9mVI/AAAAAAAAABA/OsdAg7HXVzg/s220/profilepic.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1454751069877021109.post-2701606389080109256</id><published>2011-02-24T23:48:00.000-08:00</published><updated>2011-02-25T00:24:10.963-08:00</updated><title type='text'>Creating a Body-for-Life App</title><content type='html'>It dawned on me that after I hit 30 I&#39;m kinda really putting on some belly cushion and it&#39;s gaining fast.&amp;nbsp; I had done &quot;Body-for-Life&quot; several years ago but back then I didn&#39;t stick to it very well and ended up quitting.&amp;nbsp; The eating 6 meals in a day was very hard to get used to.&amp;nbsp; Plus the the whole working out thing ... it&#39;s just difficult to get motivated and stay motivated for the entire 12 week program.&amp;nbsp; &lt;br /&gt;&lt;br /&gt;These days I&#39;m a software developer by day and so I spend long hours hunched at my desk.&amp;nbsp; I&#39;m a creature of habit, which means I&#39;m on autopilot with my head full of algorithms.&amp;nbsp; Since I haven&#39;t really developed a routine of eating right or doing exercises daily, it&#39;s very difficult for me to integrate that into a new daily routine.&amp;nbsp; &lt;br /&gt;&lt;br /&gt;What I do get motivated about is trying to develop the next &quot;thing&quot;...&amp;nbsp; an app, a website.&amp;nbsp; Something cool.&amp;nbsp; Number of cool things developed so far: 0.&amp;nbsp; And do I know how to write an iphone app?&amp;nbsp; No.&amp;nbsp; But I&#39;d thought I&#39;d figure it out along the way and I might as well share the experience for anyone else who is interested.&lt;br /&gt;&lt;br /&gt;So in this very first blog post I will show how to create an application that helps with the Body-for-Life cardio work out.&amp;nbsp; In Bill Phillips book, he talks about doing cardio every other day for just 20 minutes.&amp;nbsp; It doesn&#39;t sound like a lot, but he says it&#39;s all you need, and it&#39;s actually pretty intense.&lt;br /&gt;&lt;br /&gt;The way the cardio routine works is that you start off with a level 5 intensity.&amp;nbsp; Where 1 is laying down and 10 is sprinting for your life.&amp;nbsp; You do level 5 for 2 minutes to get warmed up.&amp;nbsp; Then for minute 3 you go to level 6.&amp;nbsp; Minute 4 you go to intensity level 7.&amp;nbsp; In the 5th minute you up it again to level 8 and so on.&amp;nbsp; You go all the way up to level 9 and then come back to level 5 in the next minute.&amp;nbsp; You repeat this pattern 4 times (20 minutes).&amp;nbsp; The last peak you try to get to a level 10.&lt;br /&gt;&lt;br /&gt;But the problem I have is that when I&#39;m running or doing jumping jacks (say, in my living room, cuz I&#39;m too lazy to drive my ass to the gym 10 minutes away even though I paid for the dang membership) I need some kind of timer to look at.&amp;nbsp; I can use my stop watch app inside my iphone but I also forget which intensity level I&#39;m supposed to be at.&lt;br /&gt;&lt;br /&gt;So I thought for my first app, I would attempt to write a application that shows you a stop watch counter plus the intensity number.&amp;nbsp; I know, I know, you were expecting something more impressive?&amp;nbsp; Yeah, but I gotta start somewhere.&amp;nbsp; In addition, I&#39;m more of a web developer, not an objective-c programmer.&amp;nbsp; But I have heard about this project called Phone Gap that allows one to port a web page writting in HTML/CSS/Javascript into a native app.&amp;nbsp; So for this first app, that&#39;s the route I will attempt.&lt;br /&gt;&lt;br /&gt;In my &lt;a href=&quot;http://icanscode.blogspot.com/2011/02/creating-body-for-life-app-part-2.html&quot;&gt;next post&lt;/a&gt;, I&#39;ll talk about how to create the counter and intensity display using javascript.</content><link rel='replies' type='application/atom+xml' href='http://icanscode.blogspot.com/feeds/2701606389080109256/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://icanscode.blogspot.com/2011/02/creating-body-for-life-app.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1454751069877021109/posts/default/2701606389080109256'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1454751069877021109/posts/default/2701606389080109256'/><link rel='alternate' type='text/html' href='http://icanscode.blogspot.com/2011/02/creating-body-for-life-app.html' title='Creating a Body-for-Life App'/><author><name>Henry C.</name><uri>http://www.blogger.com/profile/09769937758968410789</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/-sH5RRR6IjbA/TWdSTtB9mVI/AAAAAAAAABA/OsdAg7HXVzg/s220/profilepic.jpg'/></author><thr:total>0</thr:total></entry></feed>