<?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>Wickedly Smart</title>
	<atom:link href="http://wickedlysmart.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://wickedlysmart.com</link>
	<description>software mastery, the fun way</description>
	<lastBuildDate>Thu, 16 Feb 2012 22:41:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Getting started with HTML5&#8242;s Web Sockets</title>
		<link>http://wickedlysmart.com/2012/getting-started-with-html5s-web-sockets/</link>
		<comments>http://wickedlysmart.com/2012/getting-started-with-html5s-web-sockets/#comments</comments>
		<pubDate>Thu, 16 Feb 2012 22:41:59 +0000</pubDate>
		<dc:creator>Elisabeth</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[web sockets]]></category>

		<guid isPermaLink="false">http://wickedlysmart.com/?p=1569</guid>
		<description><![CDATA[Web Sockets is a new addition to HTML5 that allows you to create a persistent connection with a server for communication. With Ajax, because you&#8217;re using HTTP to communicate, the connection between your client and the server must be reestablished each time you want to get get or send data. This is fine if your [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://en.wikipedia.org/wiki/WebSocket" target="_blank" alt="Wikipedia article on Web Sockets">Web Sockets</a> is a new addition to HTML5 that allows you to create a persistent connection with a server for communication. With Ajax, because you&#8217;re using HTTP to communicate, the connection between your client and the server must be reestablished each time you want to get get or send data. This is fine if your application doesn&#8217;t need to get or send data a lot, but if you&#8217;ve built an application that, for example, gets regular updates of data (e.g. a real-time sports leader board, a stock ticker, a chat room, or a MMOG) then the overhead of creating those connections each and every time can make your app sluggish. Web Sockets can vastly improve the efficiency of communication in these types of apps. Note that as of this post, Web Sockets are supported only in Chrome and Safari.</p>
<p>One of the trickiest things about getting started with Web Sockets is getting a server set up. Because you&#8217;re not using HTTP, you can&#8217;t just use your regular web server. Two implementations of Web Socket severs are socket.io and Jetty, but the set up for these is not obvious, particularly if you&#8217;re a client-side person and don&#8217;t have much experience with the server-side of things.</p>
<p><span id="more-1569"></span></p>
<h2>socket.io</h2>
<p>Socket.io is a Node.js implementation of the Web Socket protocol. That means to use it, you also need Node.js. Fortunately, Node.js is a lot easier to install than it was just a short while ago. You&#8217;ll also need npm (Node Package Manager), which makes installing extensions to node.js, like socket.io, much easier. You&#8217;ll use npm to install socket.io.  Here are the steps and downloads you&#8217;ll need:</p>
<ol>
<li><a target="_blank" href="http://nodejs.org/" alt="node.js home page">Download and install node.js</a>. This one-click install should work on most platforms.</li>
<li><a target="_blank" href="http://npmjs.org/" alt="npm home page">Next, get and install npm</a>. The npm web page has a &#8220;one line install&#8221; that works; except you need to be running as root/administrator to do it. (Mac users: You can also try using sudo on both the curl and sh commands, but that didn&#8217;t work for me). If you&#8217;re on a Mac, to login as root, you&#8217;ll first need to create a root user and then login as root to do the install. Follow <a target="_blank" href="http://support.apple.com/kb/HT1528?viewlocale=en_US&#038;locale=en_US" alt="apple.com instructions for enabling root on a mac">these instructions (apple.com)</a> to enable and login as root. Once you&#8217;re logged in as root, you can run the &#8220;one line&#8221; at npm to do the npm install. Logout of root, back in as your normal user and you can then use npm to install socket.io, in the next step. If you&#8217;re on Windows, you&#8217;ll have to do your own digging as I&#8217;m not up to date on admin stuff on Windows.</li>
<li>To install <a target="_blank" href="http://socket.io/" alt="socket.io home page">socket.io</a>, you&#8217;ll need to download it from <a target="_blank" href="https://github.com/learnboost/socket.io">github</a>. Look for the ZIP link on that page. Unzip to a folder in the directory where you&#8217;re going to run everything, and use npm to install it (from the level above the unzipped folder). To install, type: <code>npm install socket.io</code>. You&#8217;ll see a new folder, <code>node_modules</code> created in the directory, containing socket.io in a configuration that node.js can find it with a <code>require</code>.</li>
</ol>
<p>Now that you&#8217;ve got everything installed, you&#8217;re ready to give it a try. You&#8217;ll need to create two files: the server file, that you&#8217;ll run with node.js, and a client HTML file that you&#8217;ll load in the browser. One tricky thing about socket.io (that took me a while to figure out!) is that the HTML file must be served using the Web Socket server to use the socket.io client library. I tried writing basic HTML5 Web Socket code, but I kept running into a bug, and apparently it&#8217;s a known and common bug, so the recommendation is that you use the socket.io client library to connect to the server. Unfortunately this hides the HTML5 Web Socket communications code, which is what you really want to learn, but that&#8217;s the current state of things with socket.io (from my understanding, anyway, and certainly my experience was that I ran into the bug). </p>
<h3>Server code</h3>
<p>Create a new file, ss.js and add the server code: </p>
<pre>
var app = require('http').createServer(handler)
  , io = require('socket.io').listen(app)
  , fs = require('fs')

app.listen(8080);

function handler (req, res) {
  fs.readFile(__dirname + '/index.html',
  function (err, data) {
    if (err) {
      res.writeHead(500);
      return res.end('Error loading index.html');
    }

    res.writeHead(200);
    res.end(data);
  });
}

io.sockets.on('connection', function (socket) {
  socket.emit('news', { hello: 'world' });
  socket.on('my other event', function (data) {
    console.log(data);
  });
});
</pre>
<p>This code is copied directly from the <a target="_blank" href="http://socket.io/#how-to-use">socket.io</a> web site (first example), although I did change the port to 8080, as I already have an HTTP server running on port 80. First, we create an HTTP server. The callback function for the server (that is, the function that gets called when a connection is requested) is the <code>handler</code> function. This serves an index.html file, which is where you&#8217;ll put the client code. This is just a very basic http file server, so if you want a more fully functional web server, you&#8217;ll need to use Express, and there are instructions on how to use that on the socket.io web site. I&#8217;m not going to go into that in this article. </p>
<p>After setting up the http server, we then set up the Web Socket handler. The Web Socket connections will come in on the same port as the HTTP requests, 8080, but use a different protocol (ws rather than http). When a ws connection is received, a socket is created, and we send a message to the client over that socket. The message consists of the event type and an object with one property, <code>hello</code>. </p>
<p>We also set up a message handler for the socket. When a message is received from the client, we just log it to the console. Due to lack of documentation at socket.io, I&#8217;m a little unclear on the first argument to <code>socket.emit</code> and <code>socket.on</code> but I believe it&#8217;s the event type. You can use built-in event types, like &#8220;connection&#8221;, or create custom event types, like &#8220;my other event&#8221;. </p>
<h3>Client code</h3>
<p>Now for the client. Create a file, <code>index.html</code> (remember our basic server is only going to serve index.html! Feel free to rename the file but you&#8217;ll need to change the name in the server code too).  Here&#8217;s my code (slightly modified from the code in the example on socket.io):</p>
<pre>
&lt;!doctype html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;web sockets&lt;/title&gt;
&lt;meta charset="utf-8"&gt;
&lt;script src="/socket.io/socket.io.js"&gt;&lt;/script&gt;
&lt;script&gt;
var socket = io.connect('http://localhost:8080');
socket.on('news', function (data) {
    console.log(data);
    writeMessage(data);
    socket.emit('my other event', { my: 'data' });
});

function writeMessage(msg) {
    var msgArea = document.getElementById("msgArea");
    if (typeof msg == "object") {
        msgArea.innerHTML = msg.hello;
    }
    else {
        msgArea.innerHTML = msg;
    }
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div id="msgArea"&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>Notice that we&#8217;re using the same port as we are listening on in the server, 8080. These two must match! Also notice that we&#8217;re including the socket.io JavaScript from the path: /socket.io/socket.io.js. The / at the beginning means &#8220;root&#8221;. The server is running in the directory where you&#8217;re putting these files, and that&#8217;s considered the &#8220;root&#8221;. The socket.io library is installed in this same directory for node.js, so this path will be found when you request this file using localhost:8080, which points to your node server.  The node server does some magic that allows all the code in the socket.io.js file to be understood by the browser. If you try to load this file without socket.io and node, it will fail miserably. This was a tricky bit for me to understand so make sure you&#8217;ve got everything in the right place!</p>
<p>So, to try this, you first need to run the node server, and then load up your index.html file in the browser:</p>
<ol>
<li>To run the node server, type <code>node ss.js</code>. You should see:
<pre>
info  - socket.io started
</pre>
</li>
<li>Now, use your browser to load http://localhost:8080. If all goes well, it will connect to the server and you&#8217;ll see &#8220;world&#8221; in your page, and in the console, where you&#8217;re running the server, you&#8217;ll see:
<pre>
   debug - served static content /socket.io.js
   debug - client authorized
   info  - handshake authorized 1292119758764894899
   debug - setting request GET
           /socket.io/1/websocket/1292119758764894899
   debug - set heartbeat interval for client
           1292119758764894899
   debug - client authorized for
   debug - websocket writing 1::
   debug - websocket writing 5:::
           {"name":"news","args":[{"hello":"world"}]}
   debug - websocket received data packet 5:::
           {"name":"my other event","args":[{"my":"data"}]}
           { my: 'data' }
</pre>
</ol>
<p>And voila, you have just used Web Sockets to send and receive a message from a server! Whew! </p>
<h2>Jetty</h2>
<p>Another option, and one that allows you to write HTML5 Web Socket code on the client, rather than using a framework, is to use a Jetty Web Socket server. <a target="_blank" href="http://www.eclipse.org/jetty/" alt="Jetty home page">Jetty</a> is a Java HTTP server and servlet container, and has an implementation of <a target="_blank" href="http://wiki.eclipse.org/Jetty/Feature/WebSockets" alt="Jetty Web Sockets documentation page">Web Sockets</a>, and a Web Socket test server. I&#8217;ll explain how to get the Jetty Web Socket test server up and running, and then how to create a client that uses HTML5 Web Sockets to send and receive messages.</p>
<p>First, you&#8217;ll need to download Jetty. You can download the entire Jetty folder here: <a target="_blank" href="http://download.eclipse.org/jetty/" alt="download page for Jetty">http://download.eclipse.org/jetty/</a>. This includes all the jar files you&#8217;ll need except one; also download the jetty-all jar file, which includes everything; this makes it simpler to compile and run:</p>
<p><code></p>
<p>http://repo1.maven.org/maven2/org/eclipse/jetty/aggregate/\<br />jetty-all/$JETTY_VERSION/jetty-all-$JETTY_VERSION.jar</p>
<p></code></p>
<p>where $JETTY_VERSION corresponds to the version of jetty you downloaded previously. The version I downloaded was: 8.1.0.v20120127, so my url for downloading the jetty-all file was:</p>
<p><code></p>
<p>http://repo1.maven.org/maven2/org/eclipse/jetty/aggregate/\<br />jetty-all/8.1.0.v20120127/jetty-all-8.1.0.v20120127.jar</p>
<p></code></p>
<p>On the Mac, you can use curl to get this file easily:<br />
<code><br />
curl http://repo1.maven.org/maven2/org/eclipse/jetty/aggregate/\<br />jetty-all/8.1.0.v20120127/jetty-all-8.1.0.v20120127.jar \<br />
> jetty-all-8.1.0.v20120127.jar<br />
</code></p>
<p>Create a folder, and place jetty-all-8.1.0.v20120127.jar as well as servlet-api-3.0.jar (you&#8217;ll find that in the full Jetty distribution you downloaded previously) in that folder. </p>
<h3>The server</h3>
<p>On the <a target="_blank" href="http://wiki.eclipse.org/Jetty/Feature/WebSockets" alt="Jetty Web Sockets documentation page">Jetty Web Sockets page</a>, the documentation says you can run the test server directly. I wasn&#8217;t able to do this (I get an error). So I copied the <a target="_blank" href="http://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/tags/jetty-7.4.0.v20110414/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/TestServer.java" alt="Jetty Web Sockets server side code for Test Server">server code</a> and built it myself. The code seems to be missing the following import:</p>
<pre>
import org.eclipse.jetty.websocket.*;
</pre>
<p>so I added that before compiling. You&#8217;ll need to compile with the jetty-all-8.1.0.v20120127.jar and servlet-api-3.0.jar. I did this using Eclipse, so to run the Test Server, I exported a jar file, and placed it in the same directory with jetty-all-8.1.0.v20120127.jar and servlet-api-3.0.jar.  If you want to do it from the command line, you can do this:</p>
<p><code><br />
javac -cp jetty-all-8.1.0.v20120127.jar:servlet-api-3.0.jar \<br />
TestServer.java <br />
jar -cf TestServer.jar *.class<br />
</code></p>
<p>Once you&#8217;ve got the Test Server built, you can run it like this:</p>
<p><code><br />
java -cp .:TestServer.jar:servlet-api-3.0.jar:\<br />jetty-all-8.1.0.v20120127.jar TestServer \<br />--port 8080 --docroot . --verbose<br />
</code></p>
<p>You&#8217;ve now got a Web Socket server running at port 8080.</p>
<p>If you take a look at the code, you&#8217;ll notice that there are several different &#8220;protocols&#8221; supported. The protocol is actually a sub-protocol of the Web Socket protocol and allows the server to further refine the types of connections it will accept. </p>
<p>The Jetty Web Socket server supports several different sub-protocols, and the one I found most useful when testing is the &#8220;org.ietf.websocket.test-echo-assemble&#8221; sub-protocol. This one tells the Jetty server to send a message back, echoing the data you sent from the client. This is a good way to test to make sure your code is working. You can specify which sub-protocol to use in the client code, when you connect.</p>
<h3>The client</h3>
<p>Now that you have a server running, it&#8217;s time to create the client. I based my code on code in this <a target="_blank" href="http://net.tutsplus.com/tutorials/javascript-ajax/start-using-html5-websockets-today/" alt="NetTut on Web Sockets">NetTut</a> tutorial, but changed it a bit to suit my needs and make it a bit clearer.</p>
<p>Here&#8217;s the code:</p>
<pre>
&lt;!doctype html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Node Test&lt;/title&gt;
&lt;meta charset="utf-8"&gt;
&lt;script&gt;
window.onload = init;

function message(message) {
  var msg = document.getElementById("msg");
  msg.innerHTML += message;
}

function init() {
  var socket;
  if (!("WebSocket" in window)){
    message("Sorry, no web sockets");
  }
  else {
    //The user has WebSockets
    setUpHandlers();
    connect();  

    function connect(){
      var host = "ws://localhost:8080/";
      var protocol = "org.ietf.websocket.test-echo-assemble"; 

      try {
          socket = new WebSocket(host, protocol);
          message('&lt;p class="event"&gt;Socket Status: '
                   +socket.readyState + "&lt;/p&gt;");
          socket.onopen = function() {
             message('&lt;p class="event"&gt;Socket Status: '
                     +socket.readyState+' (open)&lt;/p&gt;');
          }
          socket.onmessage = function(msg) {
             message('&lt;p class="message"&gt;Received: '
                     + msg.data + "&lt;/p&gt;");
          }
          socket.onclose = function() {
             message('&lt;p class="event"&gt;Socket Status: '+
                      socket.readyState+' (Closed)&lt;/p&gt;');
          }
       } catch(exception) {
          message('&lt;p&gt;Error'+exception + "&lt;/p&gt;");
       }
    }//End connect  

    function send() {
      var text = document.getElementById("text").value;
      if (text=="") {
        message('&lt;p class="warning"&gt;Please enter a message&lt;/p&gt;');
        return ;
      }
      try {
        socket.send(text);
        message('&lt;p class="event"&gt;Sent: '+text+"&lt;/p&gt;");
      } catch(exception) {
        message('&lt;p class="warning"&gt;' + exception.text + "&lt;/p&gt;");
      }
    }//End send

    function setUpHandlers() {
      var sendButton = document.getElementById("send");
      sendButton.onclick = function() {
        send();
      };
      var disconnectButton = document.getElementById("disconnect");
      disconnectButton.onclick = function() {
        socket.close();
      };
    }//End setUpHandlers
  }//End else
} //End init
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
  &lt;div id="msg"&gt;
  &lt;/div&gt;
  &lt;form&gt;
    &lt;input id="text" size="40"&gt;
    &lt;input type="button" id="send" value="Send"&gt;
    &lt;input type="button" id="disconnect" value="Disconnect"&gt;
  &lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>In this code, we use a form to get a message from the user to send to the server, which the server will echo back. </p>
<p>We set up the connection to the server with the line:</p>
<p><code><br />
socket = new WebSocket(host, protocol);<br />
</code></p>
<p>Note that the host points to the local Jetty server which is running on port 8080. The protocol is &#8220;org.ietf.websocket.test-echo-assemble&#8221;, which tells the server to echo back the message you send to it.</p>
<p>We set up handlers for various socket events and states. We use <code>onopen</code> to set up a callback when the socket is opened successfully, and <code>onclose</code> to set up a callback when the socket is closed. If a message is received, we handle it with the callback set up for <code>onmessage</code>.</p>
<p>Try typing a word or two in the form, and click Send. This calls the <code>send()</code> function, which sends a message to the server using <code>socket.send()</code>. The server echoes that message back to the client, so you should see the words you typed appear in the page. You can keep sending messages to (and receiving messages from) the server (all on the same socket connection), until you click Disconnect, which terminates that socket connection.</p>
<p>Web Sockets are not for the faint of heart, for sure! In this post, we&#8217;ve looked at how to get a Web Socket server up and running and create a very basic client to connect to the server, send messages to the server, and receive messages from the server. In a future post, we&#8217;ll do something more fun with Web Sockets.</p>
]]></content:encoded>
			<wfw:commentRss>http://wickedlysmart.com/2012/getting-started-with-html5s-web-sockets/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Reader Question: How to look at the computed style of an element?</title>
		<link>http://wickedlysmart.com/2012/reader-question-how-to-look-at-the-computed-style-of-an-element/</link>
		<comments>http://wickedlysmart.com/2012/reader-question-how-to-look-at-the-computed-style-of-an-element/#comments</comments>
		<pubDate>Tue, 14 Feb 2012 02:06:53 +0000</pubDate>
		<dc:creator>Elisabeth</dc:creator>
				<category><![CDATA[Beginner's Mind]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[Reader Question]]></category>
		<category><![CDATA[CSS]]></category>

		<guid isPermaLink="false">http://wickedlysmart.com/?p=1561</guid>
		<description><![CDATA[We recently got a question from Michael, who asks: When troubleshooting CSS issues, how can I determine the source of a style that is applied to an element? My favorite way to figure out how an element is getting its style is to use the Element inspector in the Safari or Chrome browser. Let&#8217;s use [...]]]></description>
			<content:encoded><![CDATA[<p>We recently got a question from Michael, who asks:</p>
<blockquote><p>
When troubleshooting CSS issues, how can I determine the source of a style that is applied to an element?
</p></blockquote>
<p>My favorite way to figure out how an element is getting its style is to use the Element inspector in the Safari or Chrome browser. Let&#8217;s use the web page at <a href="http://starbuzzcoffee.com/">Starbuzz Coffee</a> as an example. Load the page in one of these browsers, and then open up the inspector. In Safari, use the Develop &gt; Show Web Inspector menu, and in Chrome, right click on any part of the page and choose Inspect Element.</p>
<p>Once you have the inspector open, make sure the Elements tab is selected. It should look like this:</p>
<p><a href="http://wickedlysmart.com/wp-content/uploads/2012/02/starbuzz.jpg"><img src="http://wickedlysmart.com/wp-content/uploads/2012/02/starbuzz-827x1024.jpg" alt="" title="starbuzz" width="500" class="aligncenter size-large wp-image-1564" style="box-shadow: 1px 1px 7px gray;" /></a></p>
<p>Here, I&#8217;ve selected the &#8220;header&#8221; &lt;div&gt; element in the main window on the left, and on the right, I&#8217;ve opened up the Computed Style and Styles inspectors. These are incredibly useful tools for figuring out where the style of an element is coming from, which is helpful especially if you&#8217;ve got a lot of CSS!</p>
<p>Notice, that in the case of the &#8220;header&#8221; &lt;div&gt;, the matched rules (ie, the rules I specifically wrote for #header) show the background-color, margin and height properties. Also note that my user agent (that is, the default CSS in the browser) is setting the &lt;div&gt; to block display. The font-family and font-size are being inherited from the body element, which I&#8217;m also setting in my CSS. </p>
<p>Now, to see all the CSS that the browser has computed for the &#8220;header&#8221; &lt;div&gt; at the time the page is inspected, look in the Computed Styles section. Notice that you can find out the values of properties you&#8217;re not setting directly, like the current width and height of an element, using Computed Style. </p>
<p>You can usually find any discrepancies between what you <em>think</em> the style of an element should be and what it <em>actually is</em> by comparing the Computed Style with the styles you (and your user agent) are setting on the element.</p>
<p>I hope this answers your question Michael! Good luck finding your CSS bug.</p>
]]></content:encoded>
			<wfw:commentRss>http://wickedlysmart.com/2012/reader-question-how-to-look-at-the-computed-style-of-an-element/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Reader Question: How to learn to program</title>
		<link>http://wickedlysmart.com/2012/reader-question-how-to-learn-to-program/</link>
		<comments>http://wickedlysmart.com/2012/reader-question-how-to-learn-to-program/#comments</comments>
		<pubDate>Sat, 28 Jan 2012 21:17:06 +0000</pubDate>
		<dc:creator>eric</dc:creator>
				<category><![CDATA[Beginner's Mind]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[learning]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[reader question]]></category>

		<guid isPermaLink="false">http://wickedlysmart.com/?p=1549</guid>
		<description><![CDATA[A reader from Kenya asks how best to get into programing. Eric Freeman answers the question, and the answer may not be what you expected&#8230;view the video below:]]></description>
			<content:encoded><![CDATA[<p>A reader from Kenya asks how best to get into programing. Eric Freeman answers the question, and the answer may not be what you expected&#8230;view the video below:</p>
<p style="clear:both; padding-top: 20px; text-align:center;">
<iframe src="http://player.vimeo.com/video/35810457?title=0&amp;byline=0&amp;portrait=0" width="400" height="225" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe></p>
]]></content:encoded>
			<wfw:commentRss>http://wickedlysmart.com/2012/reader-question-how-to-learn-to-program/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Reader Question: Incrementing variables</title>
		<link>http://wickedlysmart.com/2012/reader-question-incrementing-variables/</link>
		<comments>http://wickedlysmart.com/2012/reader-question-incrementing-variables/#comments</comments>
		<pubDate>Thu, 19 Jan 2012 23:34:35 +0000</pubDate>
		<dc:creator>Elisabeth</dc:creator>
				<category><![CDATA[Beginner's Mind]]></category>
		<category><![CDATA[Reader Question]]></category>

		<guid isPermaLink="false">http://wickedlysmart.com/?p=1544</guid>
		<description><![CDATA[I got a good reader question today about incrementing variables. This reader is completely new to programming and was getting confused about two common ways to increment variables: count = count + 1; a statement that often appears in a while loop, and i++; a statement that often appears in a for loop, like this: [...]]]></description>
			<content:encoded><![CDATA[<p>I got a good reader question today about incrementing variables. This reader is completely new to programming and was getting confused about two common ways to increment variables:</p>
<pre>
  count = count + 1;
</pre>
<p>a statement that often appears in a while loop, and</p>
<pre>
  i++;
</pre>
<p>a statement that often appears in a for loop, like this:</p>
<pre>
  for (var i = 0; i < 10; i++) {
    ...
  }
</pre>
<p>While this question is about JavaScript, these lines of code could appear identically (or almost identically) in many languages! In <a href="http://www.amazon.com/exec/obidos/ASIN/1449390544/elisabethfree-20">Head First HTML5 Programming</a>, we speed through these language basics pretty quickly, so it's understandable that someone new to programming might be a bit confused on this point. Plus, and I hate to admit this, I think we completely forgot to explain what operators <code>++</code> and <code>--</code> actually do! (We'll fix that on the next printing!)</p>
<p>The trick to understanding the first one is to remember that when you use <code>=</code>, you are <em>assigning</em> a value to a variable. You're <em>not</em> comparing two values; you do that with the comparison operator, which is <code>==</code>.  </p>
<p>So, when you write</p>
<pre>
  count = count + 1;
</pre>
<p>you are saying: "Take the current value of the variable <code>count</code>, add 1 to it, and then change the value of <code>count</code> to that new value."</p>
<p>So if <code>count</code> is equal to 4, and you run this line of code, after you run the code, the value of <code>count</code> will be 5. </p>
<p>Adding 1 to the value of a variable is something we do <em>so</em> often in programming that language designers have added shortcuts to make it even easier to add 1 to a variable with a number value. One shortcut used in many languages is the <code>++</code> operator. Writing</p>
<pre>
  i++;
</pre>
<p>is the same as writing</p>
<pre>
  i = i + 1;
</pre>
<p>It's just a shortcut to do the same thing.  So, when you see a for loop like this:</p>
<pre>
  for (var i = 0; i < 10; i++) {
    ...
  }
</pre>
<p>there are three things happening in that for loop: the first part, <code>var i = 0;</code>, declares and initializes the the variable <code>i</code> to the value 0. Then the <em>conditional expression</em> is run: <code>i < 10</code>. This says, is <code>i</code> less than 10? Well, if we just started the loop it is less than 10, in fact it's 0. In that case, all the statements in the body of the for loop are run (that is, everything between the { and the }). Finally, the value of <code>i</code> is incremented with <code>i++</code>, making the new value of <code>i</code> equal to 1. Then you start over, except you skip the initialization bit. So you go right to the conditional expression: is <code>i</code> still less than 10? Yes, it's 1. So run all the statements in the body of the for loop again. And so on. When <code>i</code> is incremented to 10, then the for loop stops because the conditional expression is no longer true.</p>
<p>An analogous operator to <code>++</code> is <code>--</code> which subtracts 1 from the value of a variable. In other words, writing</p>
<pre>
  i--;
</pre>
<p>is the same as writing</p>
<pre>
  i = i - 1;
</pre>
<p>I hope that helps clear up that reader question. Keeping send me your questions if you run into any problems. Thank you!</p>
]]></content:encoded>
			<wfw:commentRss>http://wickedlysmart.com/2012/reader-question-incrementing-variables/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Reader Question: What are -webkit- and -moz-?</title>
		<link>http://wickedlysmart.com/2011/reader-question-what-are-webkit-and-moz/</link>
		<comments>http://wickedlysmart.com/2011/reader-question-what-are-webkit-and-moz/#comments</comments>
		<pubDate>Mon, 12 Dec 2011 18:54:45 +0000</pubDate>
		<dc:creator>Elisabeth</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Reader Question]]></category>
		<category><![CDATA[-webkit-]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[css3]]></category>

		<guid isPermaLink="false">http://wickedlysmart.com/?p=1524</guid>
		<description><![CDATA[We recently got a question from Jack, a reader of Head First HTML5 Programming, about the CSS used in the example in Chapter 3. In this example, we create a web application that creates a playlist from songs the user types into a form field on the web page, and of course, we&#8217;re using JavaScript [...]]]></description>
			<content:encoded><![CDATA[<p>We recently got a question from Jack, a reader of <a href="http://www.amazon.com/exec/obidos/ASIN/1449390544/elisabethfree-20">Head First HTML5 Programming</a>, about the CSS used in the example in Chapter 3. In this example, we create a web application that creates a playlist from songs the user types into a form field on the web page, and of course, we&#8217;re using JavaScript to dynamically update the page. Jack is curious about how the CSS for the example works: </p>
<blockquote><p>
Although the CSS seems to render OK, my IDE doesn&#8217;t seem to like a lot of it. I&#8217;m using Intellij IDEA (Java IDE) which is HTML and JavaScript capable. I&#8217;m also using the current versions of Firefox and Safari (Mac OS/X, Lion 10.7.2). Of course, I&#8217;m only on chapter 3 so have no idea what the -webkit or -moz are.  Do I need to include something else in my project?
</p></blockquote>
<p>What&#8217;s happening here is that Jack&#8217;s IDE, Intellij, doesn&#8217;t recognize the new CSS3 property <code>border-radius</code>, or the browser specific versions of this property. Here&#8217;s an example of the CSS we use in that example:</p>
<pre>
ul#playlist {
    border: 1px solid #a9a9a9;
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
    border-radius: 5px;
    margin-top: 10px;
    padding: 0px;
    list-style-type: none;
}
</pre>
<p>We actually never get into explaining -webkit- and -moz- (and the other browser-specific CSS properties) in <a href="http://www.amazon.com/exec/obidos/ASIN/1449390544/elisabethfree-20">Head First HTML5 Programming</a>, as we focus almost entirely on the JavaScript APIs, and will be going back to update our <a href="http://www.amazon.com/exec/obidos/ASIN/059610197X/elisabethfree-20">Head First HTML &#038; CSS book</a> to address updates in CSS.  </p>
<p>Some of the new CSS3 properties haven&#8217;t yet been finalized (CSS3 is still very much in development) and many of the browsers implemented early versions of these new ideas, and use the -name- prefix (like -webkit-, -moz-, -o-, and -ms-) as a way to say, &#8220;This is Mozilla&#8217;s or Webkit&#8217;s idea of what the property should be, but it&#8217;s not written in stone yet.&#8221;  So, to get your CSS to work in multiple browsers, you have to supply <em>all</em> the browser specific versions, <strong>plus</strong> the version that we <em>think</em> will eventually be the one that gets finalized in the standard!  </p>
<p>Whew.  </p>
<p>So, a new property like <code>border-radius</code> has a Webkit version, <code>-webkit-border-radius</code>, and a Mozilla version, <code>-moz-border-radius</code>, and so on.  Webkit is the browser engine used by Chrome and Safari; Mozilla is the engine used by Firefox.  -ms is for IE and -o is for Opera.  The trick is to put the browser-specific versions above (what we think will be) the actual property name (in the ordering in the CSS rule) so that the browser will use the last one it recognizes, and so will override an older browser-specific implementation with the new, final implementation when it&#8217;s complete.  </p>
<p>Not all properties have implementations in all the browsers yet, and some &#8220;final&#8221; (or close to final) versions have been implemented in some browsers (for instance, for <code>border-radius</code>, you can use <code>border-radius</code> instead of <code>-webkit-border-radius</code>, and it will work in the most recent version of Safari and in Chrome).  </p>
<p>Anyway, as you can see, it&#8217;s a bit of a mess right now, but should get cleared up as time goes on.  Jack&#8217;s IDE simply doesn&#8217;t know about these browser-specific properties (or, perhaps, the new CSS property at all) and so is highlighting these properties as potential problems.  The key is to test in the browsers, and also check sites like <a href="http://caniuse.com/">caniuse.com</a>.  For example, if you <a href="http://caniuse.com/#search=border-radius">search for &#8220;border-radius&#8221; on caniuse.com</a>, you&#8217;ll see that current versions of Safari, Firefox, Chrome, and Opera all support the <code>border-radius</code> property now, but slightly older versions of IE and Safari either don&#8217;t support it at all or require the browser-specific property name.  </p>
<p>In general, with CSS, if you want to use a &#8220;new&#8221; CSS3 property that may not be supported by all browsers (particularly if you think your users are still using old versions of browsers), you&#8217;ll want to make sure you either test to see if that user&#8217;s browser supports it (using Modernizr) and supply an alternative stylesheet if it doesn&#8217;t, or test to make sure that the page looks fine without that particular stylistic feature. For instance, if you are using CSS to do a complex layout then you&#8217;ll want to make sure the browser supports the layout properties you&#8217;re using and offer an alternative stylesheet with an older style layout if it doesn&#8217;t. For something like <code>border-radius</code>, generally, the page will look fine if your elements don&#8217;t have rounded corners so it doesn&#8217;t matter as much.</p>
<p>Thanks for the great question Jack!</p>
]]></content:encoded>
			<wfw:commentRss>http://wickedlysmart.com/2011/reader-question-what-are-webkit-and-moz/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Ten things every developer (and manager) should know about HTML5</title>
		<link>http://wickedlysmart.com/2011/ten-things-every-developer-and-manager-should-know-about-html5/</link>
		<comments>http://wickedlysmart.com/2011/ten-things-every-developer-and-manager-should-know-about-html5/#comments</comments>
		<pubDate>Thu, 08 Dec 2011 13:50:56 +0000</pubDate>
		<dc:creator>eric</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Events]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[client side]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[markup]]></category>
		<category><![CDATA[video]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://wickedlysmart.com/?p=1127</guid>
		<description><![CDATA[Learn ten things every web developer (not to mention every web developer manager) should know about HTML5. You never know this information just might be the make/break tip for your next startup, or it might even get you that new raise. In the worst case you've got some good geek tips for your next geek mixer.]]></description>
			<content:encoded><![CDATA[<p>If you missed our heavily-attended O&#8217;Reilly Webcast on December 2nd, no worries, because the presentation is <a href="http://oreillynet.com/pub/e/2099">now available online</a>. In addition, you&#8217;ll find a cliff notes version below:</p>
<p><strong>1. HTML5 Markup isn&#8217;t such a big deal.</strong></p>
<p>To understand this statement you need to first understand what HTML5 is. Is it just an incremental update to HTML4.01? Or is it something new and completely different (you might think so with all the hype around it)? The answer is really a bit of both. HTML5 does include many simplifications and additions to HTML markup, and so it is fair to call markup an incremental update (although it does have a few big additions like &lt;video&gt; and &lt;canvas&gt;). But, HTML5 also can be thought of as a family of technologies that include a whole set of new JavaScript APIs that interoperate with HTML5 markup. Let&#8217;s also not forget CSS3, which brings some powerful new styling and animation techniques to HTML5. </p>
<p>Check out the <a href="http://oreillynet.com/pub/e/2099">presentation</a> to see some of the new markup included in HTML5. If you&#8217;re already up to speed on the markup in HTML4, most of the new markup will be fairly easy for you to get under your belt.</p>
<p><strong>2. The power of HTML5 is JavaScript.</strong></p>
<p>While we&#8217;ve all been hearing &#8220;HTML5 HTML5 HTML5&#8243;, the real unsung hero of HTML5 is JavaScript and the new set of HTML5 compatible APIs. With these APIs you can now incorporate geolocation, a drawable canvas, custom video experiences, drag and drop, large amounts of local storage and even multithreaded JavaScript into your web pages (more like apps these days), and that&#8217;s just naming a few of the APIs.</p>
<p>JavaScript has developed a bit of a bad rap as a scripting language over the years, when in fact it&#8217;s a sophisticated and powerful language. Today, it&#8217;s also a fast language, having seen 100x speed improvement over the last decade (with more coming). Sure, it has a few warts here and there, but these are easy to work around if you know about them. And, JavaScript is an easy language to get started with. We devote four chapters of our new book <a href="http://www.amazon.com/exec/obidos/ASIN/1449390544/ericsbooks04">Head First HTML5 Programming</a> to getting you up to speed on JavaScript.</p>
<p>So, If you want to make the most out of HTML5, you&#8217;ll need to learn JavaScript.</p>
<p><strong>3. It&#8217;s not which standards document an API comes from that is important.</strong></p>
<p>As we wrote <a href="http://www.amazon.com/exec/obidos/ASIN/1449390544/elisabethfree-20">Head First HTML5 Programming</a> we commonly heard things like &#8220;Oh, geolocation is not part of the official HTML5 spec!&#8221; True enough. But it is an official spec of the W3C, and you know what, it doesn&#8217;t matter. Here <em>is</em> what matters: does every modern browser implement and support geolocation? That&#8217;s what we care about.</p>
<p>Sure, there is a time and place to be precise about specification relationships, but when we&#8217;re writing code, the important thing is &#8220;Will it be there for my users?&#8221;</p>
<p><strong>4. How to know if you should embrace HTML5 now.</strong></p>
<p>Check out the <a href="http://oreillynet.com/pub/e/2099">presentation</a> for a simple flow chart to guide you. But for now it goes like this: If your users are using mobile devices, you should be thinking about using HTML5 today, as HTML5 browsers are common and heavily used on today&#8217;s smartphones and tablets.</p>
<p>If your audience is desktop based and uses largely modern browsers, you&#8217;re also good to go and should be looking into HTML5. However if your audience uses older versions of IE, you&#8217;ll need to be cautious.</p>
<p>In any case you always want to make sure you&#8217;re using feature detection (see below) and are up to date on which browsers support which features. Fortunately, there are a number of great resources for getting information about browser support for HTML5. A few of our favorites include:</p>
<ul>
<li><a href="http://caniuse.com/">http://caniuse.com/</a>.</li>
<li><a href="http://www.findmebyip.com/">http://www.findmebyip.com/</a>.</li>
<li><a href="http://html5test.com/">http://html5test.com/</a>.</li>
<li>Wikipedia&#8217;s <a href="http://en.wikipedia.org/wiki/Comparison_of_web_browsers">Comparison of Web Browsers</a> page and <a href="http://en.wikipedia.org/wiki/Comparison_of_layout_engines_(HTML_5)">Comparison of Layout Engines</a> page.</li>
<li>WHATWG&#8217;s <a href="http://wiki.whatwg.org/wiki/Implementations_in_Web_browsers">Implementations in Web Browsers</a> wiki page.</li>
</ul>
<p>And of course, you should always test your web pages and applications in every browser you can!</p>
<p><strong>5. Make it easy on yourself: graceful degradation and feature detection.</strong></p>
<p>There are many ways to detect the features of HTML5 using JavaScript, from attempting to create an object to see if it&#8217;s supported, to checking to see if various <code>window</code> properties exist, to using custom methods like the &lt;video&gt; element API&#8217;s <code>canPlayType</code> method.</p>
<p>Needless to say, it&#8217;s important to check for new features so you can offer a fallback experience for users whose browsers don&#8217;t support that feature (e.g. an image or flash video instead of HTML5 video, an image or embedded Flash object instead of canvas, or even just a message indicating why the user might not be seeing what they expect and why). But with so many different ways of checking support for different features, you might be wondering if there isn&#8217;t a better way?</p>
<p>There is. The <a href="http://www.modernizr.com/">Modernizr JavaScript library</a> is a popular open-source library that you can use to make it much easier to check for HTML5 and CSS3 features and load appropriate resources, such as different JavaScript files, CSS files, images, and so on, depending on support.</p>
<p>Check out the <a href="http://oreillynet.com/pub/e/2099">presentation</a> for more concrete examples.</p>
<p><strong>6. The &lt;video&gt; tag is the easy part; what about encodings?</strong></p>
<p>If you&#8217;ve heard one thing about HTML5, it&#8217;s probably that it has a &lt;video&gt; element. And it&#8217;s true, by adding a &lt;video&#038;gt element to your HTML you can easily play video in your page without a plug-in. This is made possible by the folks writing the browsers, because they all agree on what the &lt;video&gt; element looks like. But when it comes to video formats, unfortunately, there is little agreement. Today, there are three different container formats, WebM, MP4 and Ogg, and which one you need depends on which browsers your users are using. If you&#8217;re delivering content to a narrow audience, say, users of the iPad, then your job is easy: you need only to deliver one format, MP4. If you want to support all popular browsers, then you need all three formats.</p>
<p>How? You&#8217;ll have to arrange to have the encodings done, and in the markup you can use the &lt;video&gt; element with the &lt;source&gt; element and provide multiple video files. To have more flexibility in creating a fallback if none of these types is recognized, you need to use JavaScript.</p>
<p>So, while getting a video into your web page is easier than ever before, making sure you&#8217;ve got a video that your users can actually play is still a bit of a mess.</p>
<p><strong>7. The &lt;canvas&gt; is for more than just drawing.</strong></p>
<p>The &lt;canvas&gt; element adds a native 2D drawing area to HTML.  At first glance, you might think &lt;canvas&gt; is best for creating simple drawing programs using lines, arcs, and rectangles, but you&#8217;d be short-changing yourself if you stop there.</p>
<p>In fact, if you have a look at the canvas demos on the web, you&#8217;ll see that it&#8217;s being used for everything from basic drawings, to fully interactive drawing applications, <a href="http://wickedlysmart.com/2011/how-to-make-a-pie-chart-with-html5s-canvas/">creating graphs</a>, making animations, building games, and even rendering 3D scenes.</p>
<p>One interesting use for &lt;canvas&gt; is video processing. You can take video frames from the video player, process the frame data, and then write the data into a canvas for display. For instance, you might take green screen capture video, and add a background in real-time using this technique.  Similarly, you can use a canvas for double buffering image in games.</p>
<p>So, don&#8217;t overlook the &lt;canvas&gt;; it&#8217;s a powerful new feature of HTML5 that can be used for all kinds of graphics-related applications, and the JavaScript engines in modern browsers are now fast enough to handle the load that graphics and video processing require.</p>
<p><strong>8. Some of the common JavaScript-based idoms for animation and effects are now supported by CSS3.</strong></p>
<p>CSS has come along way from the early days, and with CSS3, we now have powerful features that you can use to create effects in your web pages that you once could do only with JavaScript.</p>
<p>For instance, used to be if you wanted an element to fade in and out on a mouse hover, you&#8217;d have to write some fairly complex JavaScript code or use a UI library like jQuery or scriptaculous. These libraries have by no means been replaced by CSS3, but there are a few things you can do now with no code at all.</p>
<p>The <strong>transition</strong> and <strong>transform</strong> properties are two new properties in CSS3 that let you create interesting effects and animations. For instance, you can create a fading effect by transitioning the opacity of an element. You can manipulate elements with transform functions like rotate and scale, and when you combine a transform with a transition, create some pretty cool animations. </p>
<p>In the <a href="http://oreillynet.com/pub/e/2099">presentation</a>, we show two simple examples of using transition and transform. </p>
<p><strong>9. JSON is the new king of content formats.</strong></p>
<p>In 2004 XML was going to rule the world, however things didn&#8217;t quite work out that way.<br />
These days, many developers are using JSON instead of XML. JSON, or &#8220;JavaScript Object Notation&#8221;, allows you to use the same format for your code and your serialized objects. You also get fast parsing for free from the browser when you retrieve remote JSON data. Every browser has a built-in JSON object with two methods: <code>stringify</code>, used to create a JSON string from a JavaScript object, and <code>parse</code>, used to create a JavaScript object from a JSON string.</p>
<p>Today JSON is widely supported across web service APIs, like Twitter and Facebook. And, because of the cross-domain restrictions with XHR, many web services are implementing JSONP, or JSON with Padding. While &#8220;JSON with Padding&#8221; isn&#8217;t the most insightful name, JSONP is a convention for implementing a callback into your own JavaScript code. It&#8217;s a simple concept but a little hard to get your head around. Check out <a href="http://www.amazon.com/exec/obidos/ASIN/1449390544/elisabethfree-20">Head First HTML5 Programming</a> where we break it all down for you.</p>
<p><strong>10. XHTML is dead, long live XHTML.</strong></p>
<p>XHTML long ago lost its front-runner status  as the language of the web, with the death of XHTML2 and the rise of HTML5, but  despite rumors that doesn&#8217;t mean you can&#8217;t use XHTML; in fact we call it XHMTL5.</p>
<p>Remember that the difference between HTML and XHTML is that XHTML is proper XML. That means when you write XHTML you use strict XML syntax, and when you serve XHTML you have to use the XML mime type. The benefit of XHTML is that it is extensible (because it is XML) while HTML is not. The downside is that XHTML is strict, doesn&#8217;t play as well with other languages (like CSS and JavaScript) and wasn&#8217;t designed for building web applications.</p>
<p>So, to write XHTML5 today, add a namespace and use proper XML syntax (see the <a href="http://oreillynet.com/pub/e/2099">presentation</a> for an example).</p>
]]></content:encoded>
			<wfw:commentRss>http://wickedlysmart.com/2011/ten-things-every-developer-and-manager-should-know-about-html5/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to make a pie chart with HTML5&#8242;s canvas</title>
		<link>http://wickedlysmart.com/2011/how-to-make-a-pie-chart-with-html5s-canvas/</link>
		<comments>http://wickedlysmart.com/2011/how-to-make-a-pie-chart-with-html5s-canvas/#comments</comments>
		<pubDate>Tue, 06 Dec 2011 17:48:08 +0000</pubDate>
		<dc:creator>Elisabeth</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://wickedlysmart.com/?p=1475</guid>
		<description><![CDATA[One of the best things about the HTML5 &#60;canvas&#62; element is that we can now do things like this: without needing a plug in. I recently had to implement a similar type of graphic in canvas for a project I&#8217;m working on, so I thought I&#8217;d turn it into a tutorial on how to make [...]]]></description>
			<content:encoded><![CDATA[<p>One of the best things about the HTML5 &lt;canvas&gt; element is that we can now do things like this:</p>
<p><a href="http://wickedlysmart.com/wp-content/uploads/2011/12/pieChart.jpg"><img src="http://wickedlysmart.com/wp-content/uploads/2011/12/pieChart-300x300.jpg" alt="Example of a pie chart" title="pie chart" width="300" height="300" class="aligncenter size-medium wp-image-1477" /></a></p>
<p>without needing a plug in. I recently had to implement a similar type of graphic in canvas for a project I&#8217;m working on, so I thought I&#8217;d turn it into a tutorial on how to make a pie chart.</p>
<p><span id="more-1475"></span></p>
<p>Rather than just hardcoding the functions to make a specific pie chart, let&#8217;s write it so you can easily change the data. That way, you can reuse the code any time you need to display a pie chart. So, we&#8217;ll first create an array of data, an array of labels, and an array of colors:</p>
<pre>
var data = [120, 100, 140];
var labels = ["120%", "100%", "140%"];
var colors = ["#FFDAB9", "#E6E6FA", "#E0FFFF"];
</pre>
<p>Data contains numbers that add up to 360 (so we can make a complete circle). Each number corresponds to a segment of the pie chart.  Labels contains strings that will be used to label the segments of the pie chart, and colors contains colors that will be used to color the segments.</p>
<p>Next we can write a function, <code>drawSegment</code> that will draw one segment, specified with the parameter <code>i</code>, using these values:</p>
<pre>
function drawSegment(canvas, context, i) {
    context.save();
    var centerX = Math.floor(canvas.width / 2);
    var centerY = Math.floor(canvas.height / 2);
    radius = Math.floor(canvas.width / 2);

    var startingAngle = degreesToRadians(sumTo(data, i));
    var arcSize = degreesToRadians(data[i]);
    var endingAngle = startingAngle + arcSize;

    context.beginPath();
    context.moveTo(centerX, centerY);
    context.arc(centerX, centerY, radius,
                startingAngle, endingAngle, false);
    context.closePath();

    context.fillStyle = colors[i]:
    context.fill();

    context.restore();

    drawSegmentLabel(canvas, context, i);
}
</pre>
<p>In this code, we first save the context so we can restore it later (that way, it&#8217;s safe to use with other canvas code). Remember, when you save/restore the context, you&#8217;re basically putting the context back into the state it was in you saved it.</p>
<p>Next, we find the center of the canvas, to use as the center of the pie chart, and compute the radius of the circle. </p>
<p>The starting angle is the sum of all the data so far (since each data point corresponds to a segment of the circle), so I wrote a helper function to sum up the first i segments of the array (see below).  For example, if we&#8217;re drawing the third segment, i will be 2, and we&#8217;ll add 120 and 100, for a starting angle of 220. One of the trickiest things about learning canvas is understanding the starting and ending angles and the direction you&#8217;re drawing the arc, so review Chapter 7 in <a href="http://www.amazon.com/exec/obidos/ASIN/1449390544/elisabethfree-20">Head First HTML5 Programming</a> if you get confused about this (I know I do even though I&#8217;d done it lots of times now!).</p>
<p>The ending angle is just the starting angle plus the arcSize, which is just the number in the data array corresponding to the segment we&#8217;re drawing. Note that I&#8217;m converting everything from degrees to radians, using another helper function (see below), since that&#8217;s what the context method to draw the arc expects.</p>
<p>Now we&#8217;re ready to draw the arc. We move the canvas &#8220;pen&#8221; to the starting point, which is the center of the circle, draw the arc, and then close the path, so we get a pie wedge shape. Remember that the last argument to the <code>context.arc</code> method is the direction we&#8217;re drawing the arc; in this case, false means we&#8217;re drawing in a clockwise direction around the circle. The starting angle starts from the east side of the x axis, and goes around clockwise when we use positive angle measurements, so that&#8217;s why we draw the arcs in a clockwise direction.</p>
<p>Finally, we need to fill the arc, so we pick the color from the array, and fill the path we&#8217;ve just drawn. We restore the context, and we&#8217;re done drawing that segment. The last thing we do in the function is call another function, <code>drawSegmentLabel</code>, to draw the label.</p>
<p>Before we get to <code>drawSegmentLabel</code>, here are the helper functions, <code>degreesToRadians</code> and <code>sumTo</code>:</p>
<pre>
function degreesToRadians {
    return (degrees * Math.PI)/180;
}
function sumTo(a, i) {
    var sum = 0;
    for (var j = 0; j < i; j++) {
      sum += a[j];
    }
    return sum;
}
</pre>
<p>The function <code>drawSegmentLabel</code> adds the labels to the pie chart. You might wonder: how are we going to get the text rotated to match the segments? The trick to rotating the text for the labels is to rotate the context - it's like you're picking up the canvas, moving it and rotating it, and drawing the text as as normal. By saving and restoring the context each time the function is called, we make sure that the context goes back to its normal position after each time we call the function.</p>
<pre>
function drawSegmentLabel(canvas, context, i) {
   context.save();
   var x = Math.floor(canvas.width / 2);
   var y = Math.floor(canvas.height / 2);
   var angle = degreesToRadians(sumTo(data, i));

   context.translate(x, y);
   context.rotate(angle);
   var dx = Math.floor(canvas.width * 0.5) - 10;
   var dy = Math.floor(canvas.height * 0.05);

   context.textAlign = "right";
   var fontSize = Math.floor(canvas.height / 25);
   context.font = fontSize + "pt Helvetica";

   context.fillText(labels[i], dx, dy);

   context.restore();
}
</pre>
<p>After saving the context, we figure out the center of the circle, and then the angle to rotate the context so we can draw the text.  The angle is the same as the starting angle we used for the segment in the <code>drawSegment</code> function (ie, the sum of all the data so far, converted to radians).</p>
<p>Once we have the angle, we translate, or move, the top left corner of the context to the center of the circle and then rotate it (clockwise) to the angle that matches the starting angle of the segment. Then we adjust the horizontal starting point of the text so it's at the edge of the pie chart (since the text is right aligned, we're setting the <em>right</em> side of the text box here). I subtracted 10 pixels to get it a bit of space on the right side. We also adjust the vertical position of the text so it has a little space above it, and fits just below the top of each segment.  </p>
<p>Once we've got the position for the text figured out, we set the text alignment and font size. Notice that I'm computing the size of the font based on the size of the canvas (the pie chart is also sized to the canvas). Feel free to play with the number 25 to adjust the font size until you are happy with it (and try changing the canvas size in the HTML to make sure it works at a variety of sizes).</p>
<p>Finally, we fill the text with the label for the segment.</p>
<p>Now all we need is the code to get the canvas and the context and call the <code>drawSegment</code> function to draw all the segments.  This code assumes you've got a canvas with the id of "piechart".</p>
<pre>
canvas = document.getElementById("piechart");
var context = canvas.getContext("2d");
for (var i = 0; i < data.length; i++) {
    drawSegment(canvas, context, i);
}
</pre>
<p>And here's the HTML you need (adjust the canvas size and you should see the pie chart change size too!): </p>
<pre>
&lt;canvas id="piechart" width="400" height="400"&gt;
&lt;/canvas&gt;
</pre>
<p>Enjoy, and let me know if you make any pie charts. I've posted the <a href="https://github.com/bethrobson/HTML5/tree/master/PieChart">full code on github</a>; it's a little different--it's set up to create a PieChart object, and <code>drawSegment</code> and <code>drawSegmentLabel</code> are methods of the PieChart object rather than functions, but it is basically the same idea.</p>
]]></content:encoded>
			<wfw:commentRss>http://wickedlysmart.com/2011/how-to-make-a-pie-chart-with-html5s-canvas/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Head First HTML5, Get Chapter One, FREE</title>
		<link>http://wickedlysmart.com/2011/get-chapter-one-of-head-first-html5-programming/</link>
		<comments>http://wickedlysmart.com/2011/get-chapter-one-of-head-first-html5-programming/#comments</comments>
		<pubDate>Sat, 03 Dec 2011 19:44:27 +0000</pubDate>
		<dc:creator>wickedlysmart</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Featured]]></category>

		<guid isPermaLink="false">http://wickedlysmart.com/?p=1080</guid>
		<description><![CDATA[Head First HTML5 Programming will take your skills to the next level, especially if you&#8217;ve just finished up Head First HTML. Head First HTML5 Programming is your ultimate tour guide to creating web applications with HTML5 and JavaScript, and we give you everything you need to know to build them, including: how to add interactivity [...]]]></description>
			<content:encoded><![CDATA[<p><script type="text/javascript" src="http://forms.aweber.com/form/58/1062808058.js"></script></p>
<p><strong>Head First HTML5 Programming will take your skills to the next level, especially if you&#8217;ve just finished up Head First HTML.</strong></p>
<p><a href="http://www.amazon.com/exec/obidos/ASIN/1449390544/elisabethfree-20">Head First HTML5 Programming</a> is your ultimate tour guide to creating web applications with HTML5 and JavaScript, and we give you everything you need to know to build them, including: how to add interactivity to your pages, how to communicate with the world of Web services, and how to use the great new APIs being developed for HTML5.</p>
<p><strong>Here are just some of the things you’ll learn in Head First HTML5 Programming:</strong></p>
<ul>
<li>Learn how to make your pages truly interactive by using the power of the DOM.</li>
<li>Finally understand how JavaScript works and take yourself from novice to well-informed in just a few chapters.</li>
<li>Learn how JavaScript APIs fit into the HTML5 ecosystem, and how to use any API in your web pages.</li>
<li>Use the Geolocation API to know where your users are.</li>
<li>Bring out your inner artist with Canvas, HTML5’s new 2D drawing surface.</li>
<li>Go beyond just plugging a video into your pages, and create custom video experiences.</li>
<li>Learn the secret to grabbing five megabytes of storage in every user’s browser.</li>
<li>Improve your page’s responsiveness and performance with Web workers.</li>
<li>And much more.</li>
</ul>
<p><strong>We&#8217;d love to get you started now, with a free copy of Chapter 1:</strong><br />
<a href='http://wickedlysmart.com/wp-content/uploads/2011/10/hfhtml5chapter1.pdf' class='small-button smallorange'><span>Download Chapter 1</span></a></p>
]]></content:encoded>
			<wfw:commentRss>http://wickedlysmart.com/2011/get-chapter-one-of-head-first-html5-programming/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Why learn HTML5 for the holidays?</title>
		<link>http://wickedlysmart.com/2011/why-learn-html5-for-the-holidays/</link>
		<comments>http://wickedlysmart.com/2011/why-learn-html5-for-the-holidays/#comments</comments>
		<pubDate>Wed, 30 Nov 2011 23:53:18 +0000</pubDate>
		<dc:creator>Elisabeth</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://wickedlysmart.com/?p=1462</guid>
		<description><![CDATA[There are many good reasons to learn HTML5. One really great one is the &#60;canvas&#62; element. This element gives you the ability to add graphics and animation to your page without any plugins. If you&#8217;re at all interested in HTML5, you&#8217;ve very likely seen some compelling canvas demos. And once you know canvas, you can [...]]]></description>
			<content:encoded><![CDATA[<p>There are many good reasons to learn HTML5. One really great one is the &lt;canvas&gt; element. This element gives you the ability to add graphics and animation to your page without any plugins. If you&#8217;re at all interested in HTML5, you&#8217;ve very likely seen some compelling canvas demos. And once you know canvas, you can make your very own winter scenes for your browser. Then you can impress your whole family and keep the conversation around the holiday dinner table much more interesting. What&#8217;s not to like about that? (And yes, this web app will work on your iPad so you can pass it around easily for demos.)</p>
<p>In this post, I&#8217;ll show you how to create a falling snowflake winter scene using HTML5&#8242;s &lt;canvas&gt; element and the canvas API. This little web app will display a canvas that fills the browser window. When you click on the canvas, a snowflake image is added to the canvas, which then proceeds to fall to the bottom of the window. When it reaches the bottom, it reappears at the top of the window, and continues to fall.</p>
<p>You can learn everything you need to create this program in <a href="http://www.amazon.com/exec/obidos/ASIN/1449390544/elisabethfree-20">Head First HTML5 Programming</a>.</p>
<p><a href="http://wickedlysmart.com/html5/snowflakes/winter.html"><img src="http://wickedlysmart.com/wp-content/uploads/2011/11/winter.jpg" alt="winter scene" title="snowflakes" width="504" height="303" class="aligncenter size-full wp-image-1465" /></a></p>
<p>Click on the image to run the example.</p>
<p>Let&#8217;s start by writing the HTML. We&#8217;ll keep it as simple as possible. All we need is a canvas, and links to the JavaScript and CSS.</p>
<pre>
&lt;!doctype html&gt;
&lt;html&gt;
&lt;head&gt;
  &lt;title&gt;Winter&lt;/title&gt;
  &lt;meta charset="utf-8"&gt;
  &lt;link rel="stylesheet" href="winter.css"&gt;
  &lt;script src="winter.js"&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
  &lt;canvas id="scene"&gt;
  &lt;/canvas&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>Next, the CSS. We want the canvas to take up the entire browser window, so make sure we don&#8217;t have any padding or margins on the body, and set the canvas to display as a block element (by default, on some browsers, it displays as an inline element, which means you get a little extra white space on the edges).</p>
<pre>
html, body {
    width: 100%;
    height: 100%;
    margin: 0px;
    padding: 0px;
}
canvas#scene {
   display: block;
}
</pre>
<p>Now, we&#8217;re ready to write the JavaScript. All the code is inside an anonymous onload function, including the variables and functions we need, like variables for the canvas element object, and the context we get from the canvas. We&#8217;ve also got a variable for the snowflake image we&#8217;re using, and an array to keep track of all the snowflakes.</p>
<pre>
window.onload = function() {

  var canvas = null;
  var context = null;
  var snowflakeImage = null;
  var snowflakes = [];</pre>
<p>Next, initialize the canvas and context variables:</p>
<pre>  canvas = document.getElementById("scene");
  context = canvas.getContext("2d");</pre>
<p>and then the snowflakeImage:</p>
<pre>  var tmpImage = new Image();
  tmpImage.src = "snowflake.png";
  tmpImage.onload = function() {
    snowflakeImage = tmpImage;
  }</pre>
<p>Notice that we only have to load the image once, but we can draw it on the canvas multiple times.</p>
<p>Now, let&#8217;s set up the canvas so whenever you click in the canvas, we create a new snowflake to the canvas. We want the snowflake to appear where you clicked, so we need to get the x and y position of the click in the canvas. We&#8217;ll pass the x, y position to the function addSnowflake(), which we&#8217;ll write shortly.</p>
<pre>  canvas.onclick = function(e) {
    var x = e.clientX;
    var y = e.clientY;
    addSnowflake(x, y);
  };</pre>
<p>We&#8217;re going to use a Flake object to hold all the information associated with a snowflake, including the image, the x and y position, and so on.</p>
<p>Let&#8217;s create the Flake constructor. We&#8217;ll pass in the initial x and y position of the flake (where the user clicked), and the image (by passing in the image, we can easily use Flake for multiple kinds of snowflakes). We&#8217;ll set the width and height to the width and height of the image. Finally, we&#8217;ll add a function to update the y position of the flake so it falls to the bottom of the screen. If it reaches the bottom of the screen, then we can start it over from the top by setting it to a y position of just off the screen at the top of the browser window. You could, of course, create a much more complicated update function to better simulate flakes falling, but we&#8217;re going to keep it simple for now.</p>
<pre>  function Flake(x, y, image) {
    this.x = x;
    this.y = y;
    this.image = image;
    this.width = image.width;
    this.height = image.height;

    this.updateY = function(maxY) {
      this.y += 1;
      if (this.y &gt; maxY) {
        this.y = -(this.width/2);
      }
    }
  }</pre>
<p>Now that we have the Flake constructor, we can write addSnowflake(). All addSnowflake() has to do is create a flake, and add it to the snowflakes array:</p>
<pre>  function addSnowflake(x, y) {
    var flake = new Flake(x, y, snowflakeImage);
    snowflakes.push(flake);
  }</pre>
<p>We&#8217;ve got flakes; now we need to draw them, and make them fall. We&#8217;ll create a drawFlakes() function that will draw all the snowflakes and update them by calling their updateY() methods.</p>
<pre>  function drawFlakes() {
    context.clearRect(0, 0,
                      canvas.width,
                      canvas.height);
    for (var i = 0; i &lt; snowflakes.length; i++) {
      var flake = snowflakes[i];
      context.drawImage(flake.image,
                        flake.x, flake.y,
                        flake.width, flake.height);
      flake.updateY(canvas.height);
    }
  }</pre>
<p>First, we clear the canvas (so we don&#8217;t see the snowflakes in their previous positions), and then loop through all the snowflakes in the snowflakes array. For each flake in the array, we use the context.drawImage() method to draw the snowflake image at its current x, y position. This method also takes the width and height of the image we&#8217;re drawing, so we can just pass in those values, which are also stored in the flake object. Then we just update the position of that flake by calling the flake&#8217;s updateY() method, and continue looping. We&#8217;re passing in the height of the canvas to udpateY to use for computing the max y position of the flake.</p>
<p>So we have drawFlakes(), but how do we start the whole thing going? We can use setInterval and call drawFlakes() every 10 milliseconds so the flakes fall at a reasonable speed. Because we&#8217;re updating the y position only 1 pixel each time, we need to call drawFlakes() fairly often to get a reasonable speed for the falling effect.</p>
<pre>var started = setInterval(drawFlakes, 10);</pre>
<p>Try playing with both the interval speed as well as with the size of the y increment in the Flake updateY() method to see which combinations of values you like the best.</p>
<p>One final thing we need to do is to make sure that if you resize the browser window, the canvas resizes with it so you don&#8217;t have to reload the page. To do this, we&#8217;ll add a resize handler for the window.</p>
<pre>  function resizeWindow() {
    canvas.width = window.innerWidth;
    canvas.height = window.innerHeight;
  }
  window.onresize = resizeWindow;

  resizeWindow();
}</pre>
<p>That&#8217;s it! (Don&#8217;t forget to add that final <code>}</code> to end the window onload function definition). The full listing of the JavaScript code is below (slightly reordered), and you can <a href="http://wickedlysmart.com/html5/snowflakes/winter.html">try it here</a>. And if you&#8217;re new to JavaScript and/or want to learn more about canvas, you can get up to speed with <a href="http://www.amazon.com/exec/obidos/ASIN/1449390544/elisabethfree-20">Head First HTML5 Programming</a>.</p>
<p>If you create any of your own winter wonderland scenes with HTML5 canvas, let me know!</p>
<pre>
window.onload = function() {

  var canvas = null;
  var context = null;
  var snowflakeImage = null;
  var snowflakes = [];

  window.onresize = resizeWindow;

  canvas = document.getElementById("scene");
  context = canvas.getContext("2d");
  resizeWindow();

  var tmpImage = new Image();
  tmpImage.src = "snowflake.png";
  tmpImage.onload = function() {
    snowflakeImage = tmpImage;
  }

  canvas.onclick = function(e) {
    var x = e.clientX;
    var y = e.clientY;
    addSnowflake(x, y);
  };

  var started = setInterval(drawFlakes, 10);

  function addSnowflake(x, y) {
    var flake = new Flake(x, y, snowflakeImage);
    snowflakes.push(flake);
  }

  function Flake(x, y, image) {
    this.width = 110;
    this.height = 110;
    this.x = x;
    this.y = y;
    this.image = image;

    this.updateY = function(maxY) {
      this.y += 1;
      if (this.y &gt; maxY) {
        this.y = -(this.width/2);
      }
    }
  }

  function drawFlakes() {
    context.clearRect(0, 0,
                      canvas.width,
                      canvas.height);
    for (var i = 0; i &lt; snowflakes.length; i++) {
      var flake = snowflakes[i];
      context.drawImage(flake.image,
                        flake.x, flake.y,
                        flake.width, flake.height);
      flake.updateY(canvas.height);
    }
  }

  function resizeWindow() {
    canvas.width = window.innerWidth;
    canvas.height = window.innerHeight;
  }
}
</pre>
<p><!-- Place this tag where you want the +1 button to render --><br />
<g:plusone></g:plusone></p>
<p><!--  Place this tag after the last plusone tag --><br />
<script type="text/javascript">
  (function() {
    var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
    po.src = 'https://apis.google.com/js/plusone.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
  })();
</script></p>
]]></content:encoded>
			<wfw:commentRss>http://wickedlysmart.com/2011/why-learn-html5-for-the-holidays/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Scott Berkun on leadership and teams</title>
		<link>http://wickedlysmart.com/2011/scott-berkun-on-leadership-and-teams/</link>
		<comments>http://wickedlysmart.com/2011/scott-berkun-on-leadership-and-teams/#comments</comments>
		<pubDate>Mon, 28 Nov 2011 06:00:38 +0000</pubDate>
		<dc:creator>Elisabeth</dc:creator>
				<category><![CDATA[Blog]]></category>

		<guid isPermaLink="false">http://wickedlysmart.com/?p=1448</guid>
		<description><![CDATA[I recently had a chance to interview Scott Berkun, who has just self-published a collection of his essays in Mindfire: Big Ideas for Curious Minds. Scott has been a programmer, project manager, team leader (currently at WordPress.com), public speaker, and, of course, author (six books and counting!). He&#8217;s always interesting to talk with about&#8230; well, [...]]]></description>
			<content:encoded><![CDATA[<p>I recently had a chance to interview Scott Berkun, who has just self-published a collection of his essays in <a href="http://www.amazon.com/exec/obidos/ASIN/0983873100/elisabethfree-20">Mindfire: Big Ideas for Curious Minds</a>. Scott has been a programmer, project manager, team leader (currently at WordPress.com), <a href="http://www.youtube.com/watch?v=rRa1IPkBFbg">public speaker</a>, and, of course, author (six books and counting!). He&#8217;s always interesting to talk with about&#8230; well, just about anything; in this interview, we focused on leadership and teams.</p>
<p><strong>Elisabeth Robson: What makes a great team?</strong></p>
<p>Scott Berkun: Trust. Talent without trust makes for a bunch of disappointed talented people, who underperform against teams with less talent, but higher collaboration, based on trust. Trust sounds obvious, but most teams, organizations and families have a shortage of it.</p>
<p><strong>ER: How is leadership different from management?</strong></p>
<p>SB: They&#8217;re hard to separate. An effective leader does some management. An effective manager does some leadership. If you have to divide them, leadership is making good decisions about where to go, management is executing a plan to get you there. </p>
<p><strong>ER: How is technical leadership different from any other kind of leadership?</strong></p>
<p>SB: It&#8217;s more similar than not. A good leader earns trust (there&#8217;s that word again). A good technical leader earns a reputation for making good decisions around how to build technology, or which technologies to use, to solve a  problem. </p>
<p><strong>ER: If a programmer wants to move into a leadership position, what&#8217;s the most important thing you&#8217;d recommend for that person?</strong></p>
<p>SB: That transition depends seeing the value of non-coding tasks. Convincing another developer to approach a problem in a better way may take an hour, but the payoff will be higher than if they had spent that time writing the code themselves.</p>
<p><strong>ER: What motivates programmers to do their best work?</strong></p>
<p>SB: It depends on the programmer. Good leaders ask their teams what motivates them, or what kinds of work they like the most. To stereotype, I&#8217;d say programmers like two things: 1) solving challenging problems 2) seeing those solutions help people.</p>
<p><strong>ER: How do you get programmers to give good estimates for how long a piece of code, or project, will take?</strong></p>
<p>SB: It&#8217;s a habit people have to develop. It starts by documenting estimates before work starts, and reviewing estimates when the work is over. Having healthy discussions about why the estimates weren&#8217;t accurate, and what questions could have been asked to make them more accurate, makes the next round of estimates better. The habit of asking reviewing estimates and asking questions at the end of iterations or projects fuels better estimates.</p>
<p><strong>ER: What new technologies do you have your eye on to keep WordPress on the cutting edge?</strong></p>
<p>SB: I watch people. The cutting edge is always where people are frustrated or annoyed. Listening to people gripe about their apps or their phones reveals what the next big thing will be. Great design comes from when technology is applied to a real problem, rather than technology invented for its own sake.</p>
<p><strong>ER: You recently gave a talk about feedback at Hive2011. What&#8217;s the one  most important thing for programmers to know about giving valuable feedback to their peers?</strong></p>
<p>SB: Don&#8217;t let your ego make you an asshole. Taking pleasure in making someone feel bad about their work serves no one. If you are smart and creative you can find ways to give feedback to people so they want to hear more from you, rather than less.</p>
<p><strong>ER: WordPress is always working on new things; what is the coolest new thing coming from WordPress?</strong></p>
<p>SB: All I can say is never underestimate the power of open source.</p>
<p><strong>ER: You recently self-published a new book, Mindfire. What&#8217;s the most important thing you learned from that process?</strong></p>
<p>SB: This is the greatest time in the history of the world to be a writer. The freedom anyone has to write has never been greater.</p>
<p><strong>ER: What&#8217;s the most innovative idea you&#8217;ve heard of recently?</strong></p>
<p>SB: That there are no innovative ideas, There are only problems to be solved.</p>
<p>Thank you Scott!</p>
<p>Scott Berkun is the author of three bestselling books, <a href="http://www.amazon.com/exec/obidos/ASIN/0596517718/elisabethfree-20">Making Things Happen</a>, <a href="http://www.amazon.com/exec/obidos/ASIN/1449389627/ericsbooks04">The Myths of Innovation</a>, and <a href="http://www.amazon.com/exec/obidos/ASIN/1449301959/elisabethfree-20">Confessions of a Public Speaker</a>. His most recent book is <a href="http://www.amazon.com/exec/obidos/ASIN/0983873100/ericsbooks04">MindFire: Big Ideas for Curious Minds</a>. He managed teams at Microsoft from 1994-2003 on projects including versions 1-5 (not 6) of Internet Explorer. He currently works as a team lead on WordPress.com. He works as a writer and speaker, and his work has appeared in The New York Times, Forbes, The Economist, The Washington Post, Wired, NPR, and other media. He contributes to Harvard Business Review and BusinessWeek and has appeared as an innovation expert on MSNBC and CNBC. He writes frequently on his popular blog, <a href="http://scottberkun.com">scottberkun.com</a>, and tweets at @berkun.</p>
]]></content:encoded>
			<wfw:commentRss>http://wickedlysmart.com/2011/scott-berkun-on-leadership-and-teams/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 1.404 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2012-02-23 09:00:50 -->

