<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" version="2.0">

<channel>
	<title>Rantings in the dark</title>
	
	<link>http://kinsey.no/blog</link>
	<description>Because I want to be like the cool kids too</description>
	<lastBuildDate>Sat, 27 Feb 2010 19:21:55 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/RantingsInTheDark" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="rantingsinthedark" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>easyXDM v1.8.0 relased</title>
		<link>http://kinsey.no/blog/index.php/2010/02/27/easyxdm-v1-8-0-relased/</link>
		<comments>http://kinsey.no/blog/index.php/2010/02/27/easyxdm-v1-8-0-relased/#comments</comments>
		<pubDate>Sat, 27 Feb 2010 19:19:12 +0000</pubDate>
		<dc:creator>oyvind.kinsey</dc:creator>
				<category><![CDATA[easyXDM]]></category>
		<category><![CDATA[cross-domain]]></category>
		<category><![CDATA[cross-site]]></category>
		<category><![CDATA[easyxdm]]></category>
		<category><![CDATA[fragmenting]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[rpc]]></category>
		<category><![CDATA[xdm]]></category>

		<guid isPermaLink="false">http://kinsey.no/blog/?p=269</guid>
		<description><![CDATA[A lot has been going on with easyXDM over the past week, and I am proud to finally be able to release a version where all transport types, even the ones for IE6, deliver the same set of features.
From now on all the transports (and all the relying classes) supports

Reliability, &#8216;guaranteed&#8217; delivery of messages
The new [...]]]></description>
			<content:encoded><![CDATA[<p>A lot has been going on with easyXDM over the past week, and I am proud to finally be able to release a version where all transport types, even the ones for IE6, deliver the same set of features.</p>
<p>From now on all the transports (and all the relying classes) supports</p>
<ul>
<li>Reliability, &#8216;guaranteed&#8217; delivery of messages<br />
The new ReliableBehavior adds this to the HashTransport</li>
<li>Sender-verification,  verifying that the message originates from the original sender. This removes the risk of malicious sites spoofing the sender<br />
This is added to the HashTransport and NameTransport by the VerifyBehavior</li>
<li>Queueing, you can now send multiple messages in the same js thread<br />
This is added to the HashTransport and NameTransport by the QueueBehavior</li>
</ul>
<p><span id="more-269"></span></p>
<h2>Behaviors</h2>
<p>So what are these behaviors mentioned? Well, a behavior modifies the way a transport works, and it works by sending all events and messages through a pipeline of behaviors, where each one can let it pass, inspect it, modify it, block it etc. Each behavior is automatically chained with the others so that they form a stack, where in principal, each layer talks to the corresponding layer on the other end.</p>
<p>One example of this in action is the fragmentation. When the QueueBehavior receives an <strong>outgoing </strong>message that is larger than the max fragment size, then instead of queueing only one message, it will queue each fragment with a fragment identifier. The QueueBehaviors dispatcher will then send each message as fast as it can (it gets a callback from the next Behavior in he line when the message is delivered).</p>
<p>On the other end multiple <strong>ingoing</strong> messages will received at the QueueBehavior, but the message won&#8217;t be passed on until all fragments has arrived.</p>
<p>Using behaviors instead of applying the functionality directly to the classes adds a lot to the table</p>
<ul>
<li>Re-usability, the same behavior can be applied to all transports that accepts these.</li>
<li>Separation, each new feature is contained in a separate class, and since the pipeline is layered, you can safely introduce e.g sender-verification without risking breaking the code that handles the sending/receiving.</li>
<li>Structure, the code is a lot easier to <a href="http://easyxdm.net/v1.8.0/docs/source/easyXDM.transport.html" target="_blank">read</a> and understand, and adding new behaviors are a breeze.</li>
</ul>
<p>This is a sample from the <a href="http://easyxdm.net/v1.8.0/docs/?class=easyXDM.transport.HashTransport" target="_blank">HashTransport </a>and shows how behaviors are applied internally</p>
<pre class="brush: jscript;">
easyXDM.applyBehaviors(this, [
    new easyXDM.transport.behaviors.ReliableBehavior({
        timeout: ((useResize ? 50 : pollInterval * 1.5) + (usePolling ? pollInterval * 1.5 : 50))
    }),
    new easyXDM.transport.behaviors.QueueBehavior({
        maxLength: 4000 - _remoteUrl.length
    }),
    new easyXDM.transport.behaviors.VerifyBehavior({
        initiate: isHost
    })
]);
</pre>
<p>In the future these will be overridable, and you will be able to inject your own if you want to.</p>
<h2>Conclusion</h2>
<p>If you haven&#8217;t already, go <a href="https://www.ohloh.net/p/easyXDM/packages" target="_blank">download the newest version</a> and enjoy the new features!</p>
]]></content:encoded>
			<wfw:commentRss>http://kinsey.no/blog/index.php/2010/02/27/easyxdm-v1-8-0-relased/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>easyXDM – finally with queuing and fragmenting!</title>
		<link>http://kinsey.no/blog/index.php/2010/02/22/easyxdm_and_queuing/</link>
		<comments>http://kinsey.no/blog/index.php/2010/02/22/easyxdm_and_queuing/#comments</comments>
		<pubDate>Mon, 22 Feb 2010 18:11:43 +0000</pubDate>
		<dc:creator>oyvind.kinsey</dc:creator>
				<category><![CDATA[easyXDM]]></category>
		<category><![CDATA[cross-domain]]></category>
		<category><![CDATA[easyxdm]]></category>
		<category><![CDATA[fragmenting]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[queue]]></category>
		<category><![CDATA[rpc]]></category>
		<category><![CDATA[xdm]]></category>

		<guid isPermaLink="false">http://kinsey.no/blog/?p=261</guid>
		<description><![CDATA[With the newest release, 1.7.4 (see the commits here), we have added two important features, fragmenting for the HashTransport, and queing for both the HashTransport and NameTransport

Fragmenting
The first is definitely something that many has been waiting for, until now the HashTransport class just didn&#8217;t cope with messages that would create URLs longer than 4095 character [...]]]></description>
			<content:encoded><![CDATA[<p>With the newest release, <a href="https://www.ohloh.net/p/easyXDM/download?package=easyXDM" target="_blank">1.7.4 </a>(see the commits <a href="http://github.com/oyvindkinsey/easyXDM/commits/v1.7.4" target="_blank">here</a>), we have added two important features, <strong>fragmenting </strong>for the HashTransport, and <strong>queing </strong>for both the HashTransport and NameTransport</p>
<p><span id="more-261"></span></p>
<h2>Fragmenting</h2>
<p>The first is definitely something that many has been waiting for, until now the HashTransport class just didn&#8217;t cope with messages that would create URLs longer than 4095 character (the maximum size allowed by IE6). If a longer message was send (something that could easily happen when using the Interface class), the transport would just fail. But not anymore, you are now able to send however long messages you&#8217;d like, and of course, this was all made possible with the new queuing feature.</p>
<h2>Queuing</h2>
<p>Until now, when you tried to rapidly send messages, if you were so unfortunate to do so before the message had been read, it would be overwritten. This was especially easy to do when the HashTransport was in polling mode, as it then only checks for new messages every 300ms.</p>
<p>Both the HashTransport and the NameTransport has now been extended with a queuing feature, meaning that all messages will first go into a queue, which will then be emptied in a LIFO fashion.</p>
<h2>Conclusion</h2>
<p>easyXDM just got even better, thats about it. The only known feature request as it is now is message receipts, making the transport completely reliable, but I&#8217;m think this probably belongs in the Channel class..</p>
<p>By the way, the Continual Integration system has now been set up so that the test suite for the current head from GitHub will always be available at <a href="http://easyxdm.net/dev/tests/" target="_blank">http://easyxdm.net/dev/tests/</a>.</p>
<p>And one final thing: The project has finally got its first contributors!</p>
]]></content:encoded>
			<wfw:commentRss>http://kinsey.no/blog/index.php/2010/02/22/easyxdm_and_queuing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Resizing iframes using easyXDM</title>
		<link>http://kinsey.no/blog/index.php/2010/02/19/resizing-iframes-using-easyxdm/</link>
		<comments>http://kinsey.no/blog/index.php/2010/02/19/resizing-iframes-using-easyxdm/#comments</comments>
		<pubDate>Fri, 19 Feb 2010 16:52:35 +0000</pubDate>
		<dc:creator>oyvind.kinsey</dc:creator>
				<category><![CDATA[easyXDM]]></category>
		<category><![CDATA[easyxdm]]></category>
		<category><![CDATA[iframe]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[resize]]></category>

		<guid isPermaLink="false">http://kinsey.no/blog/?p=252</guid>
		<description><![CDATA[On thing that many are using easyXDM (and other cross-domain hacks) for, is to dynamically change the size of embedded iframes based on the contents size, so as to avoid the scrollbars.
To make it easier to do this using easyXDM, I have now published an example how how to do this here.
It really is easy, [...]]]></description>
			<content:encoded><![CDATA[<p>On thing that many are using easyXDM (and other cross-domain hacks) for, is to dynamically change the size of embedded iframes based on the contents size, so as to avoid the scrollbars.</p>
<p>To make it easier to do this using easyXDM, I have now published an example how how to do this <a href="http://easyxdm.net/example/resize_iframe.html">here</a>.</p>
<p>It really is easy, on the page hosting the iframe you use the following to load the iframe</p>
<pre class="brush: jscript;">
var transport = new easyXDM.transport.BestAvailableTransport({
    local: &quot;../hash.html&quot;,
    remote: &quot;http://provider.easyxdm.net/example/resized_iframe.html&quot;,
    container: document.getElementById(&quot;element_that_should_contain_the_frame&quot;),
    onMessage: function(message, origin){
        this.container.getElementsByTagName(&quot;iframe&quot;)[0].style.height = message + &quot;px&quot;;
    }
});
</pre>
<p>And then you put the following in the iframes body after the content</p>
<pre class="brush: jscript;">
var transport = new easyXDM.transport.BestAvailableTransport({}, function(){
    transport.postMessage(document.body.scrollHeight);
});
</pre>
<p>Thats it!<br />
Again, the sample can be viewed <a href="http://easyxdm.net/example/resize_iframe.htm">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://kinsey.no/blog/index.php/2010/02/19/resizing-iframes-using-easyxdm/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jsContract – Code contracts for Javascript</title>
		<link>http://kinsey.no/blog/index.php/2010/02/03/jscontract-code-contracts-for-javascript/</link>
		<comments>http://kinsey.no/blog/index.php/2010/02/03/jscontract-code-contracts-for-javascript/#comments</comments>
		<pubDate>Wed, 03 Feb 2010 21:01:10 +0000</pubDate>
		<dc:creator>oyvind.kinsey</dc:creator>
				<category><![CDATA[jsContract]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[code contracts]]></category>
		<category><![CDATA[design by contract]]></category>
		<category><![CDATA[instrumentation]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://kinsey.no/blog/?p=214</guid>
		<description><![CDATA[I have recently started using code contracts in one of my .net projects and I came to think that since most of the code I produce these days are in Javascript, why don&#8217;t I try it there to!
Well, easier said than done &#8211; there just is no decent frameworks for this.
During my searching I found [...]]]></description>
			<content:encoded><![CDATA[<p>I have recently started using <a href="http://en.wikipedia.org/wiki/Design_by_contract" target="_blank">code contract</a>s in one of my .net projects and I came to think that since most of the code I produce these days are in Javascript, why don&#8217;t I try it there to!</p>
<p>Well, easier said than done &#8211; there just is no decent frameworks for this.</p>
<p>During my searching I found some references to libraries such as <a href="http://www.cerny-online.com/cerny.js/documentation/guides/contracts" target="_blank">Cerny.js</a> and <a href="http://weblogs.mozillazine.org/weirdal/archives/016921.html" target="_blank">ecmaDebug</a>, but these just didn&#8217;t make the cut  - they all required heavy (and hard to follow) restructuring of your code to make them work.</p>
<p>So what did I do? Well I made <a href="http://kinsey.no/projects/jsContract/" target="_blank">jsContract</a>, a library that is clean and .. wait for it .. extremely easy to use!<span id="more-214"></span></p>
<p style="padding-left: 30px;"><strong>If you want a quick view on what Code Contracts can give you, take a look at </strong><a href="http://kinsey.no/projects/jsContract/test2.html" target="_blank"><strong>this example</strong></a><strong>!</strong></p>
<p>The following method comes from the sample code in the link above</p>
<pre class="brush: jscript;">    function _internalMethod(a, b){
        Contract.expectNumber(a);
        Contract.expectNumber(b);
        Contract.expectWhen(config.mode === &quot;divide&quot;, b &gt; 0, &quot;Divisor cannot be 0&quot;);
        Contract.expectWhen(config.mode === &quot;multiply&quot;, a &gt; 0 &amp;&amp; b &gt; 0, &quot;The multiplicands cannot be 0&quot;);
        Contract.guaranteesNumber();
        Contract.guarantees(function(result){
            return result &gt; 0;
        }, &quot;Result must be &gt; 0&quot;);

        if (config.mode == &quot;divide&quot;) {
            return a / b;
        }
        // At this point config.mode must be &quot;multiply&quot;
        return a * b;
    }
</pre>
<p>As you can see, the contract statements does not ruin the flow of the code, rather, it helps to document it.<br />
By looking at the contract at the start of the method, you can instantly see what the method expects and what it will return.<br />
This also helps you reduce code since you do not need to check for conditions that are not allowed according to the contract.</p>
<h2>Postconditions</h2>
<p>So, you might be wondering about how the <code>Contract.guarantees</code> methods work? How can a statement placed in the head of the method possibly check the return value of the method?<br />
Well, the above code will actually not check the return value when run, but by running it through  <code>Contract.instrument</code> we can get code that will!<br />
This is the output created by <code>Contract.instrument </code>for the above code</p>
<pre class="brush: jscript;">
    function _internalMethod(a, b){
        arguments.callee.isInstrumented = true;
        /*preconditions*/
        Contract.expectNumber(a);
        Contract.expectNumber(b);
        Contract.expectWhen(config.mode === &quot;divide&quot;, b &gt; 0, &quot;Divisor cannot be 0&quot;);
        Contract.expectWhen(config.mode === &quot;multiply&quot;, a &gt; 0 &amp;&amp; b &gt; 0, &quot;The multiplicands cannot be 0&quot;);
        var __return = (function(a, b){
            if (config.mode == &quot;divide&quot;) {
                return a / b;
            }
            // At this point config.mode must be &quot;multiply&quot;
            return a * b;
        }(a, b));
        /*postconditions*/
        Contract.guaranteesNumber(__return);
        Contract.guarantees(__return, function(result){
            return result &gt; 0;
        }, &quot;Result must be &gt; 0&quot;);
        return __return;
    }
</pre>
<p>As you can see the code block has been wrapped in an anonymous function, the postconditions has been moved below this and has been rewritten so that they take the result as an argument.</p>
<p><strong>We now have both pre- and postconditions checking our code!</strong></p>
<p>The framework handles nested functions just as you would expect it to and the only real change to your code is the extra anonymous function that is inserted when the parser finds a postcondition in use.</p>
<p>But now you might be wondering, how do we get the instrumented code in to our applications?</p>
<p>For this you have several options</p>
<ul>
<li>Use tools like <a href="http://kinsey.no/projects/jsContract/" target="_blank">this</a> to convert the code for you before pasting it into a js file</li>
<li>Use it as a part of you build process for automated generation
<ul>
<li>a commandline tool will be available shortly</li>
</ul>
</li>
<li>Use dynamic loading and instrumentation at runtime</li>
</ul>
<p>The last option is only viable for development scenarios, but that is mainly when code contracts are needed anyways.<br />
To load scripts dynamically you can either use your own AJAX code, or use the built in Contract.load method</p>
<p>The following code is taken from the  <a href="http://kinsey.no/projects/jsContract/test.html" target="_blank">example </a>available with the framework</p>
<pre class="brush: jscript;">
var instrument = (location.search &amp;&amp; location.search.indexOf(&quot;instrument=true&quot;) !== -1);
Contract.load(&quot;MyClass.js&quot;, instrument, function(){
    try {
        var myClass = new MyClass({
            mode: &quot;multiply&quot;
        });

        var result = myClass.publicMethod(34, 5, 3);
    }
    catch (ex) {
        alert(ex.message);
    }
});
</pre>
<p>This code loads regular or instrumented code depending on the query string.</p>
<p>Doesn&#8217;t it look cool?</p>
<p>Its available at <a href="http://github.com/oyvindkinsey/jsContract" target="_blank">github</a> and will most likely be licensed with an MIT style license.</p>
<p>Anybody want to join in, maybe help with some documentation etc?</p>
<p>Drop me a note if so!</p>
<p><strong>Note:</strong> This is the first draft, I started this project today.</p>
<p>The parser is quite naive and strings matching &#8216;function(&#8216; etc and unmatched { and } in comments  will break it. But this is a work in progress <img src='http://kinsey.no/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><strong>Update 1 04.02:</strong> { and } in comments are now safely handled, and several small issues has been corrected.</p>
<p>Now I only need to validate that the functions the parser finds are not part of a comment.</p>
<p><strong>Update 2 04.02:</strong> The parser has now been fixed, it now completely ignores anything in the comments. As far as I know this means that as long as the code validates the parser should be solid as a rock!</p>
]]></content:encoded>
			<wfw:commentRss>http://kinsey.no/blog/index.php/2010/02/03/jscontract-code-contracts-for-javascript/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>easyXDM just became even easier to use!</title>
		<link>http://kinsey.no/blog/index.php/2010/01/02/easyxdm-just-became-even-easier-to-use/</link>
		<comments>http://kinsey.no/blog/index.php/2010/01/02/easyxdm-just-became-even-easier-to-use/#comments</comments>
		<pubDate>Sat, 02 Jan 2010 19:56:04 +0000</pubDate>
		<dc:creator>oyvind.kinsey</dc:creator>
				<category><![CDATA[easyXDM]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[cross-domain]]></category>
		<category><![CDATA[easyxdm]]></category>
		<category><![CDATA[rpc]]></category>

		<guid isPermaLink="false">http://kinsey.no/blog/?p=201</guid>
		<description><![CDATA[To accommodate older browsers that does not implement the postMessage interface, easyXDM is able to fall back to using the URI fragment trick, and until now this has meant that the provided hash.html file had to be uploaded to the local domain (the &#8216;calling&#8217; domain).
This seems to be a dealbreaker for many as they are [...]]]></description>
			<content:encoded><![CDATA[<p>To accommodate older browsers that does not implement the postMessage interface, easyXDM is able to fall back to using the URI fragment trick, and until now this has meant that the provided hash.html file had to be uploaded to the local domain (the &#8216;calling&#8217; domain).</p>
<p>This seems to be a dealbreaker for many as they are unable to upload files to the server, either due to special systems, or because they just want to present an API in the form of &#8216;just include this javascript file&#8217; etc..</p>
<p>With the new <a href="https://www.ohloh.net/p/easyXDM/packages" target="_blank">1.5.5</a> release, this has all changed.</p>
<p>For scenarios where you do not want to upload the hash.html file, you can now point the local attribute to any file present on the local domain, like robots.txt or favicon.ico, and supply a readyAfter attribute with the number of milliseconds to wait before assuming the local file to be loaded and the library to be ready for interaction.</p>
<pre class="brush: jscript;">
{
local: &quot;/robots.txt&quot;,
readyAfter: 1000,
remote: &quot;http://.........&quot;,
...
}
</pre>
<p><strong>Update</strong>: Just released <a href="https://www.ohloh.net/p/easyXDM/packages" target="_blank">1.6.0</a> which makes it possible to utilize the current document instead of loading a new one from the local domain. This makes it very easy to integrate, but does mean that you will be modifying the documents location when falling back to the HashTransport &#8211; and this might interfere with for instance history managers etc.</p>
<pre class="brush: jscript;">
{
local: window,
remote: &quot;http://.........&quot;,
...
}
</pre>
<p>The hash.html file is still the recommended approach for stable<br />
implementations as it is unobtrusive and it guarantees that the library is indeed ready<br />
when transitioning into a ready state.<br />
Using hash.html also shortens the time needed to initialize easyXDM<br />
as there is no need for the delay to give the local file time to<br />
properly load.</p>
<p>All the different ways to set up easyXDM can now be viewed at <a href="http://easyxdm.net/wiki/Documentation.ashx">http://easyxdm.net/wiki/Documentation.ashx</a></p>
]]></content:encoded>
			<wfw:commentRss>http://kinsey.no/blog/index.php/2010/01/02/easyxdm-just-became-even-easier-to-use/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Modifying privileges stored binary using ExtJs</title>
		<link>http://kinsey.no/blog/index.php/2009/11/17/modifying-privileges-stored-binary-using-extjs/</link>
		<comments>http://kinsey.no/blog/index.php/2009/11/17/modifying-privileges-stored-binary-using-extjs/#comments</comments>
		<pubDate>Tue, 17 Nov 2009 18:37:03 +0000</pubDate>
		<dc:creator>oyvind.kinsey</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[binary]]></category>
		<category><![CDATA[bitwise]]></category>
		<category><![CDATA[extjs]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[privileges]]></category>

		<guid isPermaLink="false">http://kinsey.no/blog/?p=180</guid>
		<description><![CDATA[In an earlier post I showed you how to use binary operators to store multiple privileges/settings in a single integer field. Now I will present to you a simple control for visualizing and modifying such a value.


Ext.namespace(&#34;Ext.ux&#34;);
Ext.ux.Privileges = function(config){
    var _formPanel = this;
    var items = [];

   [...]]]></description>
			<content:encoded><![CDATA[<p>In an <a href="http://kinsey.no/blog/index.php/2009/11/17/storing-multiple-privilegessettings-in-a-single-integer/">earlier post</a> I showed you how to use binary operators to store multiple privileges/settings in a single integer field. Now I will present to you a simple control for visualizing and modifying such a value.</p>
<p><span id="more-180"></span></p>
<pre class="brush: jscript;">
Ext.namespace(&quot;Ext.ux&quot;);
Ext.ux.Privileges = function(config){
    var _formPanel = this;
    var items = [];

    for (var key in config.privileges) {
        if (config.privileges.hasOwnProperty(key)) {
            items.push({
                name: &quot;privilege_&quot; + config.privileges[key],
                fieldLabel: key
            });
        }
    }

    Ext.apply(config, {
        defaultType: &quot;checkbox&quot;,
        items: items,
		/**
		 * Updates the form according to the current privileges
		 * @param {Integer} p The integer containing all set privileges
		 */
        setValue: function(p){
            var field, values = {}, privilege;
			for (var key in config.privileges) {
				// Loop over all the privileges, set the value to true if set
                if (config.privileges.hasOwnProperty(key)) {
                    privilege = config.privileges[key];
                    values[&quot;privilege_&quot; + privilege] = (p == (p | privilege));
                }
            }
			// Update the form
            _formPanel.form.setValues(values);
        },
		/**
		 * Returns an integer representing all set privileges
		 * @return Integer
		 */
        getValue: function(){
            var p = 0, field, privilege;
			for (var key in config.privileges) {
				// Loop over all the privileges and see if it is set
                if (config.privileges.hasOwnProperty(key)) {
                    privilege = config.privileges[key];
                    field = _formPanel.form.findField(&quot;privilege_&quot; + privilege);
                    if (field.getValue()) {
						// The privilege is set, lets add it to p
                        p = p | privilege;
                    }
                }
            }
            return p;
        },
		/**
		 * Resets the form
		 */
        clear: function(){
            _formPanel.form.reset();
        }
    });
    Ext.ux.Privileges.superclass.constructor.call(this, config);
};
Ext.extend(Ext.ux.Privileges, Ext.form.FormPanel);
</pre>
<p>Using the following code</p>
<pre class="brush: jscript;">
var _pnlPrivileges= new Ext.ux.Privileges({
	height: 180,
	privileges: {
	    Read: 1,
	    Write: 2,
	    Create: 4,
	    Delete: 8,
	    List: 16,
	    SetPrivileges: 32,
	    Publish: 64
	}
});
</pre>
<p>you end up with something like this</p>
<p><img class="size-full wp-image-183 alignnone" title="privileges" src="http://kinsey.no/blog/wp-content/uploads/2009/11/privileges.png" alt="privileges" width="414" height="196" /></p>
<p>The controll exposes its functionality in two methods, setValue and getValue &#8211; both of these should be easy to understand <img src='http://kinsey.no/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://kinsey.no/blog/index.php/2009/11/17/modifying-privileges-stored-binary-using-extjs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Storing multiple privileges/settings in a single integer</title>
		<link>http://kinsey.no/blog/index.php/2009/11/17/storing-multiple-privilegessettings-in-a-single-integer/</link>
		<comments>http://kinsey.no/blog/index.php/2009/11/17/storing-multiple-privilegessettings-in-a-single-integer/#comments</comments>
		<pubDate>Tue, 17 Nov 2009 18:20:10 +0000</pubDate>
		<dc:creator>oyvind.kinsey</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[binary]]></category>
		<category><![CDATA[bitwise]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[privileges]]></category>

		<guid isPermaLink="false">http://kinsey.no/blog/?p=168</guid>
		<description><![CDATA[In many applications you have the need to set users privileges , and while there are many ways to do so, I prefer to using a single integer value to store a users privileges on any single entity.
This has many advantages,

you only have a single value representing all privileges
you can add and remove available privileges [...]]]></description>
			<content:encoded><![CDATA[<p>In many applications you have the need to set users privileges , and while there are many ways to do so, I prefer to using a single integer value to store a users privileges on any single entity.</p>
<p>This has many advantages,</p>
<ul>
<li>you only have a single value representing all privileges</li>
<li>you can add and remove available privileges without altering the schema/entity model/storage logic</li>
<li>checking for privileges are very simple</li>
</ul>
<p><span id="more-168"></span></p>
<p>Now you might be wondering, how is it possible to store any number of privileges in a single integer?<br />
One of the keys to doing this are the values that you assign each privilege, these must each be twice the previous value.</p>
<p>For example</p>
<ul>
<li>Read = 1</li>
<li>Write = 2</li>
<li>Delete = 4</li>
<li>&#8230; = 8</li>
</ul>
<p>To understand why we do it like this we need to take a look at the individual integers binary representation</p>
<pre>1 = 00000001
2 = 00000010
4 = 00000100
8 = 00001000
</pre>
<p>Anyone see the pattern?</p>
<p>And if you were to sum some of these, say Write (2) + Delete(4)</p>
<pre>00000010
+
00000100
=
00000110
</pre>
<p>Again, you see the pattern?</p>
<p>Each privilege is being stored as a single bit in the integer, and each bit can be checked against even if you add multiple values together.</p>
<p>So, now that we have some of the theory covered, how do we utilize this?</p>
<p>If you have an integer you can easily check for any fraction using a simple statement</p>
<p>In JavaScript</p>
<pre class="brush: jscript;">
var allPrivileges = 6;
var hasWrite = (allPrivileges  == (allPrivileges  | 2));
</pre>
<p>In VB.net</p>
<pre class="brush: vb;">
Dim allPrivileges As Integer = 6
Dim hasWrite As Boolean = allPrivileges = (allPrivileges Or 2)
</pre>
<p>Here we are using the bitwise operator | (<strong>or</strong>) to check that allPrivileges (6) binary <strong>or</strong>&#8216;ed with 2 equals 6, meaning that 2 is a contained fraction of 6.</p>
<p>Now if you want to add a new privilege (or existing one) you just binary <strong>or </strong>the current integer with the new integer<br />
In JavaScript</p>
<pre class="brush: jscript;">
var allPrivileges = 4;
allPrivileges = allprivileges | 2;
// allPrivileges equals 6
allPrivileges= allprivileges | 2;
// allPrivileges still equals 6
</pre>
<p>In VB.net</p>
<pre class="brush: vb;">
Dim allPrivileges As Integer = 4
allPrivileges = (allPrivileges Or 2)
' allPrivileges equals 6
allPrivileges = (allPrivileges Or 2)
' allPrivileges still equals 6
</pre>
<p>Wasn&#8217;t that easy?</p>
<p>In an <a href="http://kinsey.no/blog/index.php/2009/11/17/modifying-privileges-stored-binary-using-extjs/#more-180"> upcoming post</a> I will show you a simple ExtJs control for visualizing and modifying a users privileges.</p>
]]></content:encoded>
			<wfw:commentRss>http://kinsey.no/blog/index.php/2009/11/17/storing-multiple-privilegessettings-in-a-single-integer/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How to restrict your web app to a single instance</title>
		<link>http://kinsey.no/blog/index.php/2009/11/15/how-to-restrict-your-web-app-to-a-single-instance/</link>
		<comments>http://kinsey.no/blog/index.php/2009/11/15/how-to-restrict-your-web-app-to-a-single-instance/#comments</comments>
		<pubDate>Sun, 15 Nov 2009 15:37:07 +0000</pubDate>
		<dc:creator>oyvind.kinsey</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Single instance]]></category>

		<guid isPermaLink="false">http://kinsey.no/blog/?p=157</guid>
		<description><![CDATA[When building complex web applications it is often necessarry to restrict the user to keeping only a single instance open, and to do this you need to check for the precense of an existing instance, either directly or indirectly.

One way of doing this indirectly would be to set a cookie using javascript when the page [...]]]></description>
			<content:encoded><![CDATA[<p>When building complex web applications it is often necessarry to restrict the user to keeping only a single instance open, and to do this you need to check for the precense of an existing instance, either directly or indirectly.</p>
<p><span id="more-157"></span></p>
<p>One way of doing this indirectly would be to set a cookie using javascript when the page loads and then use the unload event to remove the cookie. This means that as long as there is an instance open, the cookie will be set, and this can be tested for when the page loads.</p>
<pre class="brush: jscript;">
window.onload = function(){
    if (document.cookie.indexOf(&quot;_instance=true&quot;) === -1) {
        document.cookie = &quot;_instance=true&quot;;
        // Set the onunload function
        window.onunload = function(){
            document.cookie =&quot;_instance=true;expires=Thu, 01-Jan-1970 00:00:01 GMT&quot;;
        };
        // Load the application
    }
    else {
        // Notify the user
    }
};
</pre>
<p>The disadvantage of doing it this way is that you increase the amount of data being sent to the server with each request as all cookies are being sent, but the cookie could be restricted to the documents path so that it would not be sent with non-matching requests.</p>
<p>The direct way would be to try to get a reference to the existing window using its name, but this does involve using window.open, which means the method could be blocked and rendered unreliable by popup blockers. But then again, complex application often need popups to be enabled and one could use this to check for and alert the user about the popup blocker.</p>
<pre class="brush: jscript;">
window.onload = function(){
    var doLoad = false, name = &quot;unique_name&quot;, existing = window.open(&quot;&quot;, name, &quot;&quot;);
    if (!existing) {
        // Notify the user about allowing popups
        alert(&quot;Popup blocker detected\nPlease allow popups for this domain.&quot;);
        return;
    }
    if (window === existing) {
        doLoad = true;
    }
    else {
        if (existing.document.title !== window.document.title) {
            // The referenced window is not an existing instance
            doLoad = true;
            existing.close();
            window.name = name;
        }
    }
    if (doLoad) {
        // Load the application
    }
    else {
        // Notify user
    }
};
</pre>
<p>Which way you choose is entirely up to you.<br />
If you know any other ways, feel free to add it in the comments <img src='http://kinsey.no/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://kinsey.no/blog/index.php/2009/11/15/how-to-restrict-your-web-app-to-a-single-instance/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Upcoming book review – “Ext JS 3.0 Cookbook”</title>
		<link>http://kinsey.no/blog/index.php/2009/11/11/upcoming-book-review-ext-js-3-0-cookbook/</link>
		<comments>http://kinsey.no/blog/index.php/2009/11/11/upcoming-book-review-ext-js-3-0-cookbook/#comments</comments>
		<pubDate>Wed, 11 Nov 2009 14:03:35 +0000</pubDate>
		<dc:creator>oyvind.kinsey</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[book review]]></category>
		<category><![CDATA[extjs]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://kinsey.no/blog/?p=143</guid>
		<description><![CDATA[The nice people at Packt Publishing has asked me to do a book review of  Jorge Ramons &#8220;Ext JS 3.0 Cookbook&#8220;.
According to the book description the following subjects will be covered

Work with different browsers, platforms, and the DOM, as well as determine and understand the different ExtJS data types
Create your own custom Ext JS data [...]]]></description>
			<content:encoded><![CDATA[<p><img class="size-thumbnail wp-image-145 alignright" title="Ext JS 3.0 Cookbook" src="http://kinsey.no/blog/wp-content/uploads/2009/11/1847198708-150x150.jpg" alt="Ext JS 3.0 Cookbook" width="150" height="150" />The nice people at <a href="http://www.packtpub.com/" target="_blank">Packt Publishing</a> has asked me to do a book review of  <a href="http://miamicoder.com/" target="_blank">Jorge Ramons</a> &#8220;<a href="http://www.packtpub.com/ext-js-3-0-cookbook/book" target="_blank">Ext JS 3.0 Cookbook</a>&#8220;.</p>
<p>According to the book description the following subjects will be covered</p>
<ul>
<li>Work with different browsers, platforms, and the DOM, as well as determine and understand the different ExtJS data types</li>
<li>Create your own custom Ext JS data types as you extend their functionality</li>
<li>Build great-looking and friendly forms by using client and server-side field validation, form loading, submission, field customization, and layout techniques</li>
<li>Explore the different layouts provided by the Ext JS library as well as create your own, and understand their common uses</li>
<li>Display, edit, and group tabular data generated by the server using Grid Panels</li>
<li>Explore the advantages and the efficiency tradeoffs of widgets such as Combo boxes</li>
<li>Use the drag and drop features of the grid component, data editing with the new RowEditor Class, and the new lightweight ListView component</li>
<li>Explore multiple ways of displaying master-details relationships</li>
<li>Group components or information under the same container to build hierarchical views of information by using TabPanel components</li>
<li>Use patterns to build a solid and flexible application architecture and implement additional design patterns such as auto-saving form elements, component state management, and code modules to build robust and flexible applications with Ext JS</li>
<li>Build your own custom components on top of the Ext framework and enhance the custom components created by the Ext JS users&#8217; community</li>
</ul>
<p>I&#8217;m looking forward to this as Ext and JavaScript are two things that I am quite passionate about <img src='http://kinsey.no/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://kinsey.no/blog/index.php/2009/11/11/upcoming-book-review-ext-js-3-0-cookbook/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using WCF/svc’s automatically generated javascript proxies _without_ ASP.NET AJAX</title>
		<link>http://kinsey.no/blog/index.php/2009/10/28/using-wcfsvcs-automatically-generated-javascript-proxies-_without_-asp-net-ajax/</link>
		<comments>http://kinsey.no/blog/index.php/2009/10/28/using-wcfsvcs-automatically-generated-javascript-proxies-_without_-asp-net-ajax/#comments</comments>
		<pubDate>Wed, 28 Oct 2009 17:11:05 +0000</pubDate>
		<dc:creator>oyvind.kinsey</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[asp.net ajax]]></category>
		<category><![CDATA[Ext Js]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[proxy]]></category>
		<category><![CDATA[svc]]></category>
		<category><![CDATA[wcf]]></category>
		<category><![CDATA[webservices]]></category>

		<guid isPermaLink="false">http://kinsey.no/blog/?p=133</guid>
		<description><![CDATA[Most of my web based projects consist of WCF driven webservices at the backend and a javascript UI using ExtJS, and for access to the WCF webservice I like to use its automatically generated proxies as this abstracts away the feeling of working with XMLHttpRequests, actually it abstracts it to a level where you can [...]]]></description>
			<content:encoded><![CDATA[<p>Most of my web based projects consist of WCF driven webservices at the backend and a javascript UI using <a href="http://extjs.com" target="_blank">ExtJS</a>, and for access to the WCF webservice I like to use its automatically generated proxies as this abstracts away the feeling of working with XMLHttpRequests, actually it abstracts it to a level where you can call the server side method &#8216;directly&#8217;, specifying only a callback function that should receive the response. These proxies are dynamically generated and will always reflect the serverside methods signature.<br />
<span id="more-133"></span><br />
To use the proxies all you need to do is (as long as the correct bindings are in place) access the .svc file with either &#8216;/js&#8217; or &#8216;/jsdebug&#8217; appended, and you will get the generated proxies.<br />
By the way, if you use any objects, either as an argument or as a return type, these will also be created as javascript &#8216;classes&#8217;, the same with any enumerations &#8211; its all wery nice.</p>
<p>Using both <a href="http://www.asp.net/ajax/" target="_blank">ASP.NET AJAX</a> and <a href="http://extjs.com" target="_blank">ExtJS </a>on the same page does not create any serious problems (I think there might be a couple of collisions on the Date object), but it does mean that you have quite a bit of overhead.</p>
<p>Removing the ASP.NET AJAX framework does not work initially as the generated proxy code needs this to work, so if we remove the ASP.NET AJAX framework, well, then we are going to need to replace it with something that caters to the proxy codes needs without the extra overhead of loading the entire ASP.NET AJAX framework. And here it is &#8211; this is the minimum of code needed to bootstrap the automatically generated proxy code, and to tie it into the ExtJs framework. If you want to use it with a different framework then it should not be a difficult task to exchange the Ext dependencies.</p>
<pre class="brush: jscript; smart-tabs: true; tab-size: 4;">
// Extend Functions prototype
Ext.apply(Function.prototype, {
    initializeBase: function(instance, baseArguments){
    },
    registerClass: function(typeName, baseType, interfaceTypes){
        if (baseType) {
            Ext.apply(this.prototype, baseType.prototype);
        }
    },
    registerEnum: function(name, flags){
    }
});
// Add Type and Type.registerNamespace
Ext.namespace(&quot;Type&quot;);
Type.registerNamespace = Ext.namespace;

// Create the Sys.Net.WebServiceProxy object
Ext.namespace(&quot;Sys.Net&quot;);
Sys.Net.WebServiceProxy = function(){
};
Sys.Net.WebServiceProxy._generateTypedConstructor = function(type){
    return function(properties){
        if (properties) {
            for (var name in properties) {
                this[name] = properties[name];
            }
        }
        this.__type = type;
    };
};
Ext.apply(Sys.Net.WebServiceProxy.prototype, {
    _invoke: function(path, action, useGet, params, onSuccess, onFailure, userContext){
	// Use Ext.Ajax to perform the xhr call
        Ext.Ajax.request({
            url: path + &quot;/&quot; + action,
            method: useGet ? &quot;get&quot; : &quot;post&quot;,
            jsonData: params,
            success: function(data){
                onSuccess(Ext.decode(data.responseText).d);
            },
            failure: function(data){
                onFailure(Ext.decode(data.responseText).d);
            },
            scope: userContext
        });
    },
    set_path: function(path){
        this._path = path;
    },
    get_path: function(){
        return this._path;
    }
});
</pre>
]]></content:encoded>
			<wfw:commentRss>http://kinsey.no/blog/index.php/2009/10/28/using-wcfsvcs-automatically-generated-javascript-proxies-_without_-asp-net-ajax/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
