tta.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. console.log("HERE reset on load");
  2. //var http=require("./xdd");
  3. //console.log(http);
  4. /*
  5. MA DE LA PA DA BA
  6. /
  7. /
  8. */
  9. var fs = require("fs");
  10. /*
  11. fs.exists(PATH+"/emsa",function(present){
  12. if(present){
  13. var files = fs.readdirSync(PATH+"/emsa/");
  14. console.log("file:", files);
  15. }else{
  16. console.log("no emsa folder")
  17. }
  18. var files = fs.readdirSync(PATH);
  19. console.log("files:", files);
  20. })
  21. */
  22. var ppath = require("path");
  23. $lib=typeof($lib)==="undefined"?{}:$lib;
  24. function mkbitfield() {
  25. var Container = typeof Buffer !== "undefined" ? Buffer //in node, use buffers
  26. : typeof Int8Array !== "undefined" ? Int8Array //in newer browsers, use webgl int8arrays
  27. : function(l) {
  28. var a = new Array(l);
  29. for (var i = 0; i < l; i++) a[i] = 0;
  30. }; //else, do something similar
  31. function BitField(data, opts) {
  32. if (!(this instanceof BitField)) {
  33. return new BitField(data, opts);
  34. }
  35. if (arguments.length === 0) {
  36. data = 0;
  37. }
  38. this.grow = opts && (isFinite(opts.grow) && getByteSize(opts.grow) || opts.grow) || 0;
  39. if (typeof data === "number" || data === undefined) {
  40. data = new Container(getByteSize(data));
  41. if (data.fill && !data._isBuffer) data.fill(0); // clear node buffers of garbage
  42. }
  43. this.buffer = data;
  44. }
  45. function getByteSize(num) {
  46. var out = num >> 3;
  47. if (num % 8 !== 0) out++;
  48. return out;
  49. }
  50. BitField.prototype.get = function(i) {
  51. var j = i >> 3;
  52. return (j < this.buffer.length) &&
  53. !!(this.buffer[j] & (128 >> (i % 8)));
  54. };
  55. BitField.prototype.set = function(i, b) {
  56. var j = i >> 3;
  57. if (b || arguments.length === 1) {
  58. if (this.buffer.length < j + 1) this._grow(Math.max(j + 1, Math.min(2 * this.buffer.length, this.grow)));
  59. // Set
  60. this.buffer[j] |= 128 >> (i % 8);
  61. } else if (j < this.buffer.length) {
  62. /// Clear
  63. this.buffer[j] &= ~(128 >> (i % 8));
  64. }
  65. };
  66. BitField.prototype._grow = function(length) {
  67. if (this.buffer.length < length && length <= this.grow) {
  68. var newBuffer = new Container(length);
  69. if (newBuffer.fill) newBuffer.fill(0);
  70. if (this.buffer.copy) this.buffer.copy(newBuffer, 0);
  71. else {
  72. for (var i = 0; i < this.buffer.length; i++) {
  73. newBuffer[i] = this.buffer[i];
  74. }
  75. }
  76. this.buffer = newBuffer;
  77. }
  78. };
  79. return BitField
  80. }
  81. var bf=mkbitfield();
  82. var t= bf(512)
  83. console.log(t);
  84. t.set(128,1);
  85. t.set(228,1);
  86. console.log(t);
  87. for(var i=0;i<512;i++){
  88. t.set(i,Math.random()>0.3?1:0)
  89. }
  90. console.log(t);
  91. $lib.deepfind = function deepfind(path, cb) {
  92. var origpath = ppath.resolve(path);
  93. var paths = [origpath];
  94. var crawled = [];
  95. var dons = [];
  96. var index = 0;
  97. function step() {
  98. var pa = paths.shift();
  99. var allfiles = fs.readdirSync(pa).map(function(file) {
  100. var ffa = {
  101. file: file,
  102. stat: null
  103. }
  104. try {
  105. ffa.stat = fs.statSync(pa + "/" + file)
  106. } catch (e) {
  107. ffa.stat = null;
  108. }
  109. return ffa
  110. });
  111. var folders = allfiles.filter(function(file) {
  112. return file.stat && file.stat.isDirectory();
  113. })
  114. var files = allfiles.filter(function(file) {
  115. return file.stat && file.stat.isFile();
  116. })
  117. folders.map(function(file) {
  118. paths.push(ppath.join(pa, file.file))
  119. })
  120. files.map(function(file) {
  121. dons.push(ppath.join(pa, file.file))
  122. })
  123. crawled.push(pa);
  124. if (paths.length) {
  125. setTimeout(step, 20);
  126. } else {
  127. dons = dons.map(function(file) {
  128. return file.replace(origpath, "").substring(1)
  129. });
  130. cb(dons);
  131. }
  132. }
  133. function status() {
  134. return {
  135. paths: paths.length,
  136. files: dons.length,
  137. crawled: crawled.length
  138. }
  139. }
  140. step();
  141. return status;
  142. }
  143. $lib.test = function() {
  144. return $lib.deepfind("./", function(files) {
  145. console.log("..", files.length);
  146. })
  147. }
  148. $lib.tt = $lib.test();
  149. /*
  150. virkelig simple flat fil cms
  151. med tools
  152. export til [ sitea, siteb .. ]
  153. flade filer
  154. bruger opretelse
  155. emsaconfig.json {
  156. endpoints: []
  157. }
  158. emsa/
  159. users/jannick/
  160. autoauth.txt
  161. pages/
  162. page1/
  163. somedatadata
  164. */