<?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>Claus Witt &#187; dojo</title> <atom:link href="http://www.clauswitt.com/tag/dojo/feed/" rel="self" type="application/rss+xml" /><link>http://www.clauswitt.com</link> <description>software and web developer</description> <lastBuildDate>Thu, 24 Jun 2010 20:07:03 +0000</lastBuildDate> <generator>http://wordpress.org/?v=2.9.2</generator> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <item><title>Could MemcacheQ be Used For Cometd?</title><link>http://www.clauswitt.com/could-memcacheq-be-used-for-cometd/</link> <comments>http://www.clauswitt.com/could-memcacheq-be-used-for-cometd/#comments</comments> <pubDate>Tue, 07 Apr 2009 21:32:47 +0000</pubDate> <dc:creator>Claus Witt</dc:creator> <category><![CDATA[Web development]]></category> <category><![CDATA[comet]]></category> <category><![CDATA[dojo]]></category> <category><![CDATA[memcacheq]]></category><guid isPermaLink="false">http://www.clauswitt.com/?p=214</guid> <description><![CDATA[I have been wondering for a couple of weeks would it be possible to use MemcacheQ as a kind of backend for Cometd? The reason I find it interesting is that sending message to the queue(s) would be as easy asmemcache_set($memcache_obj, $memcache_queue_name, $msg, 0, 0);In other words easy as pie. Since there are all [...]]]></description> <content:encoded><![CDATA[<p>I have been wondering for a couple of weeks would it be possible to use <a href="http://memcachedb.org/memcacheq/">MemcacheQ</a> as a kind of backend for <a href="http://en.wikipedia.org/wiki/Comet_(programming)">Cometd</a>? The reason I find it interesting is that sending message to the queue(s) would be as easy as</p><pre name="code" class="php">
memcache_set($memcache_obj, $memcache_queue_name, $msg, 0, 0);
</pre><p>In other words easy as pie.</p><p>Since there are all sorts of client libraries for memcached (and thus for memcacheq as well, since it uses the same protocol). I have been tinkering a bit last weekend, with some minor tests. I based it on <a href="http://sourceforge.net/projects/comet/">Comep</a> since I knew nothing of writing daemons in php or the comet protocol for that mather. (I would just like to use it).</p><p>Now I am not sure if Comep is even compatible with Dojo&#8217;s dojox.cometd.subscribe &#8211; and I have not gotten around to test that either. But since I have not had the time to look further into this, I thought I would just post my ideas, and hopefully someone &#8211; might even be me, once things quiets down, picks up the pieces and makes something great out of it.</p><pre name="code" class="php">
// Set the ip and port we will listen on
$address = '192.168.1.3';
$port = '666';
$max_clients = 10;

/* connect to memcached server */
$memcache_obj = memcache_connect('127.0.0.1', 22201);
if(!$memcache_obj) {
	die('Memcache object is false');
}
$memcache_queue_name = 'queue1';

$children = array();
// Array that will hold client information
$clients = Array();
$receiveClients = Array();
$client_ID = array();

// Create a TCP Stream socket
$sock = socket_create(AF_INET, SOCK_STREAM, 0);
// Bind the socket to an address/port
socket_bind($sock, $address, $port) or die('Could not bind to address');
socket_getsockname($sock, $socket_address, $socket_port);

echo "COMET-Server startet on Port: ".$socket_port."\n";

