Open Source / Programming

GUID generator in JavaScript

Found two little functions in JavaScript to create a GUID function S4(){ return (((1+Math.random())*0x10000)|0).toString(16).substring(1); } function guid() { return (S4()+S4()+”-“+S4()+”-“+S4()+”-“+S4()+”-“+S4()+S4()+S4()); } Thanks to sj at note19.com, I don’t know exactly how reliable the generator is, I ran a couple tests against 50 guids, and it passed, but I need to run the guids through the … Continue reading

How-to / Open Source / Programming

XUL File I/O: Write Files

Writing files in XUL isn’t that much harder than reading a file, in fact its very similar.  What a relief.  In my example I am appending the data “Appending Data” to my file. function writeFile() { var data = “Appending Data”; var filePath = “C:\\text.txt”; var file = Components.classes[“@mozilla.org/file/local;1”] .createInstance(Components.interfaces.nsILocalFile); var foStream = Components.classes[“@mozilla.org/network/file-output-stream;1”]    … Continue reading