Example #1
0
/**
 * Initializes a Amazon S3 Multi part file upload with the given options
 */
function MultiPartUpload(opts, callback) {
    if (!opts.client || !opts.objectName) {
        throw new Error('MultiPart upload must be created from a client and provide an object name');
    }

    if (!opts.stream && !opts.file) {
        throw new Error('MultiPart upload must be passed either a stream or file parameter');
    }

    if (opts.stream && opts.file) {
        throw new Error('You cannot provide both a stream and a file to upload');
    }

    if (opts.noDisk && opts.partSize && opts.partSize > 10485760) {
        throw new Error('Keep in-memory part sizes 10MB or less');
    }

    callback = callback || function(err, results) {};

    this.objectName = opts.objectName;
    this.fileName = opts.file;
    this.headers = opts.headers || {};
    this.client = opts.client;
    this.partSize = opts.partSize || 5242880; // 5MB default
    this.maxRetries = opts.maxRetries || 0;   // default to no retry
    this.uploadId = null;
    this.uploads = new Batch();
    this.noDisk = opts.noDisk;
    this.maxUploadSize = opts.maxUploadSize || 1/0; // infinity default
    this.currentUploadSize = 0;
    this.aborted = false;
    this.totalUploadSize = 0;

    this.uploads.concurrency(opts.batchSize ||4); // 4 simultaneous uploads by default

    // initialise the tmp directory based on opts (fallback to os.tmpDir())
    this.tmpDir = !this.noDisk && (opts.tmpDir || os.tmpDir());

    var mpu = this,
        written = 0;

    mpu.on('partProgress', function(data) {        
        written += data.written;
        mpu.emit('progress', {
            written: written,
            total: mpu.totalUploadSize,
            percent: written / mpu.totalUploadSize * 100 | 0
        });
    });

    // Recalculate progress as previously written data needs to be rewritten
    mpu.on('failed', function(part, partWritten) {
        written = written - partWritten;
    });

    if (opts.stream) {
        this._putStream(opts.stream, callback);
    } else {
        this._putFile(opts.file, callback);
    }    

}
Example #2
0
var gulp = require('gulp');
var gutil = require('gulp-util');
var shell = require('gulp-shell');
var downloadatomshell = require('gulp-download-atom-shell');
var path = require('path');
var os = require('os');
var fs = require('fs');
var wrench = require('wrench');
var atomGyp, version, gypPath, cloneDir, atomDir, replaceGyp, copyProjectContentSync, isAtomRepoExist, cloneAtomRepo, updateAtomRepo, buildAtom, bootstrapAtom, buildNoBootstrap, repoUrl, checkoutVersion, generateNodeLib, rebuildNativeModules, projectName, productName, frameworkName, renameProjectContent;

projectName = 'testProjectName';
productName = 'TestProductName';
frameworkName = 'Fireball Framework';
version = 'v0.20.1';
cloneDir = os.tmpDir();
atomDir = path.join(cloneDir, 'downloaded-atom-shell-repo');
gypPath = path.join(atomDir, 'atom.gyp');
repoUrl = 'https://github.com/atom/atom-shell';

isAtomRepoExist = function() {
  return fs.existsSync(path.join(atomDir, '.git'));
};