// Start listening for connections
socket_listen($sock);
$lastPingTime = 0;
// Loop continuously
while (true) {
    // Setup clients listen socket for reading
    $read = array();
    $read[0] = $sock;
    for ($i = 0; $i < $max_clients; $i++) {
        if ($client[$i]['sock']  != null) $read[$i + 1] = $client[$i]['sock'] ;
    }
    // Set up a blocking call to socket_select()
    $ready = socket_select($read,$A=null,$B=null,1);

    /* if a new connection is being made add it to the client array */
    if (in_array($sock, $read)) {
        for ($i = 0; $i < $max_clients; $i++) {
            if ($client[$i]['sock'] == null) {
                $client[$i]['sock'] = socket_accept($sock);
				echo 'New client';
                break;
            } else if ($i == $max_clients - 1) {

			}
        }
        if (--$ready <= 0)
            continue;
    } // end if in_array
    $value = json_encode(memcache_get($memcache_obj, $memcache_queue_name));
	if($value &#038;&#038; $value!="false") {
    	echo 'Sending value to queue: ' . $value . "\n";
		for ($i = 0; $i < $max_clients; $i++) { // for each client
	        if (in_array($client[$i]['sock'] , $read)) {
				socket_write($client[$i]['sock'], "HTTP/1.0 200 OK\r\n\r\n");
				socket_write($client[$i]['sock'], $value . "\r\n\r\n");
	        } else {
	            // Close the socket
	            if(!is_null($client[$i]['sock'])) {
					socket_close($client[$i]['sock']);
				}
	            unset($client[$i]["sock"]);
	        }
	    }
	}

} // end while
// Close the master sockets
socket_close($sock);
</pre>]]></content:encoded> <wfw:commentRss>http://www.clauswitt.com/could-memcacheq-be-used-for-cometd/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>New Versions of Dojo and Plugd Released</title><link>http://www.clauswitt.com/new-versions-of-dojo-and-plugd-released/</link> <comments>http://www.clauswitt.com/new-versions-of-dojo-and-plugd-released/#comments</comments> <pubDate>Wed, 01 Apr 2009 06:16:31 +0000</pubDate> <dc:creator>Claus Witt</dc:creator> <category><![CDATA[Web development]]></category> <category><![CDATA[dojo]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[plugd]]></category><guid isPermaLink="false">http://www.clauswitt.com/?p=210</guid> <description><![CDATA[I have not posted for about a week now, the main reason is that I am working on something very exciting, which will be features here in the comming days, if all works out. Today, while reading the most recent posts on Ajaxian, I found the announcement of the Dojo 1.3 release. Read the announcement [...]]]></description> <content:encoded><![CDATA[<p>I have not posted for about a week now, the main reason is that I am working on something very exciting, which will be features here in the comming days, if all works out.</p><p>Today, while reading <a href="http://www.ajaxian.com">the most recent posts on Ajaxian</a>, I found <a href="http://ajaxian.com/archives/dojo-13-released-along-with-plugd">the announcement of the Dojo 1.3 release</a>. <a href="http://www.dojotoolkit.org/2009/03/31/dojo-1-3-now-available">Read the announcement</a> and <a href="http://code.google.com/p/plugd/">learn about the plugd plugin</a>.</p><p>I will be using some time to update our project, which by the way will be going into the first testphase in 13 days, to the newest version of Dojo Toolkit today.</p> ]]></content:encoded> <wfw:commentRss>http://www.clauswitt.com/new-versions-of-dojo-and-plugd-released/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Plugd &#8211; Dojo: the missing APIs</title><link>http://www.clauswitt.com/plugd-dojo-the-missing-apis/</link> <comments>http://www.clauswitt.com/plugd-dojo-the-missing-apis/#comments</comments> <pubDate>Mon, 09 Mar 2009 15:00:16 +0000</pubDate> <dc:creator>Claus Witt</dc:creator> <category><![CDATA[Development]]></category> <category><![CDATA[Web development]]></category> <category><![CDATA[dojo]]></category> <category><![CDATA[js]]></category> <category><![CDATA[plugd]]></category><guid isPermaLink="false">http://www.clauswitt.com/?p=160</guid> <description><![CDATA[Just today, while reading about the release of the Dojo Toolkit 1.3 beta, I learned about the plugd addition to Dojo Toolkit. The author of plugd describes it this way.The API&#8217;s found in plugd are loosely based on &#8220;my favorite bits of jQuery&#8221; &#8230; this is not meant to be a &#8216;compatibility shim&#8217; of [...]]]></description> <content:encoded><![CDATA[<p>Just today, while reading about the <a href="http://www.clauswitt.com/2009/03/09/dojo-toolkit-13-beta-is-out/">release of the Dojo Toolkit 1.3 beta</a>, I learned about the <a href="http://code.google.com/p/plugd/">plugd</a> addition to Dojo Toolkit. The author of plugd describes it this way.</p><blockquote><p> The API&#8217;s found in plugd are loosely based on &#8220;my favorite bits of jQuery&#8221; &#8230; this is not meant to be a &#8216;compatibility shim&#8217; of any kind, it is simply the addition of functions and helpers to Dojo Base. Added magic.</p><p>plugd adds several convenience functions, all located in the dojo namespace. For instance, by loading base.js into a page, the following new Dojo API&#8217;s are made available:</p><p> * dojo.show(), dojo.hide(), dojo.toggle()<br /> * dojo.conflict()<br /> * dojo.wrap()<br /> * dojo.create()</p><p>And the following methods are added to dojo.NodeList (what you get back from calling dojo.query() (or $() after running dojo.conflict()):</p><p> * .wrap()<br /> * .show(), .hide(), .toggle()<br /> * .val()<br /> * .append()<br /> * .appendTo()<br /> * .create()<br /> * .animate()<br /> * .destroy()<br /> * .hover()<br /> * .end() (and stash() for private use)</p></blockquote> ]]></content:encoded> <wfw:commentRss>http://www.clauswitt.com/plugd-dojo-the-missing-apis/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Dojo Toolkit 1.3 Beta is Out</title><link>http://www.clauswitt.com/dojo-toolkit-13-beta-is-out/</link> <comments>http://www.clauswitt.com/dojo-toolkit-13-beta-is-out/#comments</comments> <pubDate>Mon, 09 Mar 2009 14:30:01 +0000</pubDate> <dc:creator>Claus Witt</dc:creator> <category><![CDATA[Development]]></category> <category><![CDATA[Web development]]></category> <category><![CDATA[dojo]]></category> <category><![CDATA[js]]></category><guid isPermaLink="false">http://www.clauswitt.com/?p=158</guid> <description><![CDATA[Alex Russel just (well a couple of days ago) anounced that the beta of the newest version of Dojo Toolkit is available. I&#8217;m looking forward to the actual release of this version, it seems very very fast. Dojo has always (since I got around to learning about javascript frameworks anyway) been my favourite js-framework. Maybe [...]]]></description> <content:encoded><![CDATA[<p><a href="http://alex.dojotoolkit.org/">Alex Russel</a> just (well a couple of days ago) <a href="http://alex.dojotoolkit.org/2009/03/dojo-13b3-is-out/">anounced</a> that the <a href="http://www.dojotoolkit.org/book/1-3-release-notes">beta of the newest version of Dojo Toolkit</a> is available. I&#8217;m looking forward to the actual release of this version, it seems <a href="http://selectors.turnwheel.com/">very very fast</a>.</p><p>Dojo has always (since I got around to learning about javascript frameworks anyway) been my favourite js-framework. Maybe this is just because it was the first one I learned to use. But it is built a way that seems very intuitive to me. I guess (if I had been a superstar js-developer) I would have done everything just as they have done. I am looking forward to learning even more about the new version of Dojo Toolkit, and creating even more applications using it in the near future.</p> ]]></content:encoded> <wfw:commentRss>http://www.clauswitt.com/dojo-toolkit-13-beta-is-out/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>Upload Progress Bar using Php and Dojo</title><link>http://www.clauswitt.com/upload-progress-bar-using-php-and-dojo/</link> <comments>http://www.clauswitt.com/upload-progress-bar-using-php-and-dojo/#comments</comments> <pubDate>Wed, 25 Feb 2009 12:00:56 +0000</pubDate> <dc:creator>Claus Witt</dc:creator> <category><![CDATA[Development]]></category> <category><![CDATA[Web development]]></category> <category><![CDATA[dojo]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[php]]></category><guid isPermaLink="false">http://www.clauswitt.com/?p=101</guid> <description><![CDATA[For a long time I have wanted my applications to have progress bars on uploads, but I have always thought that this was impossible when the server language was php. Unless of course you wanted to do some mixing of languages, and handle the upload via perl. I, however, wanted complete integration of the code, [...]]]></description> <content:encoded><![CDATA[<p>For a long time I have wanted my applications to have progress bars on uploads, but I have always thought that this was impossible when the server language was php. Unless of course you wanted to do some mixing of languages, and <a href="http://www.raditha.com/php/progress.php" target="_blank">handle the upload via perl</a>. I, however, wanted complete integration of the code, and wanted my mvc framework to be able to output the wanted information. A while ago my boss at <a title="VoiceArchive.com - the internet voice talent agency" href="http://www.voicearchive.com" target="_blank">Voicearchive</a> asked me if we could get a progress bar for uploads on the system that we are developing. Once again I found myself searching for possible solutions.</p><p>This time around, however, I found what I was looking for. I found an article about <a title="HOWTO: PHP and jQuery upload progress bar" href="http://t.wits.sg/2008/06/25/howto-php-and-jquery-upload-progress-bar/" target="_blank">PHP and jQuery upload progress bar</a>. In this article I learned about the <a title="pecl package uploadprogress" href="http://pecl.php.net/package/uploadprogress">PECL extension uploadprogress</a>. I began trying to make this solution work.</p><p>First thing, was that I found the extension did not work as I wanted. After a while I found that installing newest version, required installing it via &#8220;pecl install channel://pecl.php.net/uploadprogress-0.9.2&#8243; &#8211; which gave me the latest beta release of the extension. Now it returned the correct information when I uploaded a file.</p><p>The solution consists of 5 parts.</p><ol><li>The Pecl extension</li><li>The form</li><li>The progressbar widget</li><li>The javascript</li><li>and the controller which sends the data from uploadprogress as json to the client</li></ol><p>After the installation was managed, I changed the form to have the required hidden UPLOAD_IDENTIFIER value included.</p><pre name="code" class="xhtml">
<input id="addFileProgressKey" name="UPLOAD_IDENTIFIER" type="hidden" value="" />
</pre><p>The value of the field is set when the dialogbox containing the upload form is revealed, and saved in a variable, that can be used when the script needs to poll for the result.</p><pre name="code" class="javascript">
lastFileProgressKey = guid();
console.log(lastFileProgressKey);
dojo.byId('addFileProgressKey').value = lastFileProgressKey;
dijit.byId('addFileDialog').show();
</pre><p>The guid function is just a simple function which generates a guid-like random string. The value is then set to the form, and the dialog is revealed.</p><p>When the upload button on the form is pressed it calls a event handler which handles the actual upload. Before the upload is started however the following function is called.</p><pre name="code" class="javascript">
startUploadCheck(lastFileProgressKey);
</pre><p>These function do the actual work.</p><pre name="code" class="javascript">
function updateProgressBar(response) {
	if(response) {
		totalBytes = parseInt(response.bytes_total);
		uploadedBytes = parseInt(response.bytes_uploaded);
		percentage = Math.floor(100 * uploadedBytes/ totalBytes);
		uploadProgressBar.update({ progress: percentage+'%'});
		if(lastUploadId!='') {
			setTimeout("checkUpload()", 1000);
		}
	} else {
		if(lastUploadId!='') {
			setTimeout("checkUpload()", 1000);
		}
	}
}

