﻿<?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>Just A Programmer &#187; javascript</title>
	<atom:link href="http://www.justaprogrammer.net/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.justaprogrammer.net</link>
	<description>We're Just Programmers...</description>
	<lastBuildDate>Tue, 10 Jan 2012 03:59:18 +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>A BSON ObjectId implementation in Javascript</title>
		<link>http://www.justaprogrammer.net/2011/03/26/a-bson-objectid-implementation-in-javascript/</link>
		<comments>http://www.justaprogrammer.net/2011/03/26/a-bson-objectid-implementation-in-javascript/#comments</comments>
		<pubDate>Sat, 26 Mar 2011 23:10:40 +0000</pubDate>
		<dc:creator>Justin</dc:creator>
				<category><![CDATA[Just A Programmer]]></category>
		<category><![CDATA[BSON]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[mongodb]]></category>

		<guid isPermaLink="false">http://www.justaprogrammer.net/?p=503</guid>
		<description><![CDATA[Recently I spent a few days implementing the BSON ObjectId data type used by MongoDB in javascript so I could generate ObjectIds in a a web browser. I originally had a specific problem to solve. However, I ended reworking my approach in that instance so I did not have to generate ObjectIds in the browser. [...]]]></description>
			<content:encoded><![CDATA[
<div class="topsy_widget_data topsy_theme_blue" style="float: right;margin-left: 0.75em; background: url(data:,%7B%20%22url%22%3A%20%22http%253A%252F%252Fwww.justaprogrammer.net%252F2011%252F03%252F26%252Fa-bson-objectid-implementation-in-javascript%252F%22%2C%20%22shorturl%22%3A%20%22http%3A%2F%2Fbit.ly%2FeggJkf%22%2C%20%22style%22%3A%20%22big%22%2C%20%22title%22%3A%20%22A%20BSON%20ObjectId%20implementation%20in%20Javascript%22%20%7D);"></div>
<p>Recently I spent a few days implementing the <a href="http://www.mongodb.org/display/DOCS/Object+IDs">BSON ObjectId</a> data type used by <a href="http://www.mongodb.org">MongoDB </a>in javascript so I could generate ObjectIds in a a web browser. I originally had a specific problem to solve. However, I ended reworking my approach in that instance so I did not have to generate ObjectIds in the browser. Despite this, the code is still a valid approach to solving my original problem. The code is available on the <a href="https://github.com/justaprogrammer">justaprogrammer github org</a>, The project is called <a href="https://github.com/justaprogrammer/ObjectId.js">ObjectId.js</a>. Although the git repository contains a sample html file to illustrate its usage, all you need is the <a href="https://github.com/justaprogrammer/ObjectId.js/blob/master/Objectid.js">javascript file</a>, and if you want to support IE6, <a href="https://github.com/douglascrockford/JSON-js/blob/master/json2.js">json2.js</a>.</p>
<h2>How It Works</h2>
<p>Originally, I wanted an implementation of ObjectId that could interact with the format that the WCF <a href="http://msdn.microsoft.com/en-us/library/system.runtime.serialization.json.datacontractjsonserializer.aspx">DataContractJsonSerializer</a> serialized objects of the type MongoDB.Bson.ObjectId in the official 10gen <a href="https://github.com/mongodb/mongo-csharp-driver">MongoDB C# driver</a>. This format looked like this:</p>
<pre lang="javascript">{
    "timestamp":1298346771,
    "machine":8775338,
    "pid":20092,
    "increment":0
}</pre>
<p>Now, it was trivial a JSON object that looked like this. The real issue was filling those 4 values in a sensible manner. I ended up settling on the following:</p>
<ul>
<li><strong>timestamp</strong>: This is supposed to be seconds since the unix epoch. Javascript represents time as milliseconds since the UNIX epoch. Therefore all I had to do was set this to Math.floor(new Date().valueOf() / 1000)</li>
<li><strong>machine:</strong> This is normally the first three bytes of the md5 hash of the hostname. Since I can&#8217;t access that from the browser I store a random number in html5 local storage and a cookie for fallback. This makes the machine id probably consistent for a given combination of machine, logon and browser. Naturally, I could use something like <a href="https://github.com/douglascrockford/JSON-js/blob/master/json2.js">evercookie</a> to make the machine part of the object id more sticky. However, I felt this was &#8220;good enough&#8221;</li>
<li><strong>pid:</strong> Pid is generated every time ObjectId.js is executed, so usually once per page. This means that pid changes each page load, but remains consistent across Ajax calls on a single page reload.</li>
<li><strong>increment:</strong> This was simple. pid++ every time I generate a new ObjectId.</li>
</ul>
<p>So if you need to generate ObjectId&#8217;s in javascript, check out this class. If you find a bug or have an improvement, fork and send a pull request. Happy coding!.</p>

]]></content:encoded>
			<wfw:commentRss>http://www.justaprogrammer.net/2011/03/26/a-bson-objectid-implementation-in-javascript/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Adventures with SVG (a lessons learned post)</title>
		<link>http://www.justaprogrammer.net/2010/04/04/adventures-with-svg/</link>
		<comments>http://www.justaprogrammer.net/2010/04/04/adventures-with-svg/#comments</comments>
		<pubDate>Sun, 04 Apr 2010 05:29:22 +0000</pubDate>
		<dc:creator>Justin</dc:creator>
				<category><![CDATA[Just A Programmer]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[lessons learned]]></category>
		<category><![CDATA[SVG]]></category>

		<guid isPermaLink="false">http://www.justaprogrammer.net/?p=122</guid>
		<description><![CDATA[Go into the open dessert. Draw a circle around you. All that is inside the circle represents your knowledge. All that is outside the circle represents that which you do not know. The line represents that which you know you do not know. What happens as you make the circle bigger? &#8211; Unknown I don&#8217;t [...]]]></description>
			<content:encoded><![CDATA[
<div class="topsy_widget_data topsy_theme_blue" style="float: right;margin-left: 0.75em; background: url(data:,%7B%20%22url%22%3A%20%22http%253A%252F%252Fwww.justaprogrammer.net%252F2010%252F04%252F04%252Fadventures-with-svg%252F%22%2C%20%22style%22%3A%20%22big%22%2C%20%22title%22%3A%20%22Adventures%20with%20SVG%20%28a%20lessons%20learned%20post%29%22%20%7D);"></div>
<blockquote><p>Go into the open dessert. Draw a circle around you. All that is inside the circle represents your knowledge. All that is outside the circle represents that which you do not know. The line represents that which you know you do not know. What happens as you make the circle bigger?<br />
&#8211; Unknown</p></blockquote>
<p>I don&#8217;t remember where I first read a version of the above story. However, it rings true for my recent experiences. You see I wrote <a href="http://github.com/zippy1981/collapsiblePanel/tree/svg">a simple jQuery plugin</a>, and decided to use inkscape to generate the graphics used by it. I then discovered it was possible to animate the SVG files with javascript. Before I knew it I found myself wandering through a dessert awaiting the promised land of SVG. I&#8217;ve yet to reach the promised land, but I&#8217;ve learned a lot in the experience.</p>
<h3>Lesson Zero: SVG is poorly documented on the web.</h3>
<p>I need to qualify the section header a bit. The <a href="http://www.w3.org/TR/SVG11/">actual standard</a> is pretty well defined. There are examples on the web, and <a href="http://www.w3schools.com/">w3schools</a> has <a href="http://www.w3schools.com/svg/default.asp">a section on SVG</a>. However, SVG is not popular enough for you to be able to steal all your code from google. You will have to experiment to do a lot of simple tasks.</p>
<h3>Lesson One: SVG has very html like DOM.</h3>
<p>This one was a pleasant surprise actually. SVG elements have event attributes like onload and onclick. Animating is as simple as recursively calling a function via <a href="https://developer.mozilla.org/en/DOM/window.setTimeout">window.setTimeout()</a>. You could call console.log() to trace your javascript&#8217;s execution via firebug or the chrome developer console. In general I was able to leverage a lot of the javascript experience I&#8217;ve had with html.</p>
<h3>Lesson Two: I should be animating with SMIL instead of javascript.</h3>
<p>I&#8217;ll call this a lesson I&#8217;ve not really learned. If I truely learned my lesson I would have learned <a href="http://www.w3.org/AudioVideo/">SMIL</a> and done my animations with it instead of javascript. However, I was more concerned in exploring what could be done by combining javascript and SVG than animating SVGs.</p>
<h3>Lesson Three: SVG is inconsistently implemented in practice.</h3>
<p>I&#8217;m not just talking about amongsT the browsers, but that too is a problem.</p>
<p>First of all, you need to use one of several plugins to render SVGs in Internet Explorer. IE9 will finally rectify that. The no longer maintained Adobe SVG plugin was the most popular IE plugin. However, the still alpha flash and javascript based <a href="http://code.google.com/p/svgweb/">svgweb</a> by google is gaining popularity. That one has the advantage of not requiring any special software besides flash, which is probably already installed. However, it seems it does not support javascript embedded in the svg file.</p>
<p>Second, SVG support is inconsistent amongst opera, firefox, and chrome. Chrome has a nasty habit of not rendering svg embedded in html via an &lt;object/&gt; tag if the mime type is not properly set. I discovered this while serving html and svg through <a href="http://blogs.msdn.com/dmitryr/archive/2008/10/03/cassini-for-framework-3-5.aspx">Cassini</a>.</p>
<blockquote><p>(As an aside, I have made available a <a href="http://github.com/zippy1981/Cassini">modified version</a> of Cassini on <a href="http://www.github.com">github</a> so no one will have to suffer as I have.)</p></blockquote>
<p>Third, <a href="http://www.inkscape.org">inkscape</a>, the editor I use to draw my SVGs, is not a complete SVG editor, and it implents several extensions to the SVG standard. The extended elements have not prevented SVGs I drew in Inkscape from being rendered in browsers since they have different XML namespaces. While I&#8217;ve discovered how to reference external javascript files in a svg through inkscape, I have to use a separate text editor on the SVG files to embed javascript in the document.</p>
<h3>Conclusions</h3>
<p>My first conclusion is SVG is not quite ready for prime time as a deploy directly to the web technology. However, there is enough buzz happening that early adopting might be prudent for some scenarios. Browser support is improving, and the tools are improving.</p>
<p>My second conclusion is that SVG is ready as a &#8220;mastering format,&#8221; like PSD, XCF (gimp native) or Illustrator. If you want to draw with a rector tool, and then render to a bitmap, SVG is a solid format. Inkscape is a good editor.</p>
<p>My third and final conclusion, is that the desert of SVG is very big, and my circle in the sand is quite small.</p>

]]></content:encoded>
			<wfw:commentRss>http://www.justaprogrammer.net/2010/04/04/adventures-with-svg/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Printf() for jquery.</title>
		<link>http://www.justaprogrammer.net/2010/01/16/sprintf-for-jquery/</link>
		<comments>http://www.justaprogrammer.net/2010/01/16/sprintf-for-jquery/#comments</comments>
		<pubDate>Sun, 17 Jan 2010 03:26:08 +0000</pubDate>
		<dc:creator>Justin</dc:creator>
				<category><![CDATA[Just A Programmer]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.justaprogrammer.net/?p=60</guid>
		<description><![CDATA[I was preparing for my pre-session talk this past November at LISUG, when I determined that I needed a printf() function for jquery. To be more accurate, more accurately I needed an sprintf() implementation in javascript, and wanted to . Google lead me to a jquery plugin that has not been updated since 2007. However, [...]]]></description>
			<content:encoded><![CDATA[
<div class="topsy_widget_data topsy_theme_blue" style="float: right;margin-left: 0.75em; background: url(data:,%7B%20%22url%22%3A%20%22http%253A%252F%252Fwww.justaprogrammer.net%252F2010%252F01%252F16%252Fsprintf-for-jquery%252F%22%2C%20%22style%22%3A%20%22big%22%2C%20%22title%22%3A%20%22Printf%28%29%20for%20jquery.%22%20%7D);"></div>
<p>I was preparing for my pre-session talk <a href="http://lisug.org/m091118.htm">this past November </a>at <a href="http://lisug.org">LISUG</a>, when I determined that I needed a <a href="http://en.wikipedia.org/wiki/Printf">printf()</a> function for <a href="http://jquery.com">jquery</a>. To be more accurate, more accurately I needed an sprintf() implementation in javascript, and wanted to .</p>
<p>Google lead me to a <a href="http://http://plugins.jquery.com/project/sprintf">jquery plugin</a> that has not been updated since 2007. However, sometimes software gets to the point where it really doesn&#8217;t need to be maintained, and if it worked for me I was not going to dismiss it as abandoned software.</p>
<p>In the end it did require a <a href="http://plugins.jquery.com/node/11385">small patch</a> to handle %% (really print a percentage sign). Unfortunately, the maintainer has not acted on my patch. However, please apply it if you plan on using it.</p>

]]></content:encoded>
			<wfw:commentRss>http://www.justaprogrammer.net/2010/01/16/sprintf-for-jquery/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

