<?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>Topper's Blog &#187; Social Web</title>
	<atom:link href="http://blog.toppingdesign.com/category/social-web/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.toppingdesign.com</link>
	<description>Usability, Information Management, Rails, Javascript &#38; (oh no) Web 2.0</description>
	<lastBuildDate>Tue, 24 Jan 2012 19:52:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>New gig</title>
		<link>http://blog.toppingdesign.com/2012/01/24/new-gig/</link>
		<comments>http://blog.toppingdesign.com/2012/01/24/new-gig/#comments</comments>
		<pubDate>Tue, 24 Jan 2012 19:52:28 +0000</pubDate>
		<dc:creator>Topper</dc:creator>
				<category><![CDATA[Social Web]]></category>

		<guid isPermaLink="false">http://blog.toppingdesign.com/?p=269</guid>
		<description><![CDATA[Hey all, As an &#8220;oh yeah&#8230; meant to tell you.&#8221; &#8211; I&#8217;ve been CTO of Amicus since the beginning of the year. It&#8217;s awesome. We&#8217;re helping caused-based organizations kick ass. Twitter: https://twitter.com/#!/AmicusHQ]]></description>
			<content:encoded><![CDATA[<p>Hey all,</p>
<p>As an &#8220;oh yeah&#8230; meant to tell you.&#8221; &#8211; I&#8217;ve been CTO of <a href="http://blog.toppingdesign.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2FtaWN1c2hxLmNvbQ==">Amicus</a> since the beginning of the year. It&#8217;s awesome. We&#8217;re helping caused-based organizations kick ass.</p>
<p>Twitter: <a href="http://blog.toppingdesign.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cHM6Ly90d2l0dGVyLmNvbS8jIS9BbWljdXNIUQ==">https://twitter.com/#!/AmicusHQ</a></p>
 <img src="http://blog.toppingdesign.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=269" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://blog.toppingdesign.com/2012/01/24/new-gig/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My Coding Styles</title>
		<link>http://blog.toppingdesign.com/2012/01/24/my-coding-styles/</link>
		<comments>http://blog.toppingdesign.com/2012/01/24/my-coding-styles/#comments</comments>
		<pubDate>Tue, 24 Jan 2012 16:32:45 +0000</pubDate>
		<dc:creator>Topper</dc:creator>
				<category><![CDATA[Social Web]]></category>

		<guid isPermaLink="false">http://blog.toppingdesign.com/?p=266</guid>
		<description><![CDATA[I&#8217;ve already written about my path-to-pretty coding style. However, I have not written more specifically about how I approach each language in my rails stack. I do realize some of what I&#8217;ll say below is not best-practice. This is my pragmatic approach to how I code, YMMV. I have tended to work at medium scale [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve already written about my <a href="http://blog.toppingdesign.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2Jsb2cudG9wcGluZ2Rlc2lnbi5jb20vMjAxMC8wNi8wMy9wYXRoLXRvLXByZXR0eS8=" title=\"Path to Pretty\">path-to-pretty coding style</a>. However, I have not written more specifically about how I approach each language in my rails stack. I do realize some of what I&#8217;ll say below is not best-practice. This is my pragmatic approach to how I code, YMMV. I have tended to work at medium scale (1-3mm user) sites handling medium traffic (2-300 req/sec) with a small number of employees (6-50). At an order of magnitude larger of any of those statistics I realize you have to tighten up.</p>
<h2>Ruby</h2>
<ul>
<li>2 space tabs (no tabs)</li>
<li>wrap 3rd party APIs whenever you&#8217;re using them a lot</li>
<li>use modules to namespace gems with many classes</li>
<li>try my best to rely on 3rd party code, contribute back when broke</li>
<li>edge cases aren&#8217;t edge cases at scale &#8211; they happen. Think about them.</li>
<li>anything intended for the greater world must be specced to perfection, anything used internally must at the very least have enough specs that I cannot typo anything.</li>
<li>Interaction with 3rd party APIs are hard to spec which is why it&#8217;s better to wrap in your own classes. Initial testing can hit the live API, and then you can move off of doing that.</li>
</ul>
<h2>Rails</h2>
<ul>
<li>always REST, write controllers as if they were an API</li>
<li>controllers shouldn&#8217;t do much</li>
<li>models can get kind of thick. Break out into modules when *too* thick, but play that loose.</li>
<li>classes wrapping models (especially for your REST api) are encouraged and dropped right in the models folder. Model != Db table.</li>
<li>Rails 3.1+ asset management is a gift. Use it. Pass config from backend to front end using erb.</li>
<li>Your models should be very well specced. Your controllers really only need a surface layer. Acceptance tests are awesome to have when you get there.</li>
</ul>
<h2>JavaScript</h2>
<ul>
<li>CoffeeScript is better</li>
<li>jQuery is a gift. Use it.</li>
<li>namespace everything &#8211; global functions do not belong</li>
<li>any custom code you use belongs in your own namespace at Motionbox we used MBX.blah</li>
<li>I tend to believe that changing prototypes is OK, but I recognize the why of &#8220;don&#8217;t&#8221; and so don&#8217;t do it myself. I don&#8217;t avoid libraries just because they change prototypes.</li>
<li>Use an MVC framework (even for little things).</li>
<li>Spec out the MVC models. I rely on the acceptance tests for the V and C code (mostly). Any tests that rely on HTML can be brittle.</li>
</ul>
<h2>CSS/HTML</h2>
<ul>
<li>namespace all your CSS under one global class (you&#8217;ll thank me later)</li>
<li>never use style words in your classes or IDs. HTML is supposed to be what a document IS not what a document looks like. If something is a submit button it&#8217;s a &#8220;submit-button&#8221; not a &#8220;blue-submit-button.&#8221;</li>
<li>Use the minimum amount of HTML to have your app look right. Play with it, don&#8217;t just git &#8216;er done.</li>
<li>HTML should at least look like it&#8217;s functional (forms should point at the right place and be submittable).  However, I&#8217;m not a zealot when it comes to progressive javascript enhancement. My target audience probably has Javascript enabled. Yours may not&#8230; think about your audience.</li>
</ul>
 <img src="http://blog.toppingdesign.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=266" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://blog.toppingdesign.com/2012/01/24/my-coding-styles/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>IE, iframe, P3P, Cookies, oh my</title>
		<link>http://blog.toppingdesign.com/2011/11/18/ie-iframe-p3p-cookies-oh-my/</link>
		<comments>http://blog.toppingdesign.com/2011/11/18/ie-iframe-p3p-cookies-oh-my/#comments</comments>
		<pubDate>Fri, 18 Nov 2011 15:26:22 +0000</pubDate>
		<dc:creator>Topper</dc:creator>
				<category><![CDATA[Social Web]]></category>

		<guid isPermaLink="false">http://blog.toppingdesign.com/?p=260</guid>
		<description><![CDATA[I was just banging my head against the wall trying to figure out why internet explorer wasn&#8217;t remembering my user&#8217;s sessions. Turns out it&#8217;s something that has bitten me in the past. IE doesn&#8217;t allow you to set cookies when your site is in an iframe unless your site has set P3P headers. Also, ordering [...]]]></description>
			<content:encoded><![CDATA[<p>I was just banging my head against the wall trying to figure out why internet explorer wasn&#8217;t remembering my user&#8217;s sessions. Turns out it&#8217;s something that has bitten me in the past.</p>
<p>IE doesn&#8217;t allow you to set cookies when your site is in an iframe unless your site has set P3P headers. Also, ordering matters &#8211; the P3P header must be set *before* the cookie is set. </p>
<p>If you&#8217;re using ruby, this gem works pretty well: <a href="http://blog.toppingdesign.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cHM6Ly9naXRodWIuY29tL2hvb3BsYS9yYWNrLXAzcA==">https://github.com/hoopla/rack-p3p</a></p>
<p>Further reading: <a href="http://blog.toppingdesign.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3N0YWNrb3ZlcmZsb3cuY29tL3F1ZXN0aW9ucy8zODk0NTYvY29va2llLWJsb2NrZWQtbm90LXNhdmVkLWluLWlmcmFtZS1pbi1pbnRlcm5ldC1leHBsb3Jlcg==">http://stackoverflow.com/questions/389456/cookie-blocked-not-saved-in-iframe-in-internet-explorer</a></p>
<p>All the articles I read about setting headers, etags, etc were all really old. Hopefully, if you&#8217;re using rails you found this article.  Just install the gem and add the line from the README to your application.rb &#8211; no monkey patching.  Good luck.</p>
 <img src="http://blog.toppingdesign.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=260" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://blog.toppingdesign.com/2011/11/18/ie-iframe-p3p-cookies-oh-my/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Periods in your rails requests and the &#8220;format&#8221;</title>
		<link>http://blog.toppingdesign.com/2011/10/26/periods-in-your-rails-requests-and-the-format/</link>
		<comments>http://blog.toppingdesign.com/2011/10/26/periods-in-your-rails-requests-and-the-format/#comments</comments>
		<pubDate>Wed, 26 Oct 2011 14:47:04 +0000</pubDate>
		<dc:creator>Topper</dc:creator>
				<category><![CDATA[Social Web]]></category>

		<guid isPermaLink="false">http://blog.toppingdesign.com/?p=257</guid>
		<description><![CDATA[I sometimes hit a bug where a username has a period in it&#8230; so if you have a path such as: /users/my.username/files/file.ext Rails will parse that first period as the beginning of the format param&#8230; so you lose the files route, etc. It does let you use %2E though which will be unescaped to the [...]]]></description>
			<content:encoded><![CDATA[<p>I sometimes hit a bug where a username has a period in it&#8230; so if you have a path such as:</p>
<p>/users/my.username/files/file.ext</p>
<p>Rails will parse that first period as the beginning of the format param&#8230; so you lose the files route, etc.</p>
<p>It does let you use %2E though which will be unescaped to the period in your params&#8230; so</p>
<p>/users/my%2Eusername/files/file.ext</p>
<p>will give you the correct user_id param of &#8220;my.username&#8221; and continue on its routed merry way.</p>
<p>Just a simple reminder. Probably more for me than you <img src='http://blog.toppingdesign.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
 <img src="http://blog.toppingdesign.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=257" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://blog.toppingdesign.com/2011/10/26/periods-in-your-rails-requests-and-the-format/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A moment of silence</title>
		<link>http://blog.toppingdesign.com/2011/10/06/a-moment-of-silence/</link>
		<comments>http://blog.toppingdesign.com/2011/10/06/a-moment-of-silence/#comments</comments>
		<pubDate>Thu, 06 Oct 2011 13:35:52 +0000</pubDate>
		<dc:creator>Topper</dc:creator>
				<category><![CDATA[Social Web]]></category>

		<guid isPermaLink="false">http://blog.toppingdesign.com/?p=253</guid>
		<description><![CDATA[I would be remiss if I didn&#8217;t mark this day (well, yesterday). RIP Steve Jobs. I&#8217;ve been trying to think of any person or company that has changed my world more than Apple. Their products encouraged me on my path to my current career. Their personal computer interfaces have permeated the entire market. The idea [...]]]></description>
			<content:encoded><![CDATA[<p>I would be remiss if I didn&#8217;t mark this day (well, yesterday). RIP Steve Jobs. I&#8217;ve been trying to think of any person or company that has changed my world more than Apple. Their products encouraged me on my path to my current career. Their personal computer interfaces have permeated the entire market. The idea that a computer should be simple and available has shaped the planet. Their phone put the internet in my pocket, changing my world again.</p>
<p><a href="http://blog.toppingdesign.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy55b3V0dWJlLmNvbS93YXRjaD92PUQxUi1qS0twM05B">His 2005 Stanford commencement speech [VIDEO]</a> was powerful at the time, but now carries even more weight. &#8220;Stay Young. Stay Foolish.&#8221;  At 56, I guess he will always remain young, but he was certainly not foolish.</p>
<p>Steve Jobs set an example that almost none of us will attain, but in striving we hope to make the world just a little bit better.</p>
 <img src="http://blog.toppingdesign.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=253" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://blog.toppingdesign.com/2011/10/06/a-moment-of-silence/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Here, Here&#8230; how to save WebOS</title>
		<link>http://blog.toppingdesign.com/2011/08/25/here-here-how-to-save-webos/</link>
		<comments>http://blog.toppingdesign.com/2011/08/25/here-here-how-to-save-webos/#comments</comments>
		<pubDate>Thu, 25 Aug 2011 14:11:40 +0000</pubDate>
		<dc:creator>Topper</dc:creator>
				<category><![CDATA[Social Web]]></category>

		<guid isPermaLink="false">http://blog.toppingdesign.com/?p=251</guid>
		<description><![CDATA[I find it tricky to write about a company I work for (HP). So I&#8217;ll just link to this: http://www.quirksmode.org/blog/archives/2011/08/twelve_steps_fo.html Exactly. I&#8217;ll go one step further and say &#8220;be the cloud OS that no one else is.&#8221; Embrace the web. It could save you. I&#8217;d like to do a longer discussion on this, but I [...]]]></description>
			<content:encoded><![CDATA[<p>I find it tricky to write about a company I work for (HP).  So I&#8217;ll just link to this:</p>
<p><a href="http://blog.toppingdesign.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5xdWlya3Ntb2RlLm9yZy9ibG9nL2FyY2hpdmVzLzIwMTEvMDgvdHdlbHZlX3N0ZXBzX2ZvLmh0bWw=">http://www.quirksmode.org/blog/archives/2011/08/twelve_steps_fo.html</a></p>
<p>Exactly. I&#8217;ll go one step further and say &#8220;be the cloud OS that no one else is.&#8221;  Embrace the web. It could save you. I&#8217;d like to do a longer discussion on this, but I have to watch my words (probably, no one has told me this).</p>
 <img src="http://blog.toppingdesign.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=251" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://blog.toppingdesign.com/2011/08/25/here-here-how-to-save-webos/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The process of software creation</title>
		<link>http://blog.toppingdesign.com/2011/08/22/the-process-of-software-creation/</link>
		<comments>http://blog.toppingdesign.com/2011/08/22/the-process-of-software-creation/#comments</comments>
		<pubDate>Mon, 22 Aug 2011 16:22:41 +0000</pubDate>
		<dc:creator>Topper</dc:creator>
				<category><![CDATA[Social Web]]></category>

		<guid isPermaLink="false">http://blog.toppingdesign.com/?p=248</guid>
		<description><![CDATA[http://www.leanessays.com/2011/08/dont-separate-design-from.html Wow. This woman describes succinctly what I&#8217;ve been trying to describe for a few years now. At the ol&#8217; Motionbox (pre Snapfish acquisition) this is exactly what we were doing. We went from the horrible waterfall, to a version of Agile (not formal) and settled on something remarkably like what Mary writes. It worked [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.toppingdesign.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5sZWFuZXNzYXlzLmNvbS8yMDExLzA4L2RvbnQtc2VwYXJhdGUtZGVzaWduLWZyb20uaHRtbA==">http://www.leanessays.com/2011/08/dont-separate-design-from.html</a></p>
<p>Wow. This woman describes succinctly what I&#8217;ve been trying to describe for a few years now. At the ol&#8217; Motionbox (pre <a href="http://blog.toppingdesign.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3NuYXBmaXNoLmNvbQ==">Snapfish</a> acquisition) this is exactly what we were doing. We went from the horrible waterfall, to a version of Agile (not formal) and settled on something remarkably like what Mary writes.</p>
<p>It worked fantastically. It keeps everybody invested and focused on the end result rather than the details. It also keeps your team working together and doesn&#8217;t allow for excuses like &#8220;that wasn&#8217;t on the list.&#8221;</p>
<p>It, however, does require everyone on your team to be a good-to-great communicator and to be very good at their jobs (weak links stick out like sore thumbs). However, if that&#8217;s not what you&#8217;re striving for anyway&#8230; you&#8217;re probably doing it wrong.</p>
<p>Hardcore agile guys&#8230; what&#8217;s your take?</p>
 <img src="http://blog.toppingdesign.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=248" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://blog.toppingdesign.com/2011/08/22/the-process-of-software-creation/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Path to Pretty</title>
		<link>http://blog.toppingdesign.com/2010/06/03/path-to-pretty/</link>
		<comments>http://blog.toppingdesign.com/2010/06/03/path-to-pretty/#comments</comments>
		<pubDate>Thu, 03 Jun 2010 14:11:11 +0000</pubDate>
		<dc:creator>Topper</dc:creator>
				<category><![CDATA[Social Web]]></category>

		<guid isPermaLink="false">http://blog.toppingdesign.com/?p=206</guid>
		<description><![CDATA[I&#8217;ve been thinking a lot about my pragmatic approach to programming (sorry to steal from very great books). I&#8217;ve never been the zealot that makes sure all code is perfect before shipping. I also recognize the tremendous value that aesthetic code brings (that&#8217;s why I&#8217;m a ruby guy). However, the important part of writing code [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been thinking a lot about my pragmatic approach to programming (sorry to steal from very great books).</p>
<p>I&#8217;ve never been the zealot that makes sure all code is perfect before shipping. I also recognize the tremendous value that aesthetic code brings (that&#8217;s why I&#8217;m a ruby guy). However, the important part of writing code is <em>getting it out to the users</em>. Those users might be your fellow coworkers (if you&#8217;re doing something back-endy) or they might be consumers.</p>
<p><strong>My code will not matter unless someone is using it. So I get it out quickly.</strong></p>
<p>That being said, I&#8217;ve seen us cut corners too many times and it <strong>always</strong> comes back to haunt. It costs hours and hours cost dollars. Bad code is not good for anybody.</p>
<p><strong>My users will suffer from bad code because I won&#8217;t be able to react to their needs in a timely manner.</strong></p>
<p>I think I have been intuitively following a pattern now for a while that seems to work out.  I&#8217;ve been calling it &#8220;Path to Pretty&#8221; in my head.</p>
<p><strong>It&#8217;s ok to ship code that I would consider lacking if the intent and next steps for improvement are clear.</strong></p>
<p>By clear I mean that I must be able to go back in 2 months, look at the code and intuitively see what I was trying to do.  If it&#8217;s not fully optimized or there are 20 extra lines, so be it.</p>
<p><strong>As long as there is a clear path to pretty I now consider my code shippable.</strong></p>
<p><em>Footnote: I&#8217;m sure I&#8217;m not the first person to do this and there&#8217;s probably some other name for this technique. This article was mostly for my own selfish benefit.<br />
</em></p>
 <img src="http://blog.toppingdesign.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=206" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://blog.toppingdesign.com/2010/06/03/path-to-pretty/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Zookeeper &#8211; Distributed cluster software</title>
		<link>http://blog.toppingdesign.com/2010/05/27/zookeeper-distributed-cluster-software/</link>
		<comments>http://blog.toppingdesign.com/2010/05/27/zookeeper-distributed-cluster-software/#comments</comments>
		<pubDate>Thu, 27 May 2010 15:47:00 +0000</pubDate>
		<dc:creator>Topper</dc:creator>
				<category><![CDATA[Social Web]]></category>

		<guid isPermaLink="false">http://blog.toppingdesign.com/?p=195</guid>
		<description><![CDATA[I read this article about Apache Zookeeper at Igvita and was intrigued. I started looking around for ruby libraries, but nothing was as mature as I would like. I forked a branch on github and chugged along on getting the jruby and c versions to work with the same api. Zookeeper exposes a super simple [...]]]></description>
			<content:encoded><![CDATA[<p>I read <a href="http://blog.toppingdesign.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5pZ3ZpdGEuY29tLzIwMTAvMDQvMzAvZGlzdHJpYnV0ZWQtY29vcmRpbmF0aW9uLXdpdGgtem9va2VlcGVyLw==">this article about Apache Zookeeper at Igvita</a> and was intrigued.</p>
<p>I started looking around for ruby libraries, but nothing was as mature as I would like.  I <a href="http://blog.toppingdesign.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2dpdGh1Yi5jb20vdG9ib3dlcnMvem9va2VlcGVy">forked a branch on github</a> and chugged along on getting the jruby and c versions to work with the same api.</p>
<p>Zookeeper exposes a super simple API, but with that simple stuff you can build a lot of complex cluster logic.</p>
<div class="igBar"><span id="lruby-4"><a href="http://blog.toppingdesign.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=Iw==" onclick=\"javascript:showPlainTxt('ruby-4'); return false;\">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">RUBY:</span>
<div id="ruby-4">
<div class="ruby">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">zk = ZooKeeper.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">"localhost:2181"</span>, :watcher =&gt; :default<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#008000; font-style:italic;">#this will handle events using my built-in event handler</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">zk2 = ZooKeeper.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">"localhost:2181"</span>, :watcher =&gt; <span style="color:#0000FF; font-weight:bold;">false</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#008000; font-style:italic;">#this one won't receive watch events</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">zk.<span style="color:#9900CC;">watcher</span>.<span style="color:#9900CC;">register</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">"/mypath"</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> |event, zookeeper_client|</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; $stderr.<span style="color:#CC0066; font-weight:bold;">puts</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">"got an event on: #{event.path}"</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">end</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">zk.<span style="color:#9900CC;">exists</span>?<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">"/mypath"</span>, :watch =&gt; <span style="color:#0000FF; font-weight:bold;">true</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#008000; font-style:italic;"># returns nil, but sets up the app to watch for the existence of /mypath</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">zk2.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">"/mypath"</span>, <span style="color:#996600;">"my data up to 1mb"</span>, :mode =&gt; :ephemeral<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000; font-style:italic;"># create modes can be any of</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000; font-style:italic;"># :persistent_sequential, :ephemeral_sequential, :persistent, :ephemeral</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000; font-style:italic;"># now the registered watcher will fire (at least within a few 100 miliseconds)</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000; font-style:italic;"># because we set that node to be :ephemeral - when zk2 closes its connection, the &quot;/mypath&quot; will go away</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000; font-style:italic;"># but watches are one-time firing only - so we need to set it up again</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">zk.<span style="color:#9900CC;">exists</span>?<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">"/mypath"</span>, :watch =&gt; <span style="color:#0000FF; font-weight:bold;">true</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#008000; font-style:italic;">#returns true</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">zk2.<span style="color:#9900CC;">close</span>! <span style="color:#008000; font-style:italic;">#or delete or whatever</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000; font-style:italic;"># the watcher fires again and</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">zk.<span style="color:#9900CC;">exists</span>?<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">"/mypath"</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#008000; font-style:italic;">#returns false </span></div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>A limited api of create, delete, get, set, watch lets you do some really advanced things around a cluster.</p>
<h3>Examples</h3>
<p>I added some abstractions based on the <a href="http://blog.toppingdesign.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2hhZG9vcC5hcGFjaGUub3JnL3pvb2tlZXBlci9kb2NzL3IzLjAuMC9yZWNpcGVzLmh0bWw=">Zookeeper recipes</a>.</p>
<h3>Locks</h3>
<div class="igBar"><span id="lruby-5"><a href="http://blog.toppingdesign.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=Iw==" onclick=\"javascript:showPlainTxt('ruby-5'); return false;\">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">RUBY:</span>
<div id="ruby-5">
<div class="ruby">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000; font-style:italic;">#these 2 clients could be on totally separate boxes, different processes, whatever</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">zk = ZooKeeper.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">"localhost:2181"</span>, :watcher =&gt; :default<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">zk2 = ZooKeeper.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">"localhost:2181"</span>, :watcher =&gt; :default<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">lock1 = zk.<span style="color:#9900CC;">locker</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">"/mypath"</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">lock1.<span style="color:#9900CC;">lock</span> <span style="color:#008000; font-style:italic;">#true</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">lock2 = zk2.<span style="color:#9900CC;">locker</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">"/mypath"</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">lock2.<span style="color:#9900CC;">lock</span> <span style="color:#008000; font-style:italic;">#false</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">lock1.<span style="color:#9900CC;">unlock</span> <span style="color:#008000; font-style:italic;">#true</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">lock2.<span style="color:#9900CC;">lock</span> <span style="color:#008000; font-style:italic;">#true</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000; font-style:italic;"># locks are also released on a client close/crash</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">lock1.<span style="color:#9900CC;">lock</span> <span style="color:#008000; font-style:italic;">#false</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">zk2.<span style="color:#9900CC;">close</span>!</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">lock1.<span style="color:#9900CC;">lock</span> <span style="color:#008000; font-style:italic;">#true </span></div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<h3>Message Queues</h3>
<p>I also implemented a simple message queue on top of zookeeper.  However, because of the way the zookeeper "children" calls are made (returning all children), I wouldn't recommend using this for queues where pending messages will reach into the thousands.</p>
<div class="igBar"><span id="lruby-6"><a href="http://blog.toppingdesign.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=Iw==" onclick=\"javascript:showPlainTxt('ruby-6'); return false;\">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">RUBY:</span>
<div id="ruby-6">
<div class="ruby">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">client1 = ZooKeeper.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">"localhost:2181"</span>, :watcher =&gt; :default<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; client2 = ZooKeeper.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">"localhost:2181"</span>, :watcher =&gt; :default<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; publisher = client1.<span style="color:#9900CC;">queue</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">"myqueue"</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; receiver = client2.<span style="color:#9900CC;">queue</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">"myqueue"</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; receiver.<span style="color:#9900CC;">subscribe</span> <span style="color:#9966CC; font-weight:bold;">do</span> |title, data|</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># data will be whatever was published, title will be the node name</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># for the message</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; $stderr.<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">"got a message with: #{data}"</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># having a true state from the block will mark the message as 'answered'</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># sending back a false will requeue</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF; font-weight:bold;">true</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<h3>More...</h3>
<p>There's a ton you can do with this thing (priority queues, meta data store, etc).  I think it's a nice addition to the ruby toolset.</p>
 <img src="http://blog.toppingdesign.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=195" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://blog.toppingdesign.com/2010/05/27/zookeeper-distributed-cluster-software/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>WebSockets</title>
		<link>http://blog.toppingdesign.com/2010/05/05/websockets/</link>
		<comments>http://blog.toppingdesign.com/2010/05/05/websockets/#comments</comments>
		<pubDate>Wed, 05 May 2010 17:24:01 +0000</pubDate>
		<dc:creator>Topper</dc:creator>
				<category><![CDATA[Social Web]]></category>

		<guid isPermaLink="false">http://blog.toppingdesign.com/?p=187</guid>
		<description><![CDATA[I've been thinking a lot lately that websockets are going to fundamentally change the architecture of the web. It lets you think about backend architecture in a whole new light. Projects like Nanite, EventMachine, Mongo, Redis... I think these are the future. I even question the utility of rails in a client-side-app-always-connected world. I'm just [...]]]></description>
			<content:encoded><![CDATA[<p>I've been thinking a lot lately that websockets are going to fundamentally change the architecture of the web. It lets you think about backend architecture in a whole new light.  Projects like Nanite, EventMachine, Mongo, Redis... I think these are the future. I even question the utility of rails in a client-side-app-always-connected world.</p>
<p>I'm just pondering now... trying to flesh out what I think is going to happen and how we can embrace it sooner.</p>
<p>TO COME:<br />
Events: Modern JavaScript architecture is actually pretty powerful, how can we take the "bolted on functionality" approach to servers.<br />
Messages: They're kinda like events right?<br />
Request/Response Cycle: it's probably dead?</p>
 <img src="http://blog.toppingdesign.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=187" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://blog.toppingdesign.com/2010/05/05/websockets/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