cloneAtomRepo = function(cb) {
  var stream = shell([
    'git clone https://github.com/atom/atom-shell.git downloaded-atom-shell-repo'
  ], {
    cwd: cloneDir
  });

  stream.write(process.stdout);
/*globals jasmine:false, expect:false, describe:false, it:false, beforeEach:false, afterEach:false*/

"use strict";

var fs = require('fs');
var os = require('os');
var path = require('path');

var testDir = path.join(os.tmpDir(), 'asset-middleware-test');
var inDir = path.join(testDir, 'in');
var inSubDir = path.join(inDir, 'sub');
var outDir = path.join(testDir, 'out');
var outFile = path.join(outDir, 'out');

var assetMiddleware = require('./index');

function setup() {
    teardown();

    fs.mkdirSync(testDir);
    fs.mkdirSync(outDir);
    fs.mkdirSync(inDir);
    fs.mkdirSync(inSubDir);
    fs.writeFileSync(path.join(inDir, 'a.js'), 'A', { encoding: 'utf8' });
    fs.writeFileSync(path.join(inDir, 'b.css'), 'B', { encoding: 'utf8' });
    fs.writeFileSync(path.join(inDir, 'c.html'), 'C', { encoding: 'utf8' });
}

function unlinkIfExists(file) {
    fs.existsSync(file) && fs.unlinkSync(file);
}
Example #4
0
		res.on("end", function(){
			fs.writeFileSync(os.tmpDir() + sep + appconfig.tumblr  + "-postcache.json", tumblrCache);
			tumblrCache = JSON.parse(tumblrCache);
			console.log("Data OK");
		});
Example #5
0
	readTorrent(filename, function(err, torrent) {
		if (err) return ready(err);

		peerflix.torrent = torrent;
		var selected = peerflix.selected = (typeof(options.index)=='number') ? torrent.files[options.index] : biggest(torrent);
		var destination = peerflix.destination = options.path || path.join(os.tmpDir(), torrent.infoHash+'.'+selected.offset);
		var storage = peerflix.storage = createStorage(torrent, selected, { destination:destination });
		var server = peerflix.server = createServer(storage, selected, { buffer:options.buffer && numeral().unformat(options.buffer), port: options.port });
		var peers  = peerflix.peers = [];
		var destroyed = false;

		var speed = peerflix.speed = speedometer();
		peerflix.uploaded = 0;
		peerflix.downloaded = 0;
		peerflix.resyncs = 0;

		var have = bitfield(torrent.pieces.length);
		var requesting = {};

		storage.on('readable', function(i) {
			delete requesting[i];
			have.set(i);
			peers.forEach(function(peer) {
				peer.have(i);
			});
		});

		var remove = function(arr, item) {
			if (!arr) return false;
			var i = arr.indexOf(item);
			if (i === -1) return false;
			arr.splice(i, 1);
			return true;
		};
		var calcOffset = function(me) {
			var speed = me.speed();
			var time = MAX_QUEUED * BLOCK_SIZE / (speed || 1);
			var max = storage.missing.length > 60 ? storage.missing.length - 30 : storage.missing.length - 1;
			var data = 0;

			if (speed < MIN_SPEED) return max;

			peers.forEach(function(peer) {
				if (!peer.peerPieces[storage.missing[0]]) return;
				if (peer.peerChoking) return;
				if (me === peer || peer.speed() < speed) return;
				data += peer.speed() * time;
			});

			return Math.min(Math.floor(data / torrent.pieceLength), max);
		};
		var resync = function(offset) {
			var piece = server.position + offset;

			if (!requesting[piece]) return;
			if (storage.missing.length < 10) return;

			requesting[piece].forEach(function(peer) {
				if (peer.speed() > 2*BLOCK_SIZE) return;
				if (calcOffset(peer) <= offset) return;
				while (remove(requesting[piece], peer));
				peer.cancel();
				peerflix.resyncs++;
			});
		};
		var lastResync = 0;
		var resyncAll = function() {
			if (Date.now() - lastResync < 2000) return;
			lastResync = Date.now();
			for (var i = 0; i < 2; i++) {
				resync(i);
			}
		};

		var update = function() {
			peers.sort(function(a,b) {
				return b.downloaded - a.downloaded;
			});

			resyncAll();

			peers.forEach(function(peer) {
				if (peer.peerChoking) return;

				var select = function(force) {
					storage.missing.slice(calcOffset(peer)).some(function(piece) {
						if (peer.requests >= MAX_QUEUED) return true;
						if (!peer.peerPieces[piece]) return;

						var offset = storage.select(piece, force);
						if (offset === -1) return;

						requesting[piece] = requesting[piece] || [];
						requesting[piece].push(peer);

						peer.request(piece, offset, storage.sizeof(piece, offset), function(err, buffer) {
							remove(requesting[piece], peer);
							process.nextTick(update);
							if (err) return storage.deselect(piece, offset);
							storage.write(piece, offset, buffer);
						});
					});
				};

				select();
				if (!peer.requests && storage.missing.length < 30) select(true);
			});
		};

		var onconnection = function(connection, id, address) {
			if (!storage.missing.length) return;

			var protocol = wire();

			connection.pipe(protocol).pipe(connection);

			var ontimeout = connection.destroy.bind(connection);
			var timeout = setTimeout(ontimeout, HANDSHAKE_TIMEOUT);

			protocol.once('handshake', function() {
				clearTimeout(timeout);
				if (destroyed) return;

				peers.push(protocol);

				var onclose = once(function() {
					clearTimeout(timeout);
					peers.splice(peers.indexOf(protocol), 1);
					if (protocol.downloaded) sw.reconnect(address);
					process.nextTick(update);
				});

				connection.on('close', onclose);
				connection.on('error', onclose);
				protocol.once('finish', onclose);

				protocol.on('unchoke', update);
				protocol.on('have', update);

				var onchoketimeout = function() {
					if (peers.length > MIN_PEERS && sw.queued > 2 * (MAX_PEERS - peers.length)) return ontimeout();
					timeout = setTimeout(onchoketimeout, CHOKE_TIMEOUT);
				};

				protocol.on('choke', function() {
					clearTimeout(timeout);
					timeout = setTimeout(onchoketimeout, CHOKE_TIMEOUT);
				});

				protocol.on('unchoke', function() {
					clearTimeout(timeout);
				});

				protocol.once('interested', function() {
					protocol.unchoke();
				});

				timeout = setTimeout(onchoketimeout, CHOKE_TIMEOUT);
				protocol.setKeepAlive();
			});


			protocol.id = id;
			protocol.handshake(torrent.infoHash, PEER_ID);
			protocol.bitfield(have);
			protocol.interested();
			protocol.speed = speedometer();

			protocol.setTimeout(PIECE_TIMEOUT, function() {
				protocol.destroy();
			});

			protocol.on('download', function(bytes) {
				peerflix.downloaded += bytes;
				protocol.speed(bytes);
				speed(bytes);
			});

			protocol.on('upload', function(bytes) {
				peerflix.uploaded += bytes;
			});

			protocol.on('request', storage.read);
		};

		if (options.fastpeers) {
			if (!Array.isArray(options.fastpeers)) options.fastpeers = options.fastpeers.split(',');
			options.fastpeers.forEach(function(peer) {
				var socket = net.connect(peer.split(':')[1], peer.split(':')[0]);
				socket.on('connect', function() {
					onconnection(socket, peer, peer);
				});
				socket.on('error', noop);
			});
		}

		if (options.hasOwnProperty("dht") ? options.dht : true) {
			var sw = peerflix.swarm = peerSwarm(torrent.infoHash, {maxSize:MAX_PEERS});
			sw.on('connection', onconnection);
			sw.listen();
		}

		peerflix.destroy = function() {
			destroyed = true;
			peers.forEach(function(peer) {
				peer.destroy();
			});
			if (!peerflix.swarm) return;
			 // hackish
			peerflix.swarm.maxSize = 0;
			peerflix.swarm.connections.forEach(function(conn) {
				conn.destroy();
			});
			peerflix.swarm._sock.close();
			server.close();
		};

		ready(null, peerflix);
	});
Example #6
0
'use strict';

// A global fixture that creates an Express server that exercises #deet
//

let fs = require('fs');
let Path = require('path');
let os = require('os');
let express = require('express');
let app = express();

let deet = require('../../../lib')({
    validator: 'ajv',
    useMultipartParser : true,
    tempUploadFolder: os.tmpDir(),
    fileFilter : (fileinfo, headers) => { // accept all files
        return true;
    },
    app: app,
    sanitizeURLEncoded : true,
    hidePoweredBy : true,
    hppProtection : true,
    frameguard : 'deny',
    xssFilter : true,
    xssCSP : {
		defaultSrc: ["'unsafe-inline'"],
		scriptSrc: ["*.localhost:2112 'unsafe-inline'"],
		styleSrc: ["'unsafe-inline'"],
		imgSrc: [],
		connectSrc: ["*"],
		fontSrc: [],
Example #7
0
 cors: false,                                // CORS headers
 files: {
     relativeTo: '.'                         // Determines what file and directory handlers use to base relative paths off
 },
 json: {
     replacer: null,
     space: null,
     suffix: null
 },
 payload: {
     failAction: 'error',
     maxBytes: 1024 * 1024,
     output: 'data',
     parse: true,
     timeout: 10 * 1000,                     // Determines how long to wait for receiving client payload. Defaults to 10 seconds
     uploads: Os.tmpDir(),
     defaultContentType: 'application/json'
 },
 response: {
     emptyStatusCode: 200,                   // HTTP status code when payload is empty (200, 204)
     options: {}                             // Joi validation options
 },
 security: false,                            // Security headers on responses: false -> null, true -> defaults, {} -> override defaults
 state: {
     parse: true,                            // Parse content of req.headers.cookie
     failAction: 'error'                     // Action on bad cookie - 'error': return 400, 'log': log and continue, 'ignore': continue
 },
 timeout: {
     socket: undefined,                      // Determines how long before closing request socket. Defaults to node (2 minutes)
     server: false                           // Determines how long to wait for server request processing. Disabled by default
 },
Example #8
0
var fs            = require('fs')
  , path          = require('path')
  , os            = require('os')
  , rimraf        = require('rimraf')
  , exercise      = require('workshopper-exercise')()
  , filecheck     = require('workshopper-exercise/filecheck')
  , execute       = require('workshopper-exercise/execute')
  , comparestdout = require('workshopper-exercise/comparestdout')
  , wrappedexec   = require('workshopper-wrappedexec')
  , boganipsum    = require('boganipsum')

  , testFile      = path.join(os.tmpDir(), '_learnyounode_' + process.pid + '.txt')


// checks that the submission file actually exists
exercise = filecheck(exercise)

// execute the solution and submission in parallel with spawn()
exercise = execute(exercise)

// compare stdout of solution and submission
exercise = comparestdout(exercise)

// wrap up the child process in a phantom wrapper that can
// mess with the global environment and inspect execution
exercise = wrappedexec(exercise)

// a module we want run just prior to the submission in the
// child process
exercise.wrapModule(require.resolve('./wrap'))
app.set('view engine', 'jade');
app.set('views', path.join(__dirname, 'views'));

app.use('/res', express.static(path.join(__dirname, 'res')));

if (path.basename(__dirname) === 'dist') {
  app.use('/js', express.static(path.join(__dirname, 'js')));
  app.use('/less', express.static(path.join(__dirname, 'less')));
} else {
  const browserify = require('browserify-middleware');
  const less = require('less-middleware');
  browserify.settings({
    transform: ['babelify']
  });

  const tempDir = path.join(os.tmpDir(), 'node-mpv-css-cache');
  app.use('/js', browserify(path.join(__dirname, './js')));
  app.use('/less', less(path.join(__dirname, './less'), { dest: tempDir}));
  app.use('/less', express.static(tempDir));
  app.use('/less/fonts', express.static(
    path.join(__dirname, './less/fonts')));
}

app.get('/', (req, res) => res.render('index'));

io.on('connection', socket => handleSocket(socket, robot));

let port = process.env.PORT || 3000;
let ifaces = os.networkInterfaces();
http.listen(port, function() {
  Object.keys(ifaces).forEach(ifname =>
Example #10
0
module.exports = function(app, db) {
    app.set('showStackError', true);

    // Expose development mode to all views
    var isDevelopment = app.locals.isDevelopment = process.env.NODE_ENV === 'development';

    // Compile LESS files to CSS
    var tmpDir = os.tmpDir();
    app.use(less({
        src: __dirname + '/../public/styles',
        dest: tmpDir,
        prefix: '/css',
        compress: true,
        once: !isDevelopment,
        sourceMap: isDevelopment
    }));

    //Should be placed before express.static
    app.use(express.compress({
        filter: function(req, res) {
            return (/json|text|javascript|css/).test(res.getHeader('Content-Type'));
        },
        // Levels are specified in a range of 0 to 9, where-as 0 is
        // no compression and 9 is best compression, but slowest
        level: 9
    }));

    // Only use logger for development environment
    if (process.env.NODE_ENV === 'development') {
        app.use(express.logger('dev'));
    }

    // Set views path, template engine and default layout
    app.set('views', config.root + '/app/views');
    app.engine('.hbs', exphbs({
        layoutsDir: config.root + '/app/views/_layouts',
        partialsDir: config.root + '/app/views/_partials',
        defaultLayout: 'default',
        extname: '.hbs',
        helpers: helpers
    }));
    app.set('view engine', '.hbs');

    // Enable jsonp
    app.enable("jsonp callback");

    app.configure(function() {
        // The cookieParser should be above session
        app.use(express.cookieParser());

        // Request body parsing middleware should be above methodOverride
        app.use(express.urlencoded());
        app.use(express.json());
        app.use(express.methodOverride());

        // Express/Mongo session storage
        app.use(express.session({
            secret: config.sessionSecret,
            store: new mongoStore({
                db: db.connection.db,
                collection: config.sessionCollection
            })
        }));

        // Connect flash for flash messages
        app.use(flash());

        // Routes should be at the last
        app.use(app.router);

        // Setting the fav icon and static folder
        app.use(express.favicon());
        app.use(express.static(config.root + '/public'));
        app.use('/css', express.static(tmpDir));

        // Assume "not found" in the error msgs is a 404. this is somewhat
        // silly, but valid, you can do whatever you like, set properties,
        // use instanceof etc.
        app.use(function(err, req, res, next) {
            // Treat as 404
            if (~err.message.indexOf('not found')) return next();

            // Log it
            console.error(err.stack);

            // Error page
            res.status(500).render('500', {
                error: err.stack
            });
        });

        // Assume 404 since no middleware responded
        app.use(function(req, res, next) {
            res.status(404).render('404', {
                url: req.originalUrl,
                error: 'Not found'
            });
        });

    });
};
Example #11
0
'use strict';

var RegClient = require('silent-npm-registry-client');
var Os = require('os');
var Semver = require('semver');

var options = {
  registry: 'https://registry.npmjs.org/',
  cache: Os.tmpDir() + '/nodesecurity'
};

var client = new RegClient(options);


var getPackageJson = function (module, cb) {

  console.error('The getPackageJson method is deprecated');
  client.get(options.registry + module.name, {}, function (err, pkg) {

    if (err) {
      return cb(err);
    }

    if (pkg.time && pkg.time.unpublished) {
      var error = new Error('404 - Unpublished module');
      error.code = 'E404';
      error.pkgid = module.name;

      return cb(error);
    }
Example #12
0
'use strict';
var fs = require('fs');
var path = require('path');
var os = require('os');
var mkdir = require('mkdirp');
var chalk = require('chalk');
var exec = require('child_process').exec;
var which = require('which');
var tar = require('tar');
var zlib = require('zlib');
var request = require('request').defaults({
	proxy: process.env.http_proxy || process.env.HTTP_PROXY ||
			process.env.https_proxy || process.env.HTTPS_PROXY || ''
});
var progress = require('request-progress');
var tmpdir = os.tmpdir ? os.tmpdir() : os.tmpDir();
var util = module.exports;

util.fetch = function (url, dest, cb) {
	cb = cb || function () {};

	if (!fs.existsSync(path.dirname(dest))) {
		mkdir.sync(path.dirname(dest));
	}

	return progress(request.get(url))
		.on('response', function (resp) {
			var status = resp.statusCode;

			if (status < 200 || status > 300) {
				return cb(new Error('Status code ' + status));
Example #13
0
module.exports = function(grunt) {
  "use strict";

  // Metadata
  var pkg = grunt.file.readJSON("package.json");

  // Make a temp dir for Flash compilation
  var tmpDir = os.tmpdir ? os.tmpdir() : os.tmpDir();
  var flashTmpDir = path.join(tmpDir, "zcflash");

  // Shared configuration
  var localPort = 7320;  // "ZERO"

  // Project configuration.
  grunt.initConfig({
    // Task configuration
    jshint: {
      options: {
        jshintrc: ".jshintrc"
      },
      Gruntfile: ["Gruntfile.js"],
      js: ["src/javascript/ZeroClipboard/**/*.js"],
      test: {
        options: {
          jshintrc: "test/.jshintrc"
        },
        src: ["test/*.js"]
      }
    },
    flexpmd: {
      flash: {
        src: [flashTmpDir]
      }
    },
    clean: {
      dist: ["ZeroClipboard.*"],
      flash: {
        options: {
          // Force is required when trying to clean outside of the project dir
          force: true
        },
        src: [flashTmpDir]
      },
      meta: ["bower.json", "composer.json", "LICENSE"]
    },
    concat: {
      options: {
        stripBanners: true,
        process: {
          data: pkg
        }
      },
      js: {
        src: [
          "src/meta/source-banner.tmpl",
          "src/javascript/start.js",
          "src/javascript/ZeroClipboard/state.js",
          "src/javascript/ZeroClipboard/utils.js",
          "src/javascript/ZeroClipboard/flash.js",
          "src/javascript/ZeroClipboard/client.js",
          "src/javascript/ZeroClipboard/core.js",
          "src/javascript/ZeroClipboard/dom.js",
          "src/javascript/ZeroClipboard/event.js",
          "src/javascript/ZeroClipboard/deprecated.js",
          "src/javascript/end.js"
        ],
        dest: "ZeroClipboard.js"
      },
      flashMain: {
        src: [
          "src/meta/source-banner.tmpl",
          "src/flash/ZeroClipboard.as"
        ],
        dest: path.join(flashTmpDir, "ZeroClipboard.as")
      },
      flashClip: {
        src: [
          "src/meta/source-banner.tmpl",
          "src/flash/ClipboardInjector.as"
        ],
        dest: path.join(flashTmpDir, "ClipboardInjector.as")
      },
      flashJs: {
        src: [
          "src/meta/source-banner.tmpl",
          "src/flash/JsProxy.as"
        ],
        dest: path.join(flashTmpDir, "JsProxy.as")
      },
      flashXss: {
        src: [
          "src/meta/source-banner.tmpl",
          "src/flash/XssUtils.as"
        ],
        dest: path.join(flashTmpDir, "XssUtils.as")
      }
    },
    uglify: {
      options: {
        preserveComments: "some",
        report: "min"
      },
      js: {
        options: {
          beautify: {
            beautify: true,
            // `indent_level` requires jshint -W106
            indent_level: 2
          },
          mangle: false,
          compress: false
        },
        src: ["ZeroClipboard.js"],
        dest: "ZeroClipboard.js"
      },
      minjs: {
        src: ["ZeroClipboard.js"],
        dest: "ZeroClipboard.min.js"
      }
    },
    mxmlc: {
      options: {
        rawConfig: "-target-player=11.0.0 -static-link-runtime-shared-libraries=true"
      },
      swf: {
        files: {
          "ZeroClipboard.swf": ["<%= concat.flashMain.dest %>"]
        }
      }
    },
    template: {
      options: {
        data: pkg
      },
      bower: {
        files: {
          "bower.json": ["src/meta/bower.json.tmpl"]
        }
      },
      composer: {
        files: {
          "composer.json": ["src/meta/composer.json.tmpl"]
        }
      },
      LICENSE: {
        files: {
          "LICENSE": ["src/meta/LICENSE.tmpl"]
        }
      }
    },
    chmod: {
      options: {
        mode: "444"
      },
      dist: ["ZeroClipboard.*"],
      meta: ["bower.json", "composer.json", "LICENSE"]
    },
    connect: {
      server: {
        options: {
          port: localPort
        }
      }
    },
    qunit: {
      file: ["test/**/*.js.html"],
      http: {
        options: {
          urls: grunt.file.expand(["test/**/*.js.html"]).map(function(testPage) {
            return "http://localhost:" + localPort + "/" + testPage + "?noglobals=true";
          })
        }
      }
    },
    watch: {
      options: {
        spawn: false
      },
      Gruntfile: {
        files: "<%= jshint.Gruntfile %>",
        tasks: ["jshint:Gruntfile"]
      },
      js: {
        files: "<%= jshint.js %>",
        tasks: ["jshint:js", "unittest"]
      },
      test: {
        files: "<%= jshint.test %>",
        tasks: ["jshint:test", "unittest"]
      }
    }
  });

  // These plugins provide necessary tasks
  grunt.loadNpmTasks("grunt-contrib-jshint");
  grunt.loadNpmTasks("grunt-flexpmd");
  grunt.loadNpmTasks("grunt-contrib-clean");
  grunt.loadNpmTasks("grunt-contrib-concat");
  grunt.loadNpmTasks("grunt-contrib-uglify");
  grunt.loadNpmTasks("grunt-mxmlc");
  grunt.loadNpmTasks("grunt-template");
  grunt.loadNpmTasks("grunt-chmod");
  grunt.loadNpmTasks("grunt-contrib-connect");
  grunt.loadNpmTasks("grunt-contrib-qunit");
  grunt.loadNpmTasks("grunt-contrib-watch");


  //
  // Task aliases and chains
  //
  grunt.registerTask("prep-flash",   ["clean:flash", "concat:flashMain", "concat:flashClip", "concat:flashJs", "concat:flashXss"]);
  grunt.registerTask("validate",     ["jshint", "prep-flash", "flexpmd"]);
  grunt.registerTask("build",        ["clean", "concat", "uglify", "mxmlc", "template", "chmod"]);
  grunt.registerTask("build-travis", ["clean:dist", "concat", "mxmlc", "chmod:dist"]);
  grunt.registerTask("test",         ["connect", "qunit"]);

  // Default task
  grunt.registerTask("default", ["validate", "build", "test"]);
  // Travis CI task
  grunt.registerTask("travis",  ["validate", "build-travis", "test"]);

};
Example #14
0
var fs            = require('fs')
  , path          = require('path')
  , os            = require('os')
  , exercise      = require('workshopper-exercise')()
  , filecheck     = require('workshopper-exercise/filecheck')
  , execute       = require('workshopper-exercise/execute')
  , comparestdout = require('workshopper-exercise/comparestdout')
  , recorder      = require('workshopper-recorder')
  , wrappedexec   = require('workshopper-wrappedexec')

  , testDataFile  = path.join(__dirname, '../modules_nodecore/fs.md')
  , testFile      = path.join(os.tmpDir(), '_nodeready_' + process.pid + '.txt')


exercise.longCompareOutput = true

exercise = filecheck(exercise)
exercise = recorder(exercise)
exercise = execute(exercise)
exercise = comparestdout(exercise)
exercise = wrappedexec(exercise)

exercise.wrapModule(require.resolve('../modules_nodecore/wrap'))

exercise.addSetup(function (mode, callback) {
  this.submissionArgs.unshift(testFile)
  this.solutionArgs.unshift(testFile)

  fs.readFile(testDataFile, 'utf8', function (err, data) {
    if (err)
      return callback(err)
"use strict";
var babel = require("babel-core");
var fs = require("fs");
var q = require("q");
var path = require("path");
var os = require("os");
var rimraf = require("rimraf");

var tmpDir = path.resolve(os.tmpDir(), "_babel_" + process.pid);

module.exports = function (exercise) {
    exercise.addProcessor(processor);
    exercise.addCleanup(cleanup);

    return exercise;
};

function processor(mode, callback) {
    var exercise = this;

    q.all([
      writeTranspiled(exercise.submission),
      writeTranspiled(exercise.solution)
    ])
    .spread(function (newSubmission, newSolution) {
      exercise.submission = newSubmission;
      exercise.solution = newSolution;
    })
    .nodeify(callback);
}
Example #16
0
var exchangeMetadata = require('./lib/exchange-metadata')
var fileStream = require('./lib/file-stream')

var MAX_REQUESTS = 5
var CHOKE_TIMEOUT = 5000
var REQUEST_TIMEOUT = 30000
var SPEED_THRESHOLD = 3 * piece.BLOCK_LENGTH
var DEFAULT_PORT = 6881

var BAD_PIECE_STRIKES_MAX = 3
var BAD_PIECE_STRIKES_DURATION = 120000 // 2 minutes

var RECHOKE_INTERVAL = 10000
var RECHOKE_OPTIMISTIC_DURATION = 2

var TMP = fs.existsSync('/tmp') ? '/tmp' : os.tmpDir()

var noop = function () {}

var sha1 = function (data) {
  return crypto.createHash('sha1').update(data).digest('hex')
}

var thruthy = function () {
  return true
}

var falsy = function () {
  return false
}
Example #17
0
 return Q().then(function () {
     if (args.device && args.emulator) {
         return Q.reject('Cannot specify "device" and "emulator" options together.');
     }
     var platform =  args.device ? 'device' : 'emulator';
     
     if (platform === 'device')
     {
         // Copy the device framework into the provided path.
         var ipaPath = args.argv.undashed[2];
         if (!ipaPath) {
             throw new Error("You must provide an AEM Mobile .ipa, see `aemm help package`");
         }
         var tempIpaPath = path.join(os.tmpDir(), 'aemm_tmp_ipa');
         
         return FS.exists(tempIpaPath)
         .then( (exists) => {
             if (exists) {
                 return FS.removeTree(tempIpaPath);
             } else {
                 return Q();
             }
         })
         .then( () => {
             return unzip(ipaPath, tempIpaPath);
         })
         .then( () => {
             var appPath = path.join(tempIpaPath, "Payload", "Jupiter.app");
             return replaceFramework(appPath, 'device');
         })
         .then( () => {
             // Zip up the Payload directory
             var deferred = Q.defer();
             shell.cd(tempIpaPath);
             var cmd = "zip -0 -y -r zipped.ipa Payload/";
             events.emit('log', 'zipping Payload directory.');
             shell.exec(cmd, {silent:true}, function(code, stdout, stderr) {
                 if (code != 0) {
                     deferred.reject(stderr);
                 } else {
                     events.emit('results', "zip complete.");
                     deferred.resolve();
                 }
             });
             return deferred.promise;
         })
         .then( () => {
             // Backup the original .ipa
             var origIpaPath = path.join(path.dirname(ipaPath), path.basename(ipaPath,'.ipa') + "-orig.ipa");
             return FS.rename(ipaPath, origIpaPath);
         })
         .then( () => {
             return FS.rename(path.join(tempIpaPath, 'zipped.ipa'), ipaPath);
         });
     } else {
         // Copy the simulator framework into the simulator app.
         return iosApp.getInstalledAppBinaryPath('emulator')
         .then( (appPath) => {
             return replaceFramework(appPath, 'emulator');
         });
     }
 })
Example #18
0
/**
 * Initializes a Amazon S3 Multi part file upload with the given options
 */
function MultiPartUpload(opts, callback) {
    var e;

    if (!opts.client || !opts.objectName) {
      e = new Error('MultiPart upload must be created from a client and provide an object name');
      if (callback) return callback(e);
      throw e;
    }

    if (!opts.stream && !opts.file) {
      e = new Error('MultiPart upload must be passed either a stream or file parameter');
      if (callback) return callback(e);
      throw e;
    }

    if (opts.stream && opts.file) {
      e = new Error('You cannot provide both a stream and a file to upload');
      if (callback) return callback(e);
      throw e;
    }

    if (opts.noDisk && opts.partSize && opts.partSize > 10485760) {
      e = new Error('Keep in-memory part sizes 10MB or less');
      if (callback) return callback(e);
      throw e;
    }

    callback = callback || function(err, results) {};

    this.objectName = encodeSpecialCharacters(opts.objectName);
    this.fileName = opts.file;
    this.headers = opts.headers || {};
    this.client = opts.client;
    this.partSize = opts.partSize || 5242880; // 5MB default
    this.maxRetries = opts.maxRetries || 0;   // default to no retry
    this.uploadId = null;
    this.concurrency = opts.batchSize || 4;
    this.uploads = async.queue(function(task, callback) { task(callback); }, this.concurrency);
    this.noDisk = opts.noDisk;
    this.maxUploadSize = opts.maxUploadSize || 1/0; // infinity default
    this.currentUploadSize = 0;
    this.aborted = false;
    this.totalUploadSize = 0 || opts.totalUploadSize;
    this.fixedUploadSize = opts.totalUploadSize ? true : false;
    this.percentUploaded = 0;

    this.size = 0;
    this.parts = [];

    // initialise the tmp directory based on opts (fallback to os.tmpDir())
    this.tmpDir = !this.noDisk && (opts.tmpDir || os.tmpDir());

    var mpu = this;

    // ensure the tmpdir exists
    // (as well as the entire path leading to it)
    (function ensureTmpDirExists(afterwards){
      if (!mpu.tmpDir) return afterwards();
      fsx.ensureDir(mpu.tmpDir, afterwards);
    })(function(err) {
      if (err) return callback(err);

      // If we're buffering to disk, double the "totalUploadSize" we expect since
      // every byte has to be uploaded twice (once to disk, once to S3)
      if (!mpu.noDisk) {mpu.totalUploadSize *= 2;}

      var written = 0;

      mpu.on('partProgress', function(data) {
          written += data.written;
          var percent = written / mpu.totalUploadSize * 100 | 0;
          mpu.percentUploaded = percent;
          mpu.emit('progress', {
              written: written,
              total: mpu.totalUploadSize,
              percent: mpu.percentUploaded
          });
      });

      // Recalculate progress as previously written data needs to be rewritten
      mpu.on('failed', function(part, partWritten) {
          written = written - partWritten;
      });

      if (opts.stream) {
        mpu._putStream(opts.stream, callback);
      } else {
        mpu._putFile(opts.file, callback);
      }
    });


}
Project.prototype.packageProject = function(dir, includeModules, cb) {

  var fname = os.tmpDir() + '/' + 'modulus-auto-zip-' + uuid.v4() + '.zip';
  var out = fs.createWriteStream(fname);
  var zip = archiver('zip');

  var makeBytesReadable = function(bytes) {
    bytes = parseFloat(bytes);

    var precision, unit, units;
    units = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
    unit = 0;
    while (bytes >= 1024) {
      unit++;
      bytes = bytes / 1024;
      precision = unit > 2 ? 2 : 1;
    }
    return '' + (bytes.toFixed(precision)) + ' ' + units[unit];
  };

  zip.pipe(out);

  var ignore = Ignore({
    path: dir,
    ignoreFiles: ['.modulus-base-ignore', '.modulusignore']
  });

  // Copy the base ignore file to the output so it can be applied.
  fs.writeFileSync(path.join(dir, '.modulus-base-ignore'),
    fs.readFileSync(path.join(__dirname, '.modulus-base-ignore')));

  // Add node_modules to ignore file if user did not want to include it.
  if(!includeModules) {
    fs.appendFileSync(path.join(dir, '.modulus-base-ignore'), '\nnode_modules');
  }

  var pathRegex = new RegExp('^' + dir + '/');

  var zipAdders = [];

  ignore.on('child', function (c) {
    if(c.type === 'File' || c.type === 'SymbolicLink') {

      // Incoming file could be symlink, need to check if it points to something
      // and it points to a file.
      if(fs.existsSync(c.path) && fs.statSync(c.path).isFile()) {

        var filePath = c.path.replace(/\\/g, '/');

        var rel = filePath.replace(pathRegex, '');

        zipAdders.push(function(callback) {
          zip.append(fs.createReadStream(c.path), { name: rel }, callback);
        });
      }
    }
  });

  var error = false;

  ignore.on('error', function(err) {
    error = true;
    fs.unlinkSync(path.join(dir, '.modulus-base-ignore'));
    cb(err, fname);
  });

  ignore.on('close', function() {
    async.series(zipAdders, function(err) {

      if(err) {
        return cb(err);
      }

      zip.finalize(function(err, written) {

        if(err) {
          return cb(err);
        }
      });
    });
  });

  out.on('close', function() {
    var stats = fs.statSync(fname);
    modulus.io.print(makeBytesReadable(stats.size.toString()).data + ' written');

    // Remove the base ignore file.
    fs.unlinkSync(path.join(dir, '.modulus-base-ignore'));

    if(!error) {
      return cb(null, fname);
    }
  });
};
Example #20
0
// `stats` component.
//
"use strict";
var fluid  = fluid || require("infusion");
var gpii   = fluid.registerNamespace("gpii");
fluid.registerNamespace("gpii.ul.imports.eastin.runner");

require("../cacher");
require("../syncer");
require("./transformer");
require("./downloader");
require("./stats");

var os   = require("os");
var path = require("path");
var cacheFile = path.resolve(os.tmpDir(), "eastin.json");

gpii.ul.imports.eastin.runner.checkCache = function (that) {
    fluid.log("Checking for cache file...");

    // If we can, load data from the cache.
    if (gpii.ul.imports.cacher.cacheFileExists(that)) {
        var records = gpii.ul.imports.cacher.loadFromCache(that);
        that.applier.change("rawData", records);
    }
    // Otherwise, download it.
    else {
        that.downloader.download();
    }
};
Example #21
0
app.get("*", function (req, res) {
	tumblrPage({
		"indexPage" : true,
		"posts" : sortPosts(tumblrCache.response.posts)
	}, res);
});
server.listen(3000);

var appconfig = 0;
function load_appconfig(){
	appconfig = JSON.parse(fs.readFileSync(dirName(thefile)+sep+"test.json")+"" );
}
load_appconfig();

if(!fs.existsSync(os.tmpDir() + sep + appconfig.tumblr + "-postcache.json")){
	var http = require("http");
	tumblrCache = "";
	http.get("http://api.tumblr.com/v2/blog/"+appconfig.tumblr+"/posts/?api_key=R6L6HL6PmZT56qubaxqwJjwvf9M7gVA80uCxNNZEvy7q4nkxnw", function(res){
		res.on('data', function (chunk) {
			tumblrCache += chunk;
		});
		res.on("end", function(){
			fs.writeFileSync(os.tmpDir() + sep + appconfig.tumblr  + "-postcache.json", tumblrCache);
			tumblrCache = JSON.parse(tumblrCache);
			console.log("Data OK");
		});
	});
} else{
	tumblrCache = JSON.parse(fs.readFileSync(os.tmpDir() + sep + appconfig.tumblr + "-postcache.json")+"" );
	console.log("Data OK (cached)");
Example #22
0
  'OBJECT_SUFFIX as SUFFIX',
  'CDATA',
  'BDATA'
];
var tpl = 'select %s from _SYS_REPO.ACTIVE_OBJECT ' +
  'where PACKAGE_ID %s ? order by PACKAGE_ID';
var packageId = process.argv[2] || 'sap.hana.xs.ui.*';
var operator = 'like';
if (packageId.indexOf('*') === -1) {
  operator = '=';
} else {
  operator = 'like';
  packageId = packageId.replace(/\*/g, '%');
}
var sql = util.format(tpl, fields.join(','), operator);
var dirname = path.join(os.tmpDir(), '_SYS_REPO');

async.waterfall([connect, prepare, execute, copyRepo], done);

function connect(cb) {
  client.connect(cb);
}

function prepare(cb) {
  client.prepare(sql, cb);
}

function execute(statement, cb) {
  console.time('time');
  statement.execute([packageId], cb);
}
Example #23
0
  'general.autorun': 'true',
  'editor.font-size': '16',
  'editor.theme': 'monokai',
  'editor.wordwrap': 'true',
  'editor.highlight-line': 'true',
  'presentation.font-size': '33',
  'presentation.theme': 'false',
  'presentation.update-type': 'true',
  'presentation.try-secondary-display': 'true',
};

// Will hold path to php binary
let phpPath;

// Will hold tmp dir (for creating files to run)
const tmpDir = os.tmpDir();
const dummyName = 'php-assistant-dummy.php';

// Editor
const editor = ace.edit('editor');
editor.$blockScrolling = Infinity;

/* Startup routine */
$(() => {
  editorUnbind(['cmd+,', 'ctrl+t', 'ctrl+p']);

  if (isMainWindow) {
    updatePhpPath();
  }

  // Set missing settings to default
Example #24
0
File: tag.js Project: nichtich/gr
function discover(req, res, next) {
  var repos = (req.gr.directories ? req.gr.directories : []),
      pathMaxLen = repos.reduce(function(prev, current) {
        return Math.max(prev, current.replace(req.gr.homePath, '~').length + 2);
      }, 0);

  function pad(s, len) {
    return (s.toString().length < len ?
      new Array(len - s.toString().length).join(' ') : '');
  }


  var editor = process.env['GIT_EDITOR'] || process.env['EDITOR'] || 'nano',
      tmpfile = os.tmpDir() + '/gr-repos-tmp.txt',
      gitPaths = findBySubdir(req.gr.homePath, ['.git']),
      append = '';

  // for each git path:
  gitPaths.sort().forEach(function(dir) {
    var tags, humanDir;
    // 1) normalize by taking dirname, changing homePath to ~/ and sorting
    dir = path.dirname(dir);
    humanDir = dir.replace(new RegExp('^' + req.gr.homePath + '/'), '~/')
                  .replace(/ /g, '\\ ');
    // 2) search for matching tags
    tags = req.gr.getTagsByPath(dir);

    // 3) append to the template
    append += humanDir +
              pad(humanDir, pathMaxLen) +
              tags.map(function(s) { return '@' + s; }).join(' ') + '\n';
  });

  // now, write the file
  // and launch the user's editor

  fs.writeFileSync(tmpfile,
    fs.readFileSync(__dirname + '/discover.template.md').toString() + append);

  var task = spawn(editor, [tmpfile], {
    env: process.env,
    stdio: 'inherit'
  });

  function indata(c) {
    task.stdin.write(c);
  }
  function outdata(c) {
    process.stdout.write(c);
  }

  task.on('exit', function(code) {
    // cleanup
    if (code !== 0) {
      console.log('');
      console.log('spawn-task: "' + line + '" exited with nonzero exit code: ' + code);
      // task.emit('error', new Error('Child process exited with nonzero exit code: '+ code));
    }
  });

  task.once('close', function() {
    // now read back the file
    var lines = fs.readFileSync(tmpfile).toString().split('\n');
    applyTags(req, lines);
    if (req.format == 'human') {
      console.log('Tags updated. Run `gr status` or `gr tag list` to see the current state.');
    }
    req.exit();
    return;
  });
}
'use strict';
var path = require('path');
var fs = require('graceful-fs');
var crypto = require('crypto');
var os = require('os');
var osenv = require('osenv');
var EOL = os.EOL;
var _ = require('lodash');
var mkdirp = require('mkdirp');
var yaml = require('js-yaml');

var user = (osenv.user() || generateFakeUser()).replace(/\\/g, '-');
var tmpDir = path.join(os.tmpdir ? os.tmpdir() : os.tmpDir(), user);
var configDir = process.env.XDG_CONFIG_HOME || path.join(osenv.home() || tmpDir, '.config');
var permissionError = 'You don\'t have access to this file.';

function generateFakeUser() {
	var uid = [process.pid, Date.now(), Math.floor(Math.random() * 1000000)].join('-');
	return crypto.createHash('md5').update(uid).digest('hex');
}

function Configstore(id, defaults) {
	this.path = path.join(configDir, 'configstore', id + '.yml');
	this.all = _.extend({}, defaults, this.all);
}

Configstore.prototype = Object.create(Object.prototype, {
	all: {
		get: function () {
			try {
				return yaml.safeLoad(fs.readFileSync(this.path, 'utf8'), {
Example #26
0
var fs            = require('fs')
  , path          = require('path')
  , os            = require('os')
  , exercise      = require('workshopper-exercise')()
  , filecheck     = require('workshopper-exercise/filecheck')
  , execute       = require('workshopper-exercise/execute')
  , comparestdout = require('workshopper-exercise/comparestdout')
  , wrappedexec   = require('workshopper-wrappedexec')
  , after         = require('after')
  , rimraf        = require('rimraf')
  , verify        = require('./verify')
  , files         = require('../filtered_ls/file-list')

  , testDir       = path.join(os.tmpDir(), '_learnyounode_' + process.pid)


// checks that the submission file actually exists
exercise = filecheck(exercise)

// execute the solution and submission in parallel with spawn()
exercise = execute(exercise)

// compare stdout of solution and submission
exercise = comparestdout(exercise)

// wrap up the child process in a phantom wrapper that can
// mess with the global environment and inspect execution
exercise = wrappedexec(exercise)

// modules we want run just prior to the submission in the
// child process
Example #27
0
function getCacheFolder(repoName) {
    return path.join(os.tmpDir(), 'fireball-doc-src', repoName);
}
Example #28
0
CLI.prototype.do_sources = function do_sources(subcmd, opts, args, callback) {
    var self = this;
    if (args.length > 0) {
        callback(new errors.UsageError(
            'unexpected args: ' + args.join(' ')));
        return;
    }
    var nActions = 0;
    if (opts.edit) nActions++;
    if (opts.add) nActions++;
    if (opts.del) nActions++;
    if (nActions > 1) {
        callback(new errors.UsageError(
            'cannot specify more than one of "-a", "-d" and "-e"'));
        return;
    }
    var skipPingCheck = opts.force === true;
    if (opts.edit) {
        var before = self.tool.sources.map(function (s) { return s.url; });
        var beforeText = before.join('\n')
            + '\n\n'
            + '#\n'
            + '# Enter source URLs, on per line.\n'
            + '# Comments beginning with "#" are stripped.\n'
            + '#\n';
        var tmpPath = path.resolve(os.tmpDir(),
            format('imgadm-sources-%s.txt', process.pid));
        fs.writeFileSync(tmpPath, beforeText, 'utf8');

        var vi = spawn('/usr/bin/vi', ['-f', tmpPath], {stdio: 'inherit'});
        vi.on('exit', function (code) {
            if (code) {
                console.warn('Error editing image sources: %s (ignoring)',
                    code);
                callback();
                return;
            }
            var afterText = fs.readFileSync(tmpPath, 'utf8');
            fs.unlinkSync(tmpPath);
            if (afterText === beforeText) {
                console.log('Image sources unchanged');
                callback();
                return;
            }
            var after = afterText.trim().split(/\n/g).filter(function (line) {
                line = line.split('#')[0].trim();
                if (line.length === 0)
                    return false;
                return true;
            });
            if (after.join('\n') === before.join('\n')) {
                console.log('Image sources unchanged');
                callback();
                return;
            }
            self.tool.updateSourceUrls(after, skipPingCheck,
                function (err, changes) {
                    if (err) {
                        callback(err);
                    } else {
                        changes.forEach(function (change) {
                            if (change.type === 'reorder') {
                                console.log('Reordered image sources');
                            } else if (change.type === 'add') {
                                console.log('Added image source "%s"',
                                    change.url);
                            } else if (change.type === 'del') {
                                console.log('Deleted image source "%s"',
                                    change.url);
                            }
                        });
                        callback();
                    }
                });
        });
    } else if (opts.add) {
        this.tool.configAddSource({url: opts.add}, skipPingCheck,
            function (err, changed) {
                if (err) {
                    callback(err);
                } else if (changed) {
                    console.log('Added image source "%s"', opts.add);
                } else {
                    console.log('Already have image source "%s", no change',
                        opts.add);
                }
            }
        );
    } else if (opts.del) {
        this.tool.configDelSourceUrl(opts.del, function (err, changed) {
            if (err) {
                callback(err);
            } else if (changed) {
                console.log('Deleted image source "%s"', opts.del);
            } else {
                console.log('Do not have image source "%s", no change',
                    opts.del);
            }
        });
    } else {
        var sources = this.tool.sources.map(function (s) {
            return s.url;
        });
        if (opts.json) {
            console.log(JSON.stringify(sources, null, 2));
        } else {
            sources.forEach(function (s) {
                console.log(s);
            });
        }
        callback();
    }
};
Example #29
0
Lambda.prototype._codeDirectory = function (program) {
  var epoch_time = +new Date();

  return os.tmpDir() + '/' + program.functionName + '-' + epoch_time;
};
Example #30
0
#!/usr/bin/env node

/**
 * Remove all traces of WebTorrent Desktop from the system (config and temp files).
 * Useful for developers.
 */

var fs = require('fs')
var os = require('os')
var path = require('path')
var rimraf = require('rimraf')

var config = require('../config')
var handlers = require('../main/handlers')

rimraf.sync(config.CONFIG_PATH)

var tmpPath
try {
  tmpPath = path.join(fs.statSync('/tmp') && '/tmp', 'webtorrent')
} catch (err) {
  tmpPath = path.join(os.tmpDir(), 'webtorrent')
}
rimraf.sync(tmpPath)

// Uninstall .torrent file and magnet link handlers
handlers.uninstall()