<?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>Robert Accettura&#039;s Fun With Wordage &#187; json</title>
	<atom:link href="http://robert.accettura.com/blog/tag/json/feed/" rel="self" type="application/rss+xml" />
	<link>http://robert.accettura.com</link>
	<description>Robert Accettura&#039;s Personal Blog on Web Development and Tech</description>
	<lastBuildDate>Thu, 09 Feb 2012 01:43:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<atom:link rel='hub' href='http://robert.accettura.com/?pushpress=hub'/>
<cloud domain='robert.accettura.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
		<item>
		<title>DBSlayer + Node.js</title>
		<link>http://robert.accettura.com/blog/2011/05/26/dbslayer-node-js/</link>
		<comments>http://robert.accettura.com/blog/2011/05/26/dbslayer-node-js/#comments</comments>
		<pubDate>Fri, 27 May 2011 01:00:46 +0000</pubDate>
		<dc:creator>Robert</dc:creator>
				<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[dbslayer]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[nodejs]]></category>
		<category><![CDATA[nytimes]]></category>

		<guid isPermaLink="false">http://robert.accettura.com/?p=5658</guid>
		<description><![CDATA[Lately it seems the rage among developers is to take node.js and combine it with something else unusual. So here&#8217;s my contribution. DBSlayer is a project by NYTimes a few years ago that seems to be somewhat forgotten but is &#8230; <a href="http://robert.accettura.com/blog/2011/05/26/dbslayer-node-js/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Lately it seems the rage among developers is to take <a href="http://nodejs.org/">node.js</a> and combine it with something else unusual.  So here&#8217;s my contribution.</p>
<p><a href="http://code.nytimes.com/projects/dbslayer">DBSlayer</a> is a project by NYTimes a few years ago that seems to be somewhat forgotten but is pretty cool.   It&#8217;s another MySQL proxy, but with a slight twist.  Rather than use a binary protocol, or XML, they went with JSON.   It supports things like connection pooling, round-robin distribution to slaves, automatic fallover, and it&#8217;s mutithreaded.  It&#8217;s pretty fast and easy to work with.  It&#8217;s almost like turning a MySQL database into a REST API.  You pass a SQL query as a query argument and it gives you a JSON response.</p>
<p>Once you start it you can do something query using a request like:</p>
<pre>http://localhost:9090/db?%7B%22SQL%22%3A%22SELECT%20*%20FROM%20facts%20WHERE%20id%3D1%3B%22%7D%20</pre>
<p>That will give you a JSON object containing the result of your query.</p>
<p>So doing that in node.js is roughly:</p>
<pre>

var sql = '{&quot;SQL&quot;:&quot;SELECT * FROM facts WHERE id=7;&quot;}';

var http = require('http');
var client = http.createClient(9090, 'localhost');

var request = client.request('GET', '/db?' + escape(sql), {});
request.end();
request.on('response', function (response) {
  console.log('STATUS: ' + response.statusCode);
  console.log('HEADERS: ' + JSON.stringify(response.headers));
  response.setEncoding('utf8');
  response.on('data', function (chunk) {
    console.log('BODY: ' + chunk);
  });
});
</pre>
<p>Running that looks like this:</p>
<pre>
$ node test.js
STATUS: 200
HEADERS: {"date":"Fri, 27 May 2011 02:02:27 GMT","server":"dbslayer/beta-12","content-type":"text/plain; charset=utf-8","content-length":"290","connection":"close"}
BODY: {"RESULT" : {"HEADER" : ["id" , "fact" , "author" , "ip" , "timestamp"] , "ROWS" : [[7 , "1+1=2" , "raccettura" , "127.0.0.1" , 123456]] , "TYPES" : ["MYSQL_TYPE_LONG" , "MYSQL_TYPE_VAR_STRING" , "MYSQL_TYPE_VAR_STRING" , "MYSQL_TYPE_VAR_STRING" , "MYSQL_TYPE_LONGLONG"]} , "SERVER" : "db"}
</pre>
<p>You could obviously clean that up and create a little library to hide the HTTP parts.</p>
<p>It&#8217;s an interesting JS centric way to abstract your database while maintaining SQL level control.  JSON is  becoming the new XML.
<div id="rja_commentCountImage"><a href="http://robert.accettura.com/?p=5658#comments"><img src="http://robert.accettura.com/wp-content/commentCount/2011/05/8c96a3d.gif" alt="Comment Count" style="border:0;" /></a></div>
]]></content:encoded>
			<wfw:commentRss>http://robert.accettura.com/blog/2011/05/26/dbslayer-node-js/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Things You&#8217;ll Love About Firefox 3.5</title>
		<link>http://robert.accettura.com/blog/2009/06/20/things-youll-love-about-firefox-3-5/</link>
		<comments>http://robert.accettura.com/blog/2009/06/20/things-youll-love-about-firefox-3-5/#comments</comments>
		<pubDate>Sat, 20 Jun 2009 23:39:28 +0000</pubDate>
		<dc:creator>Robert</dc:creator>
				<category><![CDATA[Mozilla]]></category>
		<category><![CDATA[awesomebar]]></category>
		<category><![CDATA[firefox 3.5]]></category>
		<category><![CDATA[font-face]]></category>
		<category><![CDATA[geolocation]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[tracemonkey]]></category>
		<category><![CDATA[video]]></category>
		<category><![CDATA[web workers]]></category>
		<category><![CDATA[xmlhttprequest]]></category>

		<guid isPermaLink="false">http://robert.accettura.com/?p=2706</guid>
		<description><![CDATA[For the upcoming Firefox 3.6 release: go here! Firefox 3.5 is around the corner. For those who don&#8217;t pay attention to development here&#8217;s the big features worth checking out. There are lots more, but these are my favorites: User Centric &#8230; <a href="http://robert.accettura.com/blog/2009/06/20/things-youll-love-about-firefox-3-5/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div style="background-color: #FFFFD1; border: 2px solid #FFF100; margin: 10px 0; padding: 5px 11px;">
<strong>For the upcoming Firefox 3.6 release:</strong> <a href="http://robert.accettura.com/blog/2010/01/19/things-youll-love-about-firefox-3-6/">go here</a>!</p>
</div>
<p>Firefox 3.5 is around the corner.  For those who don&#8217;t pay attention to development here&#8217;s the big features worth checking out.  There are lots more, but these are my favorites:</p>
<h3>User Centric Features</h3>
<p><strong>Private Browsing</strong> &#8211; Officially it&#8217;s called &#8220;Private Browsing&#8221; but most know it as &#8220;porn mode&#8221;.  Simply put once you turn on the feature nothing about your browsing is saved to your computer until you turn it off.  No browser history, cookies, cache, no passwords, download list.  Great for shared computers where you may not want the next person to know where you shopped, what you bought etc.</p>
<p><strong>Faster JavaScript</strong> &#8211; Everyone is doing it.  Firefox 3.5 now ships with <a href="https://wiki.mozilla.org/JavaScript:TraceMonkey">TraceMonkey</a>  which uses a technique, called <a href="http://www.ics.uci.edu/%7Efranz/Site/pubs-pdf/ICS-TR-06-16.pdf">trace trees</a> to add just-in-time native code compilation to SpiderMonkey, the JS engine in Firefox.  Bottom line: faster JavaScript makes JavaScript powered sites like Gmail way faster.</p>
<p><strong>Faster Awesomebar</strong> &#8211; The awesomebar is a fast way of browsing the web, but the UI can sometimes get a little sluggish.  Some <a href="http://autonome.wordpress.com/2009/05/05/front-end-performance-in-firefox-35-and-beyond/">awesome work</a> has been done to optimize it for better performance.  Faster UI = better browsing experience.</p>
<p><strong>Better Awesomebar</strong> &#8211; The Awesomebar got a few enhancements including autocomplete for tagging, which is extremely handy as well as editing tags on multiple bookmarks at the same time.  </p>
<p><strong>Undo Closed Window</strong> &#8211; We&#8217;ve all done it before.  Now you can undo a closed window just like a closed tab.</p>
<p><strong>Drag Tab To New Window</strong> &#8211; Previously you could drag/drop to reorder tabs.  Now you can drag a tab off the tab bar to move it into its own window.  This may sound trivial but it actually makes organizing tabs much easier.</p>
<p><strong>Video/Audio</strong> &#8211; Firefox 3.5 supports the new HTML5 <code>&lt;video/&gt;</code> and <code>&lt;audio/&gt;</code> tags.  Specifically it supports Vorbis in Ogg containers, as well as WAV with support for more formats expected in the future.  I&#8217;ve <a href="http://robert.accettura.com/blog/tag/ogg-theora/">discussed open video before</a> and suggest learning more about how important this is there.</p>
<p><strong>SSL Error Pages Suck Less</strong> &#8211; The error pages shown when there is an SSL error were pretty tough on users since they didn&#8217;t display anything helpful.  The new error pages are a bit more helpful.  The bug implementing the changes has tons of details on the <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=431826">changes</a>.</p>
<p><strong>Geolocation</strong> &#8211; Simply put a website can (if you allow it) gather information about your internet connection and using a location service (provided by Google by default) will calculate your location.  No more needing to constantly type in your zip code, or city name to get local information.  For privacy you need to explicitly allow it.  <a href="http://www.mozilla.com/en-US/firefox/geolocation/">Geolocation</a> is in a word awesome.</p>
<p><strong>New Icon</strong> &#8211; Well, it&#8217;s not really new.  It&#8217;s &#8220;refreshed&#8221; I guess.  It&#8217;s not a huge change, but it does look really sharp, especially in more modern operating systems that use larger icons like Mac OS X.  Alex Faaborg has it <a href="http://blog.mozilla.com/faaborg/2009/06/18/the-new-firefox-icon/">on his blog</a> in various sizes for you see.</p>
<h3>Developer Centric Features</h3>
<p><strong>Web Workers</strong> &#8211; My personal favorite is <a href="https://developer.mozilla.org/En/Using_web_workers">web workers</a>.  Essentially its background processing in a separate thread for JavaScript.  No more locking up the browser&#8217;s UI because you need to do some complicated JS calculations. I&#8217;ll leave it to the documentation linked above for examples.  Very handy stuff.</p>
<p><strong>@font-face</strong> &#8211; Designers have long been frustrated with the lack of font options on the web.  They often resort to using images and flash as a way to expand their font options.  With <code>@font-face</code> it&#8217;s now possible to use custom fonts and reference them via css.  There is however the issue of licensing of fonts used on a webpage since the font file itself is accessible via a web browser.</p>
<p><strong>Native JSON</strong> Enough said.  <a href="https://developer.mozilla.org/En/Using_native_JSON">Native JSON</a> is fast.  <code>var obj = JSON.parse(someJS);</code></p>
<p><strong>Cross Site xhr</strong> &#8211; <code>xmlHttpRequest()</code> has ushered in a new era of JavaScript.  It&#8217;s not however without some serious limitations.  One of the most obvious limitations is that you can&#8217;t use it across hostnames.  <a href="https://developer.mozilla.org/En/HTTP_access_control">Until now</a>.</p>
<p>There&#8217;s <a href="https://developer.mozilla.org/en/Firefox_3.5_for_developers">more</a> cool toys, but these are my favorite.</p>
<p>Still not convinced of all the new stuff?  Check out <a href="http://people.mozilla.com/~blizzard/launch/">this demo</a>, then look at the source behind it.  It&#8217;s pretty impressive.
<div id="rja_commentCountImage"><a href="http://robert.accettura.com/?p=2706#comments"><img src="http://robert.accettura.com/wp-content/commentCount/2009/06/2e74c2c.gif" alt="Comment Count" style="border:0;" /></a></div>
]]></content:encoded>
			<wfw:commentRss>http://robert.accettura.com/blog/2009/06/20/things-youll-love-about-firefox-3-5/feed/</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>A Look At Simple Update Protocol (SUP)</title>
		<link>http://robert.accettura.com/blog/2008/08/28/a-look-at-simple-update-protocol-sup/</link>
		<comments>http://robert.accettura.com/blog/2008/08/28/a-look-at-simple-update-protocol-sup/#comments</comments>
		<pubDate>Fri, 29 Aug 2008 02:00:27 +0000</pubDate>
		<dc:creator>Robert</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[atom]]></category>
		<category><![CDATA[friendfeed]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[RSS]]></category>
		<category><![CDATA[simple update protocol]]></category>
		<category><![CDATA[sup]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[xmpp]]></category>

		<guid isPermaLink="false">http://robert.accettura.com/?p=1917</guid>
		<description><![CDATA[The increasingly popular FriendFeed is proposing a new protocol known as Simple Update Protocol (SUP). The problem FriendFeed is encountering is noting new. They monitor a RSS feeds over a variety of services for each user. This can really add &#8230; <a href="http://robert.accettura.com/blog/2008/08/28/a-look-at-simple-update-protocol-sup/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The increasingly popular FriendFeed is proposing a new protocol known as <a href="http://blog.friendfeed.com/2008/08/simple-update-protocol-fetch-updates.html">Simple Update Protocol</a> (SUP).  The problem FriendFeed is encountering is noting new.  They monitor a RSS feeds over a variety of services for each user.  This can really add up.  To keep things timely they poll them frequently.  Generally speaking this is a very wasteful process since the majority of those feeds likely didn&#8217;t change.  That&#8217;s wasted resources.  SUP in a nutshell is a changelog for feeds so that a service like FriendFeed can check only the ones that changed.  This allows for quicker updates with less polling.  Here&#8217;s my analysis of the proposal.</p>
<p><span id="more-1917"></span></p>
<h4>Gripes:</h4>
<ul>
<li>I&#8217;m not sure I agree with the authors decision to use JSON as the format.  Considering this will be used mostly (if not only) to keep tabs on xml documents (RSS, ATOM mostly) it seems more correct to use XML.  Presumably the reason for JSON is that it&#8217;s computationally easier to parse.  The NYTimes created a database abstraction layer called <a href="http://code.nytimes.com/projects/dbslayer">DBSlayer</a> that uses JSON rather than a binary protocol to avoid the need for a client.  The advantage of JSON over xml is <a href="http://open.blogs.nytimes.com/2008/05/08/announcing-the-dbslayer-activerecord-adapter/">JSON is easy to parse</a>, and I agree.  JSON also tends to be lighter since you don&#8217;t have opening and closing tags surrounding all your data.  Still, why introduce JSON to XML world?</li>
<li>SUP needs index files.  Google made a great move with it&#8217;s Sitemaps Protocol by allowing for <a href="https://www.google.com/webmasters/tools/docs/en/protocol.html#sitemapIndexXMLExample">Sitemap Indexes</a>.  Essentially it&#8217;s a bootstrap that lists several index files.  Google further restricted that a Sitemap shall contain no more than 50,000 items and be no larger than 10MB.  For a very popular site such as Facebook the SUP feed could become painful to parse as 1 file.  Having a SUP Index would be much better.  I&#8217;d essentially copy Google&#8217;s design and rules regarding size, I think they work rather well.</li>
<li>SUP should allow for both using SUP-IDs or RSS URL&#8217;s.  SUP could be more useful if it were an index of all RSS feeds in some cases.  Having that option in the protocol would make sense and future proof.  I&#8217;m sure Google wouldn&#8217;t mind it.</li>
</ul>
<h4>Likes:</h4>
<ul>
<li>Unlike using XMPP which can be tough for a startup to implement (look at Twitter).  HTTP is &#8220;native&#8221; and obvious.  It also allows for using things like Gzip encoding to cut down on bandwidth and all other nice things that HTTP allows for.  It&#8217;s also firewall friendly, something that TCP based solutions often aren&#8217;t.  XMPP can also be very resource intensive, a supplemental feed really isn&#8217;t.</li>
<li>Would cut down on unnecessary feed polling.  As noted by FriendFeed they would still need to poll, but the interval would be significantly higher resulting in less requests.</li>
</ul>
<p>It&#8217;s important to note the difference in computational resources &#8220;requests&#8221;, &#8220;bandwidth&#8221;, and &#8220;CPU&#8221;.  It seems a lot of people commenting on the proposal have confused them.  This proposal would reduce requests and bandwidth and CPU provided enough consumers supported SUP. </p>
<p>Every time a consumer reads an RSS feed on a dynamic site (assuming no cache exists), the database is being hit to get the latest items.  Even if a <code>If-Modified-Since</code> header is sent with the request, the site still needs to check if there&#8217;s something newer than that date.  For this reason, using <code>If-Modified-Since</code>, while conserving bandwidth doesn&#8217;t help much to reduce the number of requests or CPU required.  SUP works around this by only hitting one feed, and then only retrieving known updated feeds.  Clearly <code>If-Modified-Since</code> and SUP aren&#8217;t doing the same thing.  They are however somewhat complementary.</p>
<p>To generate this SUP feed, one must essentially do one of two things:</p>
<ul>
<li>On a &#8220;cron&#8221; or some other interval based method query the database for updates and generate a feed.  That includes feeds someone may or may not request (think about all those accounts you created on a website and never again visited).  Sharded databases may also add more complexity.  This can be pretty ugly.</li>
<li>When a change takes place, for example when a user adds a photo on Flickr, update a table in a database containing the SUP-IDs of changed feeds.  Then on interval generate a feed using that one table.  Periodically that table needs to be flushed of records no longer needed.  Generating the feed off of that table is substantially easier.  Of course one can argue if that&#8217;s &#8220;correct&#8221; or not from a data modeling point of view.  It&#8217;s not really normalized, but than again, how many production databases really are, at least when performance matters?</li>
</ul>
<p>This isn&#8217;t exactly a brand new idea.  Six Apart has an Atom based <a href="http://updates.sixapart.com/">update service</a>, Twitter uses <a href="http://blog.twitter.com/2008/07/twitter-and-xmpp-drinking-from-fire.html">XMPP</a> (though it looks like they may phase that out).  LiveJournal at one point had a TCP based system that did essentially the same thing.</p>
<p>Overall SUP isn&#8217;t really a bad way of doing things.  In a sense, it&#8217;s Google Sitemaps for feeds.  It solves a problem that today doesn&#8217;t have a great solution.
<div id="rja_commentCountImage"><a href="http://robert.accettura.com/?p=1917#comments"><img src="http://robert.accettura.com/wp-content/commentCount/2008/08/cb79f8f.gif" alt="Comment Count" style="border:0;" /></a></div>
]]></content:encoded>
			<wfw:commentRss>http://robert.accettura.com/blog/2008/08/28/a-look-at-simple-update-protocol-sup/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Google Releases Protocol Buffers</title>
		<link>http://robert.accettura.com/blog/2008/07/07/google-releases-protocol-buffers/</link>
		<comments>http://robert.accettura.com/blog/2008/07/07/google-releases-protocol-buffers/#comments</comments>
		<pubDate>Tue, 08 Jul 2008 03:11:18 +0000</pubDate>
		<dc:creator>Robert</dc:creator>
				<category><![CDATA[Google]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[dbslayer]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[memcached]]></category>
		<category><![CDATA[nytimes]]></category>
		<category><![CDATA[protocol buffers]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://robert.accettura.com/?p=1817</guid>
		<description><![CDATA[Google today released Protocol Buffers. Protocol Buffers is their &#8220;language-neutral, platform-neutral, extensible mechanism for serializing structured data&#8221;. In general it&#8217;s pretty interesting stuff, and looking over the docs, seems pretty well thought out. I agree XML is bulky and wasteful &#8230; <a href="http://robert.accettura.com/blog/2008/07/07/google-releases-protocol-buffers/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Google today <a href="http://google-code-updates.blogspot.com/2008/07/protocol-buffers-our-serialized.html">released Protocol Buffers</a>.  <a href="http://code.google.com/apis/protocolbuffers/">Protocol Buffers</a> is their &#8220;language-neutral, platform-neutral, extensible mechanism for serializing structured data&#8221;. In general it&#8217;s pretty interesting stuff, and looking over the docs, seems pretty well thought out.</p>
<p>I agree XML is bulky and wasteful for the task.  There&#8217;s a reason why many web developers prefer JSON rather than actual XML when using xmlHttpRequest: XML parsing can be a real performance killer.  JSON in my mind is currently the winner in this department since it&#8217;s light weight, simple, and a can be interpreted by pretty much any language on the planet (may need to install a module, gem, extension, or include a class).  The downside to JSON is that it doesn&#8217;t really allow you to define structure.  JSON also is still not binary format, so you have a performance penalty to parse the string.  The upside is that JSON is rather easy for humans to read (great for debugging).  The NY Times even made a database abstraction layer called <a href="http://code.nytimes.com/projects/dbslayer">DBSlayer</a> that interfaces using JSON.</p>
<p>Serialized PHP has become somewhat popular (Yahoo Developer Network API&#8217;s support it), but it&#8217;s language specific, though interpreters that can read/write it exist for other languages including Perl, Python and Java.  It&#8217;s also somewhat complicated for what it provides.  At a glance it&#8217;s a string of garbage until you break it down.</p>
<p>It looks like Google already has support for Java, Python, and C++.  It&#8217;s only a matter of time before Perl, PHP, and Ruby get support for Protocol Buffers as well.</p>
<p>I could see Protocol Buffers being pretty useful in combination with <a href=" http://www.danga.com/memcached/">Memcached</a>.</p>
<p>It&#8217;s great to see Google open sourcing stuff like this.
<div id="rja_commentCountImage"><a href="http://robert.accettura.com/?p=1817#comments"><img src="http://robert.accettura.com/wp-content/commentCount/2008/07/f4a4da9.gif" alt="Comment Count" style="border:0;" /></a></div>
]]></content:encoded>
			<wfw:commentRss>http://robert.accettura.com/blog/2008/07/07/google-releases-protocol-buffers/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

