Permalink
Browse files

[TIDY] file and directory cleanup

  • Loading branch information...
1 parent 6accac9 commit 08feeae24df8c40872373d147486187910ffd662 @coolaj86 committed Jan 23, 2012
View
@@ -7,10 +7,16 @@
;
while (x + 1 != x) {
+ // 10000000
+ if (!(x % 10000000)) {
+ console.log(x);
+ }
+
if (x >= scale) {
console.log(x);
scale *= 10;
}
+
x += 1
}
View
@@ -0,0 +1,3 @@
+What an AMA-AAAAAA-ZING!!! File!
+
+I love this file. It's the most awesomenest everz!!!
View
@@ -0,0 +1 @@
+This is file 1
View
@@ -0,0 +1 @@
+This is file 2
File renamed without changes.

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -1,25 +0,0 @@
-(function (undefined) {
- // npm install ahr
- var request = require('ahr'),
- getter,
- handler,
- timestamp = (new Date()).valueOf();
-
- getter = function () {
- request.get("http://localhost:3000/file.txt").when(handler);
- }
-
- // TODO add oneshot:true to AbstractHttpRequest
- handler = function (err, ahr, data) {
- if (err) {
- console.log(err);
- return;
- }
- var now = (new Date()).valueOf();
- console.log("response in " + (now - timestamp) / 1000.0 + "s");
- timestamp = now;
- getter();
- };
-
- getter();
-}());
View
@@ -1,28 +0,0 @@
-"use strict";
-(function () {
- var connect = require('connect'),
- respondOnFileUpdate = require('./http-inotify-util').respondOnFileUpdate;
-
- function rest(app) {
- app.get('/', function (req, resp) {
- resp.writeHead("200");
- resp.write("<pre>")
- console.log(req);
- resp.write("Hello " + req.socket.remoteAddress + "\n\n");
- resp.write("Visit <a href='file.txt'>file.txt</a> " +
- "and then place content in the file of the same name.\n\n" +
- "The response will not occur until you have written the file");
- resp.write("</pre>");
- resp.end();
- });
-
- // path, filename
- app.get('/file.txt', respondOnFileUpdate('.', ['file.txt']));
- }
-
-
- // accept http requests
- connect.createServer(
- connect.router(rest)
- ).listen('3000');
-}());
View
@@ -1,90 +0,0 @@
-"use strict";
-(function () {
- var inotify = require("inotify-plusplus").create(),
- connect = require("connect");
- fs = require("fs");
-
- // TODO bundle with inotify++
- inotify.watchFiles = function (directive, path, files, options) {
- if ('string' === typeof files) {
- files = [files];
- }
- Object.keys(directive).forEach(function (ioevent) {
- var original_responder = directive[ioevent];
- directive[ioevent] = undefined;
-
- directive[ioevent] = function (ev) {
- console.log(ev);
- files.forEach(function (filename) {
- if (filename !== ev.name) { return };
- original_responder(ev);
- });
- }
- });
- return inotify.watch(directive, path, options);
- };
-
- function pumpToClients(clients, readStream) {
- //console.log("pumpToClients");
- var keys = Object.keys(clients);
-
- keys.forEach(function (ip) {
- var client = clients[ip];
-
- client.resp.writeHead("200");
-
- readStream.on('data', function (data) {
- client.resp.write(data);
- });
-
- readStream.on('end', function () {
- client.resp.end();
- client[ip] = undefined;
- delete client[ip];
- });
- });
- }
-
- function respondOnFileUpdate(path, names) {
- if ('string' === typeof names) {
- names = [names];
- }
- var clients = {};
- //clients.pump = function (stream) {
- // pumpToClients(clients, stream)
- //};
- inotify.watchFiles({
- close_write: function (ev) {
- var file = fs.createReadStream(path + '/' + ev.name);
- //clients.pump(file);
- pumpToClients(clients, file);
- }
- }, path, names);
-
- return function (req, resp) {
- var cid = req.socket.remoteAddress + req.url,
- client,
- now = (new Date()).valueOf(),
- elapsed;
-
- if (client = clients[cid]) {
- // why would a client request before
- client.end();
- //elapsed = now - client.timestamp;
- //return;
- }
-
- client = clients[cid] = {};
-
- client.req = req;
- client.resp = resp;
- client.timestamp = (new Date()).valueOf();
- };
- }
-
- module.exports = {
- respondOnFileUpdate: respondOnFileUpdate,
- pumpToClients: pumpToClients
- };
-
-}());
@@ -1,11 +1,11 @@
{
"author": "AJ ONeal <coolaj86@gmail.com> (http://coolaj86.info)",
- "name": "validate-json",
+ "name": "json-validate",
"description": "A commandline utility test the validity of JSON files",
- "version": "1.0.0",
+ "version": "1.1.0",
"main": "index.js",
"bin": {
- "validate-json": "./index.js"
+ "json-validate": "./index.js"
},
"engines": {
"node": ">= 0.2.0"
@@ -0,0 +1,67 @@
+(function () {
+ "use strict";
+
+ require('bufferjs');
+
+ var http = require('http')
+ , url = require('url')
+ , fs = require('fs')
+ , server;
+
+
+ function cors(req, res, next) {
+ res.setHeader('Access-Control-Allow-Origin', '*');
+ res.setHeader('Access-Control-Allow-Credentials', 'true');
+ res.setHeader('Access-Control-Allow-Methods', 'POST, GET, PUT, DELETE, OPTIONS');
+ res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Accept, X-HTTP-Method-Override, X-Method-Override');
+ next();
+ }
+
+ function jsonp(req, res) {
+ var urlObj = url.parse(req.url, true)
+ , jsonpCallback = urlObj.query.jsonp;
+
+ res.end(jsonpCallback + '(' + JSON.stringify(urlObj.query) + ')');
+ }
+
+ function echoTests(request, response) {
+ }
+
+ function uploadTests(request, response) {
+ response.write("Upload in progress...err... done");
+ fs.writeFileSync('http.body.dat', request.body);
+ response.end();
+ }
+
+ function requestListener(request, response) {
+ var data = [];
+
+ function concat(chunk) {
+ data.push(chunk);
+ }
+
+ function route() {
+ cors(request, response, function () {});
+ if (data.length) {
+ request.body = Buffer.concat(data).toString('utf8');
+ }
+
+ if (request.url.match(/jsonp=/)) {
+ return jsonp(request, response);
+ }
+
+ if (request.url.match('/echo-tests')) {
+ return echoTests(request, response);
+ }
+
+ return uploadTests(request, response);
+ }
+
+ request.on('data', concat);
+ request.on('end', route);
+ }
+
+ server = http.createServer(requestListener);
+ server.listen(9000);
+ console.log('http on 9000');
+}());
@@ -0,0 +1,24 @@
+(function () {
+ "use strict";
+
+ require('bufferjs');
+
+ var net = require('net')
+ , fs = require('fs')
+ , server;
+
+ function acceptClient(client) {
+ var data = [];
+ client.on('data', function (chunk) {
+ data.push(chunk);
+ console.log(chunk.toString('utf8'));
+ });
+ client.on('end', function () {
+ var alldata = Buffer.concat(data);
+ fs.writeFileSync('log.bin', alldata);
+ });
+ }
+
+ server = net.createServer(acceptClient);
+ server.listen(9000);
+}());
File renamed without changes.
View
@@ -0,0 +1,110 @@
+(function () {
+ "use strict";
+
+ var fs = require('fs'),
+ request = require('ahr');
+
+ // https://developer.mozilla.org/en/DOM/Blob
+ function Blob(blob) {
+ var me = this;
+
+ if (!Buffer.isBuffer(blob), contentType) {
+ throw new Exception("Must initialize Blob with a Buffer");
+ }
+ me.size = blob.length;
+ me.type = contentType;
+ me.slice = function (start, length, contentType) {
+ return new Blob(blob.slice(start, length), contentType);
+ };
+
+ // non-standard
+ me.getBuffer = function () {
+ return blob;
+ };
+ }
+
+ // TODO http://ejohn.org/blog/simple-javascript-inheritance/
+ // http://www.w3.org/TR/FileAPI/#dfn-file
+ // https://developer.mozilla.org/en/DOM/File
+ function File(path) {
+ var this = me;
+
+ me.name = '';
+ me.lastModifiedDate = '';
+ }
+
+ function nodeReadDataUrl() {
+ }
+
+ // https://developer.mozilla.org/en/DOM/FileReader
+ function FileReader() {
+ var me = this,
+ emitter = new EventEmitter();
+
+ me.EMPTY = 0;
+ me.LOADING = 1;
+ me.DONE = 2;
+
+
+ emitter.on('end', function (data) {
+ me.readyState = me.LOADING;
+ emitter.emit('onloadstart');
+ emitter.emit('onprogress');
+ // emitter.emit('onerror');
+ emitter.emit('onload', {
+ target: {
+ result: data
+ }
+ });
+ me.readyState = me.DONE;
+ emitter.emit('onloadend');
+ });
+
+
+ me.abort = function () {
+ me.readyState = me.DONE;
+ emitter.emit('onabort');
+ };
+ me.readAsArrayBuffer = function (file) {
+ var data = file.getBuffer();
+ emitter.emit('end', []);
+ };
+ me.readAsBinaryString = function (file) {
+ emitter.emit('end', file.getBuffer());
+ };
+ me.readAsDataURL = function (file) {
+ var dataUrl = "data:";
+ if (file.type) {
+ dataUrl += file.type + ';';
+ }
+ if (/text/i.test(file.type)) {
+ dataUrl += 'charset=utf-8,';
+ } else {
+ dataUrl += 'base64,';
+ }
+ dataUrl += file.getBuffer().toString('base64');
+ emitter.emit('end', dataUrl);
+ };
+ me.readAsText = function (file, encoding) {
+ var data = file.getBuffer();
+ emitter.emit('end', file.getBuffer().toString(encoding || 'utf8'));
+ };
+
+ me.error = undefined;
+ me.readyState = me.EMPTY;
+ me.result = undefined;
+ me.addEventListener = function (on, callback) {
+ emitter.on(on, callback);
+ };
+ }
+
+ // https://developer.mozilla.org/en/DOM/FileList
+ FileList = {
+ create: function(files) {
+ files.item = function(index) {
+ return files[index];
+ }
+ return files;
+ }
+ }
+}());
Oops, something went wrong.

0 comments on commit 08feeae

Please sign in to comment.