<?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; javascript</title> <atom:link href="http://www.clauswitt.com/tag/javascript/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>Project Euler Problem Five</title><link>http://www.clauswitt.com/project-euler-problem-five/</link> <comments>http://www.clauswitt.com/project-euler-problem-five/#comments</comments> <pubDate>Mon, 07 Jun 2010 06:30:37 +0000</pubDate> <dc:creator>Claus Witt</dc:creator> <category><![CDATA[Development]]></category> <category><![CDATA[evenly divisable]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[nodejs]]></category> <category><![CDATA[problem five]]></category> <category><![CDATA[project euler]]></category><guid isPermaLink="false">http://www.clauswitt.com/?p=398</guid> <description><![CDATA[Continuing our combined node.js and project euler posts. We got to problem five, which asks us &#8220;What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?&#8221;. First of all we only check numbers below or equal to 20! because we know for sure that this number [...]]]></description> <content:encoded><![CDATA[<p>Continuing our combined <a href="http://nodejs.org">node.js</a> and <a href="http://www.clauswitt.com/tag/project-euler/">project euler posts</a>. We got to <a href="http://projecteuler.net/index.php?section=problems&#038;id=5">problem five</a>, which asks us &#8220;What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?&#8221;.</p><p>First of all we only check numbers below or equal to 20! because we know for sure that this number will satisfy the criterium of the question, we just don&#8217;t know if there is a result below this number, we also know that the number must be at least 20. For this reason we check all numbers between 20 and 20! if all numbers between 1 and 20 is a divisor &#8211; if one of the numbers fail, we move on to the next candidate. As soon as a candidate proves to be correct, we exit and return the result.</p> <script src="http://gist.github.com/420267.js"></script> ]]></content:encoded> <wfw:commentRss>http://www.clauswitt.com/project-euler-problem-five/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Project Euler Problem Four</title><link>http://www.clauswitt.com/project-euler-problem-four/</link> <comments>http://www.clauswitt.com/project-euler-problem-four/#comments</comments> <pubDate>Fri, 04 Jun 2010 06:00:34 +0000</pubDate> <dc:creator>Claus Witt</dc:creator> <category><![CDATA[Development]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[largest palindrome]]></category> <category><![CDATA[problem four]]></category> <category><![CDATA[project euler]]></category><guid isPermaLink="false">http://www.clauswitt.com/?p=390</guid> <description><![CDATA[Find the largest palindrome made from the product of two 3-digit numbers. This is problem four of project euler, and this one actually caused me some problems. The reason was that I wrongly assumed that a number with the largest divisor would also would be the largest number. But of course this is not necessarily [...]]]></description> <content:encoded><![CDATA[<p>Find the largest palindrome made from the product of two 3-digit numbers. This is <a href="http://projecteuler.net/index.php?section=problems&#038;id=4">problem four of project euler</a>, and this one actually caused me some problems. The reason was that I wrongly assumed that a number with the largest divisor would also would be the largest number. But of course this is not necessarily the case.</p> <script src="http://gist.github.com/418472.js"></script> <p>As the <a href="http://www.clauswitt.com/project-euler-problem-one/">previous</a> <a href="http://www.clauswitt.com/project-euler-problem-two/">three</a> <a href="http://www.clauswitt.com/project-euler-problem-three/">problems</a> I have posted about, this is written to run on <a href="http://nodejs.org">node.js</a>.</p> ]]></content:encoded> <wfw:commentRss>http://www.clauswitt.com/project-euler-problem-four/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Project Euler Problem Three</title><link>http://www.clauswitt.com/project-euler-problem-three/</link> <comments>http://www.clauswitt.com/project-euler-problem-three/#comments</comments> <pubDate>Tue, 01 Jun 2010 06:00:54 +0000</pubDate> <dc:creator>Claus Witt</dc:creator> <category><![CDATA[Development]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[nodejs]]></category> <category><![CDATA[problem three]]></category> <category><![CDATA[project euler]]></category><guid isPermaLink="false">http://www.clauswitt.com/?p=388</guid> <description><![CDATA[Continuing my posts about Project Euler Problems, this time with problem three, which asks us to find the &#8220;the largest prime factor of the number 600851475143&#8243;. This time I have decided to explain the code a bit more, through comments &#8211; since this problem is a bit more tricky than the previous two problems. Once [...]]]></description> <content:encoded><![CDATA[<p>Continuing my posts about <a href="http://projecteuler.net/index.php?section=problems">Project Euler Problems</a>, this time with <a href="http://projecteuler.net/index.php?section=problems&#038;id=3">problem three</a>, which asks us to find the &#8220;the largest prime factor of the number 600851475143&#8243;.</p><p>This time I have decided to explain the code a bit more, through comments &#8211; since this problem is a bit more tricky than the previous two problems.</p> <script src="http://gist.github.com/418464.js"></script> <p>Once again, you will need node.js to run the code.</p> ]]></content:encoded> <wfw:commentRss>http://www.clauswitt.com/project-euler-problem-three/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Project Euler Problem One</title><link>http://www.clauswitt.com/project-euler-problem-one/</link> <comments>http://www.clauswitt.com/project-euler-problem-one/#comments</comments> <pubDate>Sat, 29 May 2010 18:55:17 +0000</pubDate> <dc:creator>Claus Witt</dc:creator> <category><![CDATA[Development]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[nodejs]]></category> <category><![CDATA[project euler]]></category><guid isPermaLink="false">http://www.clauswitt.com/?p=365</guid> <description><![CDATA[A long time ago I decided to do a couple of posts about project euler. I find the problems to be great excersize. It was not before I began to look into node.js though, that I began writing code for the problems for the purpose of publishing it. The first problem on the list is [...]]]></description> <content:encoded><![CDATA[<p>A long time ago I decided to do a couple of posts about <a href="http://projecteuler.net/">project euler</a>. I find <a href="http://projecteuler.net/index.php?section=problems">the problems</a> to be great excersize. It was not before I began to look into <a href="http://nodejs.org/">node.js</a> though, that I began writing code for the problems for the purpose of publishing it.</p><p><a href="http://projecteuler.net/index.php?section=problems&#038;id=1">The first problem</a> on the list is very simple. &#8220;Find the sum of all the multiples of 3 or 5 below 1000&#8243;. The solution, then, must be to find all numbers that are multiples of 3 and 5, and then adding those&#8230;</p> <script src="http://gist.github.com/418446.js"></script> <p>This solution is pretty simple. You (probably) need nodejs to run the code.</p> ]]></content:encoded> <wfw:commentRss>http://www.clauswitt.com/project-euler-problem-one/feed/</wfw:commentRss> <slash:comments>2</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>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 5/31 queries in 0.021 seconds using memcached

Served from: www.clauswitt.com @ 2010-07-30 04:37:13 -->