Sök
Hjälp?
Behöver ni experthjälp med något programmeringsärende eller vill ni kanske fråga om råd inför en IT-investering? Kontakta mig så ska jag försöka hjälpa er!Nyckelord
Addon Apache Computer CSS Design Development Download Error Firefox Google HOWTO HTML Internet Internet Explorer iPhone JavaScript JeOS Linux Microsoft MSDN MySQL NoScript Open Source Opera Patent Perl php Programmering Recension Roligt rsync Safari Security SEO Server Slow Software SSH Ubuntu Virus Visual Basic VMWare Web Windows Wordpress
Nyheter från New SeedAnnons
Arkiv
- November 2011
- October 2011
- September 2011
- August 2011
- July 2011
- June 2011
- May 2011
- April 2011
- March 2011
- February 2011
- January 2011
- December 2010
- November 2010
- October 2010
- September 2010
- August 2010
- July 2010
- June 2010
- October 2009
- September 2009
- June 2009
- April 2009
- March 2009
- February 2009
- January 2009
- December 2008
- November 2008
- October 2008
- September 2008
- August 2008
- July 2008
Monthly Archives: September 2008
Stop Software Patents day
Marking the three year anniversary of the European Parliaments no to software patents the 24th of September is being made “Stop Software Patents World Day”.
Best programming reference sites
On “Ask Slashdot” the readers recently got to answer which their favourite programming reference sites where for different languages. While most of the gems that where posted are quite well known I thought I’d make a quick summery of all the valuable links posted there.
Most languages have recieved at least one link but it’s interesting to see some obscure languages in there while others are not even listed (Visual Basic? educational languages like SmallTalk? and at the time of this writing no reference to either MSDN or Google Code). It’s a good group of links though, many informative pages here for anyone who uses these languages.
These are all the sites that programmers recommended (who else visits slashdot?) in alphabetical order.
Algol
http://www.algol68.org/
C
http://cprogramming.com/
http://www.acm.uiuc.edu/webmonkeys/book/c_guide/
http://www.devshed.com/
C++
http://www.cplusplus.com/
http://www.devshed.com/
http://www.parashift.com/c++-faq-lite/
http://www.sgi.com/tech/stl/
CSS
http://w3schools.com/css/default.asp
FORTH
http://www.phact.org/e/forth.htm
HTML
http://w3schools.com/html/default.asp
Java
http://java.sun.com/
http://java.sun.com/javase/reference/api.jsp
JavaScript
http://developer.mozilla.org/
http://w3schools.com/js/default.asp
Logo
http://el.media.mit.edu/Logo-foundation/logo/programming.html
LUA
http://lua-users.org/wiki/
http://www.lua.org/
http://www.lua.org/manual/5.1/
Lucid
http://www.haskell.org/haskellwiki/Lucid
Pascal
http://www.freepascal.org/docs-html/ref/ref.html
Perl
http://cpan.org/
http://use.perl.org/
http://www.perl.com/
http://www.perlmonks.org/
PHP
http://php.net/
PL/I
http://www.users.bigpond.com/robin_v/resource.htm
Prolog
http://www.logic.at/prolog/faq/faq.html
Ruby
http://ruby-doc.org/core/
http://api.rubyonrails.org/
Python
http://code.activestate.com/recipes/langs/python/
http://python.org/
Scheme (LISP)
http://srfi.schemers.org/
http://www.schemers.org/Documents/Standards/R5RS/
SNOBOL
http://www.snobol4.org/
TCL
http://en.wikibooks.org/wiki/Programming:Tcl
http://tcl.tk/
Multilanguage
http://c2.com/cgi-bin/wiki
http://www.gotapi.com/html
http://www.quickref.org/
http://www.regular-expressions.info/
http://www.rosettacode.org/wiki/Main_Page
Not purely programming but related
http://en.wikibooks.org/wiki/Main_Page
http://mindprod.com/jgloss/unmainprinciples.html
http://www.google.com/ (!)
Not mentioned links, added by me
Google Code
Visual Basic
SmallTalk
MSDN
Large Hadron Rap
Not exactly software but technical at least so I just have to link it.
So if we do manage to make a black hole and suck us in this is the last remnant of our civilization. It’s a valid contribution.
Using AJAX to asynchronously load slow XML files
More and more I’ve come across situations where I want to use AJAX to download a XML file to use in the interface but know beforhand that the file will take a long time to load. With asyncroneous download of XML files by JavaScript, which is kind of what the buzz word AJAX is all about, you must be carefull not to leave the client in limbo between a useable interface and a locked up screen.
Unfortunately this script only works in Internet Explorer, useful tips of how to port it properly (with the asynchronous property intact) would be highly appreciated.
Here is a simple description of the basic functions needed to perfom a asynchronous download where the user will have the option to abort.
First we need a simple function that download the XML, this is pretty standard and the code is lovingly ripped off from w3school.com.
function loadXml(sUrl){
try{
//Internet Explorer
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
}
catch(e){
try{
//Firefox, Mozilla, Opera, etc.
xmlDoc = document.implementation.createDocument("","",null);
}
catch(e) {
alert(e.message)
}
}
try{
xmlDoc.async = 'true';
xmlDoc.load(sUrl);
}
catch(e) {
alert(e.message)
}
}
This code is pretty straight forward and I assume you allready know of it, if not read the guide over at W3Schools. The only difference in the above code compared to that from the tutorial over at W3Schools is the flag “xmlDoc.async = ‘true’”. This means that the code will continue executing after the load is called without waiting for the load to finish. This will place the status of the xmlDoc variable in a limbo which can be checked with the “readyState” flag.
To check if our file is ready to use we have a test-loop that will check if readyState changes:
function testReadyLoop(){
i++;
if (xmlDoc.readyState == 4){
// the file has completed the download
alert('xmlDoc ready to use! Contents:\n' + xmlDoc.xml);
// TODO: add code here of what to do with the file
}
else{
if (!abortXmlLoad){
// try again in 1 second
setTimeout("testReadyLoop();",1000);
}
else{
// stop loading the xml file
xmlDoc.abort();
alert('Loading of the XML file aborted!');
}
}
}
The incrementation of the variable “i” is just a counter that will be used later and the “abortXmlLoad” is a boolean if the loop should continue or not, these will be explained later. What happens in this function is that it first tests if readyState is 4 which indicates that the file is ready to be used, if this is the case we simple show an alert with the contents of the file, here more intelligent code would be placed. If it’s not ready it checks if it should continue waiting for the file or not, if it should it calls itself in 1 second (1000 ms) otherwise it aborts the loading and simply stops.
To abort a download we need to set the “abortXmlLoad” flag to true, a short function is needed for this:
function abortAsyncXML(){
// set the abort flag to true
abortXmlLoad = true;
}
Now we have all the functions needed for the asynchronous download, a last function is added to tie them all togheter:
function loadAsyncXML(sUrl){
// set abort to false and start download
abortXmlLoad = false;
i = 0;
loadXml(sUrl);
// start loop to check when ready
testReadyLoop();
}
This function first resets the values of “i” and “abortXmlLoad” and then it calls the download and after that starts the loop to test if the download is ready. The file will now download silently in the background and pop an alert when ready unless someone calls “abortAsyncXml” before that happens.
As you may have noticed there are a few global variables I use across the functions that also need to be added to the top of the script:
var xmlDoc; var abortXmlLoad; var i;
To use this script a small form need to be added to the page:
<form>
<input type="button" value="load" onclick="loadAsyncXML('sample.xml');">
<input type="button" value="abort" onclick="abortAsyncXML();">
</form>
This will load the file “sample.xml” and abort if the abort button is pushed. In order to test that the abort button is working you would have to build a slow loading page that simulates long loading time.
I will post a link to the full code and sample later. Hope you found this helpful.
Posted in Guide, Programmering
Tagged abort, AJAX, async, Asynchronously, HOWTO, JavaScript, load, Slow, tutorial, XML, xmldoc
1 Comment
Are you not (yet) against software patents?
Are software patents protecting the inventors and is something needed to protect intelectual property?
Read this: http://news.zdnet.com/2424-9595_22-218626.html
If it designed to be used to protect intelectual property then it is now abused by large companies for making absurd claims, in this case Microsoft.
Makes me want to patent the “O”-button… peple cant write blgs withut it.