function checkUpload() {
	dojo.xhrGet( {
		url :'/uploadprogress/check?uploadid='+lastUploadId,
		handleAs: 'json',
		preventCache: true,
		load: updateProgressBar,
		error: function(data) {
			if(lastUploadId!='') {
				setTimeout("checkUpload()", 1000);
			}
		}
	});
}

function startUploadCheck(uploadid) {
	dijit.byId('uploadProgressDialog').show();
	lastUploadId = uploadid;
	checkUpload( uploadid );
}

function hideProgressDialog() {
	lastUploadId = '';
	dijit.byId('uploadProgressDialog').hide();
}
</pre><p>The dojo widget used is the <a href="http://www.dojotoolkit.org/book/dojo-book-0-9/part-2-dijit/user-assistance-and-feedback/progress-bar" target="_blank" title="Dojo ProgressBar">ProgressBar</a>.</p><p>The controller is the simplest part of the equation.</p><pre name="code" class="php">
public function check() {
    $formUploadId = $this->request['uploadid'];
    return json_encode(uploadprogress_get_info($formUploadId));
}
</pre><p>All the legwork is done by uploadprogress_get_info, which then is passed through json_encode.</p> ]]></content:encoded> <wfw:commentRss>http://www.clauswitt.com/upload-progress-bar-using-php-and-dojo/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using memcached
Page Caching using memcached (user agent is rejected)
Database Caching using memcached

Served from: www.clauswitt.com @ 2010-07-30 04:27:47 -->