<commit_before>#!/usr/bin/env node

'use strict'

var utils = require('./utils'),
    fs = require('fs'),
    path = require('path'),
    esprima = require('esprima'),
    escodegen = require('escodegen'),
    ast = require('./ast'),
    q = require('q'),

    SRC_DIR = path.join( __dirname, 'src' ),
    EXERCISES_DIR = path.join( SRC_DIR, 'exercises' ),
    STARTER_REPO_DIR = path.join( SRC_DIR, 'starter_repo' ),
    REPO_TMP = path.join( STARTER_REPO_DIR, 'template' ),
    REPO_CONTENTS = path.join( STARTER_REPO_DIR, 'contents' ),
    RESOURCES_DIR_NAME = 'resources',

    GEN_DIR = path.join( __dirname, 'exercises' ),
    REPO_DIR_NAME = 'starting.git',
    MACHINES_FILE = path.join( __dirname, 'machines.js' ),
    VIEWERS_FILE = path.join( __dirname, 'viewers.js' ),
    REPOS_FILE = path.join( __dirname, 'repos.js' ),

    ANGLER_URL = 'http://localhost/hooks'

function createNewRepo( repoDir ) {
    var git = utils.git.bind.bind( utils.git, null, repoDir )

    return utils.cp( REPO_CONTENTS, repoDir )
    .then( utils.git.bind( null, __dirname, 'init', [ '--template=' + REPO_TMP, repoDir ] ) )
    .then( git( 'config', [ 'angler.url', ANGLER_URL ] ) )
    .then( git( 'config', [ 'receive.denyCurrentBranch', 'false' ] ) )
    .then( git( 'add', ':/' ) )
}

function createExerciseDir( exercise ) {
    // copy the exercise resources into the output dir
    var resourcesDir = path.join( EXERCISES_DIR, exercise, RESOURCES_DIR_NAME ),
        exerciseName = exercise.substring( exercise.indexOf('-') + 1 ),
        outputDir = path.join( GEN_DIR, exerciseName ),
        repoPath = path.join( outputDir, REPO_DIR_NAME ),

        pending = [
            q.nfcall( fs.stat, resourcesDir )
            .then( utils.cp.bind( null, resourcesDir, outputDir ), function() { /* noop */ } ),
            createNewRepo( repoPath )
        ]

    return q.all( pending )
}

// npm replaces all .gitignores with .npmignores on install. fix this.
function replaceNPMIgnores( src ) {
    return q.nfcall( fs.stat, src )
    .then( function( stats ) {
        if ( stats.isDirectory() ) {
            return q.nfcall( fs.readdir, src )
            .then( function( files ) {
                return q.all( files.map( function( file ) {
                    return replaceNPMIgnores( path.join( src, file ) )
                }) )
            })
        } else if ( path.basename( src ) === '.npmignore' ) {
            return q.nfcall( fs.rename, src, path.join( path.dirname( src ), '.gitignore' ) )
        }
    })
}

replaceNPMIgnores( SRC_DIR )
.then( utils.getExercises )
.done( function( exerciseConfs ) {
    return q.nfcall( fs.mkdir, GEN_DIR )
    .done( function() {
        var exercises = Object.keys( exerciseConfs ),
            orderRe = /^([0-9]+)-/,
            orderedExercises = exercises.filter( function( ex ) {
                    return orderRe.test( ex ) // hide unordered exercises
                }).sort( function( ex1, ex2 ) {
                    var getOrder = function( ex ) { return parseInt( orderRe.exec( ex )[1] ) },
                        ex1Order = getOrder( ex1 ),
                        ex2Order = getOrder( ex2 )
                    return ex1Order < ex2Order ? -1 : 1
                }).map( function( ex ) {
                    return ast.createLiteral( ex.substring( ex.indexOf('-') + 1 ) )
                }),
            machines = [],
            viewers = [ ast.createProperty( '_order', ast.createArray( orderedExercises ) ) ],
            repos = [],
            outputDir

        // split the configs
        exercises.forEach( function( exercise ) {
            var exerciseName = exercise.substring( exercise.indexOf('-') + 1 ),
                exerciseConf = require( exerciseConfs[ exercise ].path ),
                confAst = esprima.parse( exerciseConfs[ exercise ].data ),
                combinedScopeExprs = ast.getCombinedScopeExprs( confAst ),
                confTrees = ast.getConfSubtrees( confAst )

            // make the output directory
            outputDir = path.join( GEN_DIR, exerciseName )
            q.nfcall( fs.mkdir, outputDir )
            .done( createExerciseDir.bind( null, exercise, exerciseConf ) )

            function mkConfSubmodule( confAst ) {
                var submodule = ast.createSubmodule( combinedScopeExprs, confAst )
                return ast.createProperty( exerciseName, submodule )
            }

            machines.push( mkConfSubmodule( confTrees.machine ) )
            viewers.push( mkConfSubmodule( confTrees.viewer ) )
            repos.push( mkConfSubmodule( confTrees.repo || ast.createObject([]) ) )
        })

        function writeMod( file, props ) {
            var mod = ast.createModule( null, ast.createObject( props ) )
            fs.writeFile( file, escodegen.generate( mod ) )
        }

        // write out the split configs
        writeMod( MACHINES_FILE, machines )
        writeMod( VIEWERS_FILE, viewers )
        writeMod( REPOS_FILE, repos )
    })
})
<commit_msg>Added comments to createx<commit_after>#!/usr/bin/env node

'use strict'

var utils = require('./utils'),
    fs = require('fs'),
    path = require('path'),
    esprima = require('esprima'),
    escodegen = require('escodegen'),
    ast = require('./ast'),
    q = require('q'),

    SRC_DIR = path.join( __dirname, 'src' ),
    EXERCISES_DIR = path.join( SRC_DIR, 'exercises' ),
    STARTER_REPO_DIR = path.join( SRC_DIR, 'starter_repo' ),
    REPO_TMP = path.join( STARTER_REPO_DIR, 'template' ),
    REPO_CONTENTS = path.join( STARTER_REPO_DIR, 'contents' ),
    RESOURCES_DIR_NAME = 'resources',

    GEN_DIR = path.join( __dirname, 'exercises' ),
    REPO_DIR_NAME = 'starting.git',
    MACHINES_FILE = path.join( __dirname, 'machines.js' ),
    VIEWERS_FILE = path.join( __dirname, 'viewers.js' ),
    REPOS_FILE = path.join( __dirname, 'repos.js' ),

    ANGLER_URL = 'http://localhost/hooks'

function createNewRepo( repoDir ) {
    var git = utils.git.bind.bind( utils.git, null, repoDir )

    return utils.cp( REPO_CONTENTS, repoDir )
    .then( utils.git.bind( null, __dirname, 'init', [ '--template=' + REPO_TMP, repoDir ] ) )
    .then( git( 'config', [ 'angler.url', ANGLER_URL ] ) )
    .then( git( 'config', [ 'receive.denyCurrentBranch', 'false' ] ) )
    .then( git( 'add', ':/' ) )
}

function createExerciseDir( exercise ) {
    // copy the exercise resources into the output dir
    var resourcesDir = path.join( EXERCISES_DIR, exercise, RESOURCES_DIR_NAME ),
        exerciseName = exercise.substring( exercise.indexOf('-') + 1 ),
        outputDir = path.join( GEN_DIR, exerciseName ),
        repoPath = path.join( outputDir, REPO_DIR_NAME ),

        pending = [
            q.nfcall( fs.stat, resourcesDir )
            .then( utils.cp.bind( null, resourcesDir, outputDir ), function() { /* noop */ } ),
            createNewRepo( repoPath )
        ]

    return q.all( pending )
}

// npm replaces all .gitignores with .npmignores on install. fix this.
function replaceNPMIgnores( src ) {
    return q.nfcall( fs.stat, src )
    .then( function( stats ) {
        if ( stats.isDirectory() ) {
            return q.nfcall( fs.readdir, src )
            .then( function( files ) {
                return q.all( files.map( function( file ) {
                    return replaceNPMIgnores( path.join( src, file ) )
                }) )
            })
        } else if ( path.basename( src ) === '.npmignore' ) {
            return q.nfcall( fs.rename, src, path.join( path.dirname( src ), '.gitignore' ) )
        }
    })
}

replaceNPMIgnores( SRC_DIR )
.then( utils.getExercises )
.done( function( exerciseConfs ) {
    return q.nfcall( fs.mkdir, GEN_DIR )
    .done( function() {
        var exercises = Object.keys( exerciseConfs ),
            orderRe = /^([0-9]+)-/,
            orderedExercises = exercises.filter( function( ex ) {
                    return orderRe.test( ex ) // hide unordered exercises
                }).sort( function( ex1, ex2 ) {
                    var getOrder = function( ex ) { return parseInt( orderRe.exec( ex )[1] ) },
                        ex1Order = getOrder( ex1 ),
                        ex2Order = getOrder( ex2 )
                    return ex1Order < ex2Order ? -1 : 1
                }).map( function( ex ) {
                    return ast.createLiteral( ex.substring( ex.indexOf('-') + 1 ) )
                }),
            machines = [],
            viewers = [ ast.createProperty( '_order', ast.createArray( orderedExercises ) ) ],
            repos = [],
            outputDir,
            writeMod = function( file, props ) {
                // outputs a node module that exports an object of submodules
                var mod = ast.createModule( null, ast.createObject( props ) )
                fs.writeFile( file, escodegen.generate( mod ) )
            }

        // split the configs
        exercises.forEach( function( exercise ) {
            var exerciseName = exercise.substring( exercise.indexOf('-') + 1 ),
                theConf = require( exerciseConfs[ exercise ].path ), // check for syntax errors
                confAst = esprima.parse( exerciseConfs[ exercise ].data ), // config's parse tree
                combinedScopeExprs = ast.getCombinedScopeExprs( confAst ), // defs at top of file
                confTrees = ast.getConfSubtrees( confAst ), // machine, viewer, repo
                mkConfSubmodule = function( confAst ) {
                    /* a submodule takes the following form:
                       function() {
                         var privateVars = 'go here'
                         return publicExport // usually an object
                       }
                     */
                    var submodule = ast.createSubmodule( combinedScopeExprs, confAst )
                    return ast.createProperty( exerciseName, submodule )
                }

            // make the output directory
            outputDir = path.join( GEN_DIR, exerciseName )
            q.nfcall( fs.mkdir, outputDir )
            .done( createExerciseDir.bind( null, exercise ) )

            machines.push( mkConfSubmodule( confTrees.machine ) )
            viewers.push( mkConfSubmodule( confTrees.viewer ) )
            repos.push( mkConfSubmodule( confTrees.repo || ast.createObject([]) ) )
        })

        // write out the split configs
        writeMod( MACHINES_FILE, machines )
        writeMod( VIEWERS_FILE, viewers )
        writeMod( REPOS_FILE, repos )
    })
})
<|endoftext|>


<commit_before>// Thesis - Data Wrangling - To Do:

// • Need to gather countries and remove them in pre-processing
// • Add Dada set into final data via…? needs to be ranked - it has to come in early.
//  	- re-scrape Dada with updated crawler,
//      add that in p-reduce, remove that from the other stuff
//
// -> How does final dataset get made?
// • Continue scrape
//
//-----------------------------------------------------------------------------
//collect.js gets gets pages and runs them through the data pipeline

//  Output data structure:
///    this page's URL                  url        str
///    links from this page             mapsTo     []
///    pages linking to this one        mapsFrom   []
///    metaData from wiki's data page   metaData   {}
///    if object should not be scraped  noscrape   binary (either has attr or does not have it)

// Will need to ID 'influencers' - things that bear an outsize influence on all events of time, such as WWI, and catalogue them
// appropriately / define them as stopping points to keep thesis centered around Dada

// RUN NOTES:
// Wikipedia appears to block IP at some point (unclear what the cutoff is)

var request = require('request');
var fs = require('fs');
var async = require('async');

//local modules
var dataScrape = require('./s-wikiData');
var mF = require('./s-mapsFrom');
var mT = require('./s-mainPage');
var detect = require('./s-detect');

//data
var pagesIn = JSON.parse(fs.readFileSync('Dada-update0.json'));
var pages = [];

// test URLs - 'Francis_Picabia' - 'Ann%C3%A9es_folles' - 'Dada'

// pagesIn[pgI] counter
var pgI = 0;
// array of urls to scrape (this will be a parameter)
var urlArr = pagesIn[pgI].mapsFrom;
// loop start
var i = 0;
// loop endPoint
var endLoop = urlArr.length-1;

var exceptions = [
  'wikisource.org',
  '.jpg',
  '.png',
  '.gif',
  'Book:'
]

var fullSkip = [
  'wikipedia',      // no foriegn pages (not in scope)
  'wiktionary.org', // no wiktionary pages
  'wikiquote',      // no wikiquote pages
  '_talk:',         // no talk pages
  'Draft:'
]

 // Empty Array that is filled with already-scraped items
 // to avoid potentially scraping the same page twice
var dups = [];

// check for exceptions
function skip(link, exc) {
  var fact = false;
  for (var c in exc) {
    if (link.includes(exc[c])) {
      fact = true;
      break;
    }
  }
  return fact;
}

// check for matches
function skipMatch(link, exc) {
  var fact = false;
  for (var c in exc) {
    if (link===exc[c]) {
      fact = true;
      console.log('COLLECT CAUGHT DUP: '+link);
      break;
    }
  }
  return fact;
}

function getRando(min, max) {
  return Math.floor(Math.random() * (max - min) + min);
}

//initialize lastBatch
var lastBatch = 0;

function writeDataFile(counter) {
  counter++;
  if (counter>=endLoop || counter%250==0) { //if last loop or if counter is divisible by 250, write the file
    fs.writeFile('data/MapsFrom-update'+lastBatch+'-'+counter+'.json', JSON.stringify(pages), function(err) {
        if (err) {throw err;}
        console.log('file written');
        lastBatch=counter;
        pages = [];
    });
  }
}

function crawler () {           //  create a loop function
   setTimeout(function () {    //  call a 3s setTimeout when the loop is called

        // check for already scraped urls
        if(!skipMatch(pagesIn[pgI].mapsTo[i], dups)) {

          var page = new Object;
          page.distance = 1;
          page.root = pagesIn[pgI].url; // will need to modify this for next batch?
          page.url =  urlArr[i]; //testURL_1;
          //track already scraped pages
          dups.push(page.url);

          //this scraper only handles english and is not equipped for non-english pages
          var url = 'https://en.wikipedia.org/wiki/'+page.url;
          var mapsFromURL = 'https://en.wikipedia.org/w/index.php?title=Special:WhatLinksHere/'+page.url+'&limit=3000';

          //check for fullSkip (pages not scraping) pages
          if (!skip(page.url, fullSkip)) {

          // collect links pointing at this page
          request(mapsFromURL, function(err, resp, body) {
            if (err) {throw err;}
              console.log('scraping mapsFrom '+mapsFromURL);
              page.mapsFrom = mF.scrape(body);
             //  console.log(page.mapsFrom);
             if (!skip(page.url, exceptions)) {

              // collect links pointing outwards from the page
              request(url, function(err, resp, body) {
                 if (err) {throw err;}
                  console.log('scraping mainPage '+url);
                  var s = mT.scrape(body, url);
                 //  console.log(s);
                  page.mapsTo = s.mapsTo;
                  page.wikiData = s.wikiData;
                  page.image = s.image;
                  page.title = s.title;

                 if (page.wikiData!=undefined) {
                   // collect wikiData (categorical info)
                   request(page.wikiData, function(err, resp, body) {
                      if (err) {throw err;}
                       console.log('scraping wikiData '+page.wikiData);
                       page.metaData = dataScrape.scrape(body);
                       pages.push(page);
                       writeDataFile(i);

                   }); // end wikiData request
                 } else {
                   // case no wikiData
                   page.metaData = null;
                   pages.push(page);
                   writeDataFile(i);
                 }
              }); // end mainPage request

            } else {
              // some urls lead to direct sources, like images and manifesto, that do not have 'mainPage' or 'wikiData' items
              // so just push the page as is
              pages.push(page);
              writeDataFile(i);
            }

          });

        } else {
          page.noScrape = 1;
          pages.push(page);
          console.log('-NO SCRAPE-');
          writeDataFile(i);
        } // end fullSkip conditional

      } // end dups conditional

    //update count and check for end case
    i++;
    if (i < endLoop) { //pagesIn[pgI].mapsTo.length-1
         console.log(i+' of '+ endLoop);
         crawler();
    }

    //set delay between 1200 and 3600 milliseconds per request
  }, getRando(1200,3600))

}
//
crawler();
<commit_msg>iteration count ++<commit_after>// Thesis - Data Wrangling - To Do:

// • Need to gather countries and remove them in pre-processing
// • Add Dada set into final data via…? needs to be ranked - it has to come in early.
//  	- re-scrape Dada with updated crawler,
//      add that in p-reduce, remove that from the other stuff
//
// -> How does final dataset get made?
// • Continue scrape
//
//-----------------------------------------------------------------------------
//collect.js gets gets pages and runs them through the data pipeline

//  Output data structure:
///    this page's URL                  url        str
///    links from this page             mapsTo     []
///    pages linking to this one        mapsFrom   []
///    metaData from wiki's data page   metaData   {}
///    if object should not be scraped  noscrape   binary (either has attr or does not have it)

// Will need to ID 'influencers' - things that bear an outsize influence on all events of time, such as WWI, and catalogue them
// appropriately / define them as stopping points to keep thesis centered around Dada

// RUN NOTES:
// Wikipedia appears to block IP at some point (unclear what the cutoff is)

var request = require('request');
var fs = require('fs');
var async = require('async');

//local modules
var dataScrape = require('./s-wikiData');
var mF = require('./s-mapsFrom');
var mT = require('./s-mainPage');
var detect = require('./s-detect');

//data
var pagesIn = JSON.parse(fs.readFileSync('Dada-update0.json'));
var pages = [];

// test URLs - 'Francis_Picabia' - 'Ann%C3%A9es_folles' - 'Dada'

// pagesIn[pgI] counter
var pgI = 0;
// array of urls to scrape (this will be a parameter)
var urlArr = pagesIn[pgI].mapsFrom;
// loop start
var i = 1000;
// loop endPoint
var endLoop = urlArr.length-1;

var exceptions = [
  'wikisource.org',
  '.jpg',
  '.png',
  '.gif',
  'Book:'
]

var fullSkip = [
  'wikipedia',      // no foriegn pages (not in scope)
  'wiktionary.org', // no wiktionary pages
  'wikiquote',      // no wikiquote pages
  '_talk:',         // no talk pages
  'Draft:'
]

 // Empty Array that is filled with already-scraped items
 // to avoid potentially scraping the same page twice
var dups = [];

// check for exceptions
function skip(link, exc) {
  var fact = false;
  for (var c in exc) {
    if (link.includes(exc[c])) {
      fact = true;
      break;
    }
  }
  return fact;
}

// check for matches
function skipMatch(link, exc) {
  var fact = false;
  for (var c in exc) {
    if (link===exc[c]) {
      fact = true;
      console.log('COLLECT CAUGHT DUP: '+link);
      break;
    }
  }
  return fact;
}

function getRando(min, max) {
  return Math.floor(Math.random() * (max - min) + min);
}

//initialize lastBatch
var lastBatch = 0;

function writeDataFile(counter) {
  counter++;
  if (counter>=endLoop || counter%250==0) { //if last loop or if counter is divisible by 250, write the file
    fs.writeFile('data/MapsFrom-update'+lastBatch+'-'+counter+'.json', JSON.stringify(pages), function(err) {
        if (err) {throw err;}
        console.log('file written');
        lastBatch=counter;
        pages = [];
    });
  }
}

function crawler () {           //  create a loop function
   setTimeout(function () {    //  call a 3s setTimeout when the loop is called

        // check for already scraped urls
        if(!skipMatch(pagesIn[pgI].mapsTo[i], dups)) {

          var page = new Object;
          page.distance = 1;
          page.root = pagesIn[pgI].url; // will need to modify this for next batch?
          page.url =  urlArr[i]; //testURL_1;
          //track already scraped pages
          dups.push(page.url);

          //this scraper only handles english and is not equipped for non-english pages
          var url = 'https://en.wikipedia.org/wiki/'+page.url;
          var mapsFromURL = 'https://en.wikipedia.org/w/index.php?title=Special:WhatLinksHere/'+page.url+'&limit=3000';

          //check for fullSkip (pages not scraping) pages
          if (!skip(page.url, fullSkip)) {

          // collect links pointing at this page
          request(mapsFromURL, function(err, resp, body) {
            if (err) {throw err;}
              console.log('scraping mapsFrom '+mapsFromURL);
              page.mapsFrom = mF.scrape(body);
             //  console.log(page.mapsFrom);
             if (!skip(page.url, exceptions)) {

              // collect links pointing outwards from the page
              request(url, function(err, resp, body) {
                 if (err) {throw err;}
                  console.log('scraping mainPage '+url);
                  var s = mT.scrape(body, url);
                 //  console.log(s);
                  page.mapsTo = s.mapsTo;
                  page.wikiData = s.wikiData;
                  page.image = s.image;
                  page.title = s.title;

                 if (page.wikiData!=undefined) {
                   // collect wikiData (categorical info)
                   request(page.wikiData, function(err, resp, body) {
                      if (err) {throw err;}
                       console.log('scraping wikiData '+page.wikiData);
                       page.metaData = dataScrape.scrape(body);
                       pages.push(page);
                       writeDataFile(i);

                   }); // end wikiData request
                 } else {
                   // case no wikiData
                   page.metaData = null;
                   pages.push(page);
                   writeDataFile(i);
                 }
              }); // end mainPage request

            } else {
              // some urls lead to direct sources, like images and manifesto, that do not have 'mainPage' or 'wikiData' items
              // so just push the page as is
              pages.push(page);
              writeDataFile(i);
            }

          });

        } else {
          page.noScrape = 1;
          pages.push(page);
          console.log('-NO SCRAPE-');
          writeDataFile(i);
        } // end fullSkip conditional

      } // end dups conditional

    //update count and check for end case
    i++;
    if (i < endLoop) { //pagesIn[pgI].mapsTo.length-1
         console.log(i+' of '+ endLoop);
         crawler();
    }

    //set delay between 1200 and 3600 milliseconds per request
  }, getRando(1200,3600))

}
//
crawler();
<|endoftext|>


<commit_before>var webpack = require('webpack');
var path = require('path');

module.exports = {
  entry: {
    'main': './src/index.ts'
  },

  resolve: {
    extensions: ['.ts','.js'],
    modules: [
      path.resolve(__dirname, 'node_modules'),
      // path.resolve(__dirname, 'src'),
    ]
  },

  output: {
    path: path.resolve(__dirname, 'dist'),
    library: 'nvd3-chart',
    libraryTarget: 'umd',
    filename: '[name].js'
  },

  module: {
    rules: [
      {
        test: /\.ts$/,
        use: [
          'awesome-typescript-loader'
        ]
      }
    ]
  },

  plugins: [
    new webpack.ContextReplacementPlugin(
      // The (\\|\/) piece accounts for path separators in *nix and Windows
      /angular(\\|\/)core(\\|\/)src(\\|\/)linker/,
      path.resolve(__dirname, 'src'),
      {
        // your Angular Async Route paths relative to this root directory
      }
    )
  ],

  /*
  * Include polyfills or mocks for various node stuff
  * Description: Node configuration
  *
  * See: https://webpack.github.io/docs/configuration.html#node
  */
  node: {
    global: true,
    crypto: 'empty',
    process: true,
    module: false,
    clearImmediate: false,
    setImmediate: false
  }
};<commit_msg>chore(webpack): change ContextReplacementPlugin path to fix error<commit_after>var webpack = require('webpack');
var path = require('path');

module.exports = {
  entry: {
    'main': './src/index.ts'
  },

  resolve: {
    extensions: ['.ts','.js'],
    modules: [
      path.resolve(__dirname, 'node_modules'),
      // path.resolve(__dirname, 'src'),
    ]
  },

  output: {
    path: path.resolve(__dirname, 'dist'),
    library: 'nvd3-chart',
    libraryTarget: 'umd',
    filename: '[name].js'
  },

  module: {
    rules: [
      {
        test: /\.ts$/,
        use: [
          'awesome-typescript-loader'
        ]
      }
    ]
  },

  plugins: [
    new webpack.ContextReplacementPlugin(
      // The (\\|\/) piece accounts for path separators in *nix and Windows
      /angular(\\|\/)core(\\|\/)@angular/,
      path.resolve(__dirname, 'src'),
      {
        // your Angular Async Route paths relative to this root directory
      }
    )
  ],

  /*
  * Include polyfills or mocks for various node stuff
  * Description: Node configuration
  *
  * See: https://webpack.github.io/docs/configuration.html#node
  */
  node: {
    global: true,
    crypto: 'empty',
    process: true,
    module: false,
    clearImmediate: false,
    setImmediate: false
  }
};<|endoftext|>


<commit_before>// @datatype_void

var helpers = require('./helpers');
// Webpack Plugins
var ProvidePlugin = require('webpack/lib/ProvidePlugin');
var DefinePlugin  = require('webpack/lib/DefinePlugin');
var ENV = process.env.ENV = process.env.NODE_ENV = 'test';

/*
 * Config
 */
module.exports = {
  devtool: 'inline-source-map',
  resolve: {
    extensions: ['', '.ts', '.js', '.scss']
  },
  module: {
    preLoaders: [
      {
        test: /\.ts$/,
        loader: 'tslint-loader',
        exclude: [
          helpers.root('node_modules')
        ]
      },
      {
        test: /\.js$/,
        loader: "source-map-loader",
        exclude: [
          helpers.root('node_modules/rxjs')
        ]
      }
    ],
    loaders: [
      {
        test: /\.ts$/,
        loader: 'awesome-typescript-loader',
        query: {
          "compilerOptions": {
            "removeComments": true,
          }
        },
        exclude: [ /\.e2e\.ts$/, helpers.root('node_modules') ]
      },
      {
        test: /\.json$/,
        loader: 'json-loader',
        exclude: [ helpers.root('src/index.html'), helpers.root('node_modules') ] },
      {
        test: /\.html$/,
        loader: 'raw-loader',
        exclude: [ helpers.root('src/index.html'), helpers.root('node_modules') ] },
      {
        test: /\.css$/,
        loader: 'raw-loader',
        exclude: [ helpers.root('src/index.html'), helpers.root('node_modules') ] },
      {
        test: /\.scss$/,
        loader: 'style!css!autoprefixer-loader?browsers=last 2 versions!sass',
        exclude: [ helpers.root('node_modules') ]
      }
    ],
    postLoaders: [
      // instrument only testing sources with Istanbul
      {
        test: /\.(js|ts)$/,
        include: helpers.root('src'),
        loader: 'istanbul-instrumenter-loader',
        exclude: [
          /\.(e2e|spec)\.ts$/,
          /node_modules/
        ]
      }
    ]
  },
  plugins: [
    new DefinePlugin({
      // Environment helpers
      'ENV': JSON.stringify(ENV),
      'HMR': false
    })
  ],
  node: {
    global: 'window',
    progress: false,
    crypto: 'empty',
    module: false,
    clearImmediate: false,
    setImmediate: false
  },
  tslint: {
    emitErrors: false,
    failOnHint: false,
    resourcePath: 'src',
  }
};
<commit_msg>chore(webpack.test): remove excludes<commit_after>// @datatype_void

var helpers = require('./helpers');
// Webpack Plugins
var ProvidePlugin = require('webpack/lib/ProvidePlugin');
var DefinePlugin  = require('webpack/lib/DefinePlugin');
var ENV = process.env.ENV = process.env.NODE_ENV = 'test';

/*
 * Config
 */
module.exports = {
  devtool: 'inline-source-map',
  resolve: {
    extensions: ['', '.ts', '.js', '.scss']
  },
  module: {
    preLoaders: [
      {
        test: /\.ts$/,
        loader: 'tslint-loader',
        exclude: [
          helpers.root('node_modules')
        ]
      },
      {
        test: /\.js$/,
        loader: "source-map-loader",
        exclude: [
          helpers.root('node_modules/rxjs')
        ]
      }
    ],
    loaders: [
      {
        test: /\.ts$/,
        loader: 'awesome-typescript-loader',
        query: {
          "compilerOptions": {
            "removeComments": true,
          }
        },
        exclude: [ /\.e2e\.ts$/ ]
      },
      {
        test: /\.json$/,
        loader: 'json-loader',
        exclude: [ helpers.root('src/index.html') ] },
      {
        test: /\.html$/,
        loader: 'raw-loader',
        exclude: [ helpers.root('src/index.html') ] },
      {
        test: /\.css$/,
        loader: 'raw-loader',
        exclude: [ helpers.root('src/index.html') ] },
      {
        test: /\.scss$/,
        loader: 'style!css!autoprefixer-loader?browsers=last 2 versions!sass',
        exclude: [ helpers.root('src/index.html') ] },
      }
    ],
    postLoaders: [
      // instrument only testing sources with Istanbul
      {
        test: /\.(js|ts)$/,
        include: helpers.root('src'),
        loader: 'istanbul-instrumenter-loader',
        exclude: [
          /\.(e2e|spec)\.ts$/,
          /node_modules/
        ]
      }
    ]
  },
  plugins: [
    new DefinePlugin({
      // Environment helpers
      'ENV': JSON.stringify(ENV),
      'HMR': false
    })
  ],
  node: {
    global: 'window',
    progress: false,
    crypto: 'empty',
    module: false,
    clearImmediate: false,
    setImmediate: false
  },
  tslint: {
    emitErrors: false,
    failOnHint: false,
    resourcePath: 'src',
  }
};
<|endoftext|>


<commit_before>/**
 * jsonalyzer Python code linting
 *
 * @copyright 2015, Ajax.org B.V.
 * @author Lennart Kats <lennart add c9.io>
 */
define(function(require, exports, module) {

var baseHandler = require("plugins/c9.ide.language/base_handler");
var workerUtil = require("plugins/c9.ide.language/worker_util");

var handler = module.exports = Object.create(baseHandler);
var pythonVersion = "python2";
var pythonPath = "";
var launchCommand;
var ssh;
var PYLINT_OPTIONS = [
    "-d", "all",
    "-e", "E",
    "-e", "F",
    "-e", "W0101", // Unreachable code
    "-e", "W0109", // Duplicate key in dictionary
    "-e", "W0199", // Assert called on a 2-tuple. Did you mean \'assert x,y\'?
    "-e", "W0612", // Unused variable
    "-e", "W0602", // Used global without assignment
    "-r", "n",
    "--msg-template={line}:{column}:\\ [{msg_id}]\\ {msg}"
];

handler.handlesLanguage = function(language) {
    return language === "python";
};

handler.init = function(callback) {
    var emitter = handler.getEmitter();
    emitter.on("set_python_config", function(e) {
        pythonVersion = e.pythonVersion;
        pythonPath = e.pythonPath;
    });
    emitter.on("set_python_scripts", function(e) {
        launchCommand = e.launchCommand;
        ssh = e.ssh;
    });
    callback();
};

handler.analyze = function(docValue, fullAst, options, callback) {
    // Get a copy of pylint. For ssh workspaces we need to use a helper script;
    // in other cases we have the "pylint2" and "pylint3" commands.
    var commands = ssh
        ? ["-c", launchCommand, "--", pythonVersion, "$ENV/bin/pylint"]
        : ["-c", pythonVersion === "python2" ? "pylint2" : "pylint3"];
    commands[commands.length - 1] += " " + PYLINT_OPTIONS.join(" ") + " $FILE";

    var hasStarImports = /from\s+[^\s]+\s+import\s+\*/.test(docValue);
    var markers = [];
    workerUtil.execAnalysis(
        "bash",
        {
            mode: "tempfile",
            args: commands,
            maxCallInterval: 1200,
            env: {
                PYTHONPATH: pythonPath
            }
        },
        function(err, stdout, stderr) {
            if (err && err.code !== 2) return callback(err);

            stdout.split("\n").forEach(function(line) {
                var marker = parseLine(line, hasStarImports);
                marker && markers.push(marker);
            });

            callback(null, markers);
        }
    );
};

function parseLine(line, hasStarImports) {
    var match = line.match(/(\d+):(\d+): \[([^\]]+)\] (.*)/);
    if (!match)
        return;
    var row = match[1];
    var column = match[2];
    var code = match[3];
    var message = match[4];
    var level = getLevel(code);

    if (/print statement used/.test(message))
        return;
    if (hasStarImports && /undefined variable/i.test(message)) {
        level = "info";
        message += "?";
    }

    return {
        pos: {
            sl: parseInt(row, 10) - 1,
            sc: parseInt(column, 10)
        },
        message: message,
        code: code,
        level: level
    };
}

function getLevel(code) {
    if (code[0] === "E" || code[0] === "F")
        return "error";
    if (code === "W0612") // unused variable
        return "info";
    if (code === "W0602") // global without assignment
        return "info";
    return "warning";
}

});<commit_msg>Use a tempfile in cwd for pylint to fix relative imports<commit_after>/**
 * jsonalyzer Python code linting
 *
 * @copyright 2015, Ajax.org B.V.
 * @author Lennart Kats <lennart add c9.io>
 */
define(function(require, exports, module) {

var baseHandler = require("plugins/c9.ide.language/base_handler");
var workerUtil = require("plugins/c9.ide.language/worker_util");

var handler = module.exports = Object.create(baseHandler);
var pythonVersion = "python2";
var pythonPath = "";
var launchCommand;
var ssh;
var PYLINT_OPTIONS = [
    "-d", "all",
    "-e", "E",
    "-e", "F",
    "-e", "W0101", // Unreachable code
    "-e", "W0109", // Duplicate key in dictionary
    "-e", "W0199", // Assert called on a 2-tuple. Did you mean \'assert x,y\'?
    "-e", "W0612", // Unused variable
    "-e", "W0602", // Used global without assignment
    "-r", "n",
    "--msg-template={line}:{column}:\\ [{msg_id}]\\ {msg}"
];

handler.handlesLanguage = function(language) {
    return language === "python";
};

handler.init = function(callback) {
    var emitter = handler.getEmitter();
    emitter.on("set_python_config", function(e) {
        pythonVersion = e.pythonVersion;
        pythonPath = e.pythonPath;
    });
    emitter.on("set_python_scripts", function(e) {
        launchCommand = e.launchCommand;
        ssh = e.ssh;
    });
    callback();
};

handler.analyze = function(docValue, fullAst, options, callback) {
    // Get a copy of pylint. For ssh workspaces we need to use a helper script;
    // in other cases we have the "pylint2" and "pylint3" commands.
    var commands = ssh
        ? ["-c", launchCommand, "--", pythonVersion, "$ENV/bin/pylint"]
        : ["-c", pythonVersion === "python2" ? "pylint2" : "pylint3"];
    commands[commands.length - 1] += " " + PYLINT_OPTIONS.join(" ") + " $FILE";

    var hasStarImports = /from\s+[^\s]+\s+import\s+\*/.test(docValue);
    var markers = [];
    workerUtil.execAnalysis(
        "bash",
        {
            mode: "local-tempfile",
            args: commands,
            maxCallInterval: 1200,
            env: {
                PYTHONPATH: pythonPath
            }
        },
        function(err, stdout, stderr) {
            if (err && err.code !== 2) return callback(err);

            stdout.split("\n").forEach(function(line) {
                var marker = parseLine(line, hasStarImports);
                marker && markers.push(marker);
            });

            callback(null, markers);
        }
    );
};

function parseLine(line, hasStarImports) {
    var match = line.match(/(\d+):(\d+): \[([^\]]+)\] (.*)/);
    if (!match)
        return;
    var row = match[1];
    var column = match[2];
    var code = match[3];
    var message = match[4];
    var level = getLevel(code);

    if (/print statement used/.test(message))
        return;
    if (hasStarImports && /undefined variable/i.test(message)) {
        level = "info";
        message += "?";
    }

    return {
        pos: {
            sl: parseInt(row, 10) - 1,
            sc: parseInt(column, 10)
        },
        message: message,
        code: code,
        level: level
    };
}

function getLevel(code) {
    if (code[0] === "E" || code[0] === "F")
        return "error";
    if (code === "W0612") // unused variable
        return "info";
    if (code === "W0602") // global without assignment
        return "info";
    return "warning";
}

});<|endoftext|>


<commit_before>import webpack from 'webpack'
import _debug from 'debug'

import projectConfig, { paths } from '../config'

const debug = _debug('app:webpack:config:test')
const srcDir = paths('src')
const testDir = paths('test')
const globalStylesDir = paths('globalStyles')
const cssLoader = [
  'css?modules',
  'sourceMap',
  'importLoaders=1',
  'localIdentName=[name]__[local]___[hash:base64:5]'
].join('&')
const {
  __CLIENT__,
  __SERVER__,
  __DEV__,
  __PROD__,
  __DEBUG__
} = projectConfig

debug('Create configuration.')
const config = {
  devtool: 'cheap-module-source-map',
  resolve: {
    root: [srcDir],
    extensions: ['', '.js', '.jsx']
  },
  module: {
    loaders: [
      {
        test: /\.js$/,
        loader: 'babel',
        include: [testDir],
        query: {
          cacheDirectory: true
        }
      },
      {
        test: /\.json$/,
        loader: 'json'
      },
      {
        test: /\.css$/,
        include: [srcDir],
        exclude: [globalStylesDir],
        loaders: [
          'style',
          cssLoader,
          'postcss'
        ]
      },
      {
        test: /common\/styles\/global\/app\.css$/,
        include: [srcDir],
        loaders: [
          'style',
          'css?sourceMap',
          'postcss'
        ]
      },
      {
        test: /\.(woff|woff2|eot|ttf|svg)(\?v=\d+\.\d+\.\d+)?$/,
        loader: 'file?name=fonts/[name].[ext]'
      },
      {
        test: /\.(png|jpe?g|gif|ico|svg)$/,
        loader: 'url?limit=10000'
      }
    ]
  },
  postcss: wPack => ([
    require('postcss-import')({ addDependencyTo: wPack }),
    require('postcss-url')(),
    require('postcss-cssnext')()
  ]),
  plugins: [
    new webpack.DefinePlugin({
      __CLIENT__,
      __SERVER__,
      __DEV__,
      __PROD__,
      __DEBUG__
    })
  ]
}

export default config
<commit_msg>refactor(test.config): update devtool<commit_after>import webpack from 'webpack'
import _debug from 'debug'

import projectConfig, { paths } from '../config'

const debug = _debug('app:webpack:config:test')
const srcDir = paths('src')
const testDir = paths('test')
const globalStylesDir = paths('globalStyles')
const cssLoader = [
  'css?modules',
  'sourceMap',
  'importLoaders=1',
  'localIdentName=[name]__[local]___[hash:base64:5]'
].join('&')
const {
  __CLIENT__,
  __SERVER__,
  __DEV__,
  __PROD__,
  __DEBUG__
} = projectConfig

debug('Create configuration.')
const config = {
  devtool: 'inline-source-map',
  resolve: {
    root: [srcDir],
    extensions: ['', '.js', '.jsx']
  },
  module: {
    loaders: [
      {
        test: /\.js$/,
        loader: 'babel',
        include: [testDir],
        query: {
          cacheDirectory: true
        }
      },
      {
        test: /\.json$/,
        loader: 'json'
      },
      {
        test: /\.css$/,
        include: [srcDir],
        exclude: [globalStylesDir],
        loaders: [
          'style',
          cssLoader,
          'postcss'
        ]
      },
      {
        test: /common\/styles\/global\/app\.css$/,
        include: [srcDir],
        loaders: [
          'style',
          'css?sourceMap',
          'postcss'
        ]
      },
      {
        test: /\.(woff|woff2|eot|ttf|svg)(\?v=\d+\.\d+\.\d+)?$/,
        loader: 'file?name=fonts/[name].[ext]'
      },
      {
        test: /\.(png|jpe?g|gif|ico|svg)$/,
        loader: 'url?limit=10000'
      }
    ]
  },
  postcss: wPack => ([
    require('postcss-import')({ addDependencyTo: wPack }),
    require('postcss-url')(),
    require('postcss-cssnext')()
  ]),
  plugins: [
    new webpack.DefinePlugin({
      __CLIENT__,
      __SERVER__,
      __DEV__,
      __PROD__,
      __DEBUG__
    })
  ]
}

export default config
<|endoftext|>


<commit_before>var send = require( CONFIG.root + "/core/send.js" ).send,
    getModule = require( CONFIG.root + "/db/queries.js" ).getUsersModule,
    modules = new ( require( "node-static" ).Server )( CONFIG.root + "/modules" );

//browser modules
this.getModule = function( link ) {

    if (link.path && typeof link.path[2] != "undefined") {

        var module = link.path[2].replace( /[^0-9a-z_\-]/gi, "" );

        if (module != "") {

            getModule(module, link.session.uid, function(err, res) {

                if (err || !res.module) {

                    send.notfound(link.res);
                }
                else {

                    link.req.url = res.module + (res.dir || "") + "/" + link.path.slice(3).join("/").replace(/[^a-z0-9\/\.\-_]|\.\.\//gi, "");

                    modules.serve(link.req, link.res);
                }
            });
        }
        else {

            send.badrequest(link.res);
        }
    }
    else {

        send.badrequest(link.res);
    }
};<commit_msg>minor change<commit_after>var send = require( CONFIG.root + "/core/send.js" ).send,
    getModule = require( CONFIG.root + "/db/queries.js" ).getUsersModule,
    modules = new ( require( "node-static" ).Server )( CONFIG.root + "/modules" );

//browser modules
this.getModule = function( link ) {

    if (link.path && typeof link.path[2] != "undefined") {

        var module = link.path[2].replace(/[^0-9a-z_\-]/gi, "");

        if (module != "") {

            getModule(module, link.session.uid, function(err, res) {

                if (err || !res.module) {

                    send.notfound(link.res);
                }
                else {

                    link.req.url = res.module + (res.dir || "") + "/" + link.path.slice(3).join("/").replace(/[^a-z0-9\/\.\-_]|\.\.\//gi, "");

                    modules.serve(link.req, link.res);
                }
            });
        }
        else {

            send.badrequest(link.res);
        }
    }
    else {

        send.badrequest(link.res);
    }
};<|endoftext|>


<commit_before>/**
 *  Dev Webpack Configuration
 */

const path = require('path');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');

module.exports = {
  // This is the base directory for resolving entry, loaders etc.
  context: path.resolve(process.cwd(), 'app/'),
  // Here is where the application starts executing and webpack starts bundling
  // [name] will be swoleciety
  entry: {
    swoleciety: './app.js',
  },
  // Where to output your bundle
  output: {
    // Name of the output bundle
    filename: 'bundle.js',
    // Where the bundle will be written to
    path: path.resolve(process.cwd(), 'build'),
    // The public URL of the output directory when referenced in the browser.
    // Relative paths are relative to the html page
    // Use this path when trying to load an asset/
    // i.e background-image: url(/build/sample.png)
    publicPath: 'build/',
    library: 'Swoleciety',
    libraryTarget: 'umd',
  },
  // webpack-dev-server serves the output files from public path listed above
  devServer: {
    // Port number to listen for requests
    port: 4000,
    host: 'localhost',
    // Enables gzip compression
    compress: true,
    // This is where the server should send content from
    contentBase: path.resolve(process.cwd(), './app'),
    // Although the output bundle is written to the build directory
    // We want to tell webpack where to host the generated bundle
    // on the server.
    publicPath: '/public/assets/',
  },
  // Creates a simple source map
  devtool: 'cheap-eval-source-map',
  resolve: {
    extensions: ['.js', '.jsx'],
  },
  performance: {
    // Shows warning message if assets too large
    hints: 'warning',
  },
  // Don;t bundle these modules. Request them at runtime
  // by adding script tag in html file
  externals: {
    react: {
      root: 'React',
      commonjs2: 'react',
      commonjs: 'react',
      amd: 'react',
    },
    'react-dom': {
      root: 'ReactDOM',
      commonjs2: 'react-dom',
      commonjs: 'react-dom',
      amd: 'react-dom',
    },
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        loader: 'babel-loader',
        exclude: /node_modules/,
        options: {
          presets: ['babel-preset-es2015', 'babel-preset-react'],
        },
      },
      {
        test: /\.html$/,
        loader: 'html-loader',
        exclude: /node_modules/,
      },
      {
        test: /\.scss$/,
        use: [
          {
            loader: 'style-loader', // Create Style node from JS strings
          },
          {
            loader: 'css-loader', // Translate CSS into CommmonJS
          },
          {
            loader: 'sass-loader', // Compile to Sass to CSS
          },
        ],
      },
      {
        test: /\.json$/,
        loader: 'json-loader',
        exclude: /node_modules/,
      },
    ],
  },
  plugins: [
    new UglifyJSPlugin(),
  ],
};
<commit_msg>Updated webpack dev server<commit_after>/**
 *  Dev Webpack Configuration
 */

const path = require('path');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');

module.exports = {
  // This is the base directory for resolving entry, loaders etc.
  context: path.resolve(process.cwd(), 'app/'),
  // Here is where the application starts executing and webpack starts bundling
  // [name] will be swoleciety
  entry: {
    swoleciety: './app.js',
  },
  // Where to output your bundle
  output: {
    // Name of the output bundle
    filename: 'bundle.js',
    // Where the bundle will be written to
    path: path.resolve(process.cwd(), 'build'),
    // The public URL of the output directory when referenced in the browser.
    // Relative paths are relative to the html page
    // Use this path when trying to load an asset/
    // i.e background-image: url(/build/sample.png)
    publicPath: 'build/',
    library: 'Swoleciety',
    libraryTarget: 'umd',
  },
  // webpack-dev-server serves the output files from public path listed above
  devServer: {
    // Port number to listen for requests
    port: 4000,
    host: '0.0.0.0',
    // Enables gzip compression
    compress: true,
    // This is where the server should send content from
    contentBase: path.resolve(process.cwd(), './app'),
    // Although the output bundle is written to the build directory
    // We want to tell webpack where to host the generated bundle
    // on the server.
    publicPath: '/public/assets/',
  },
  // Creates a simple source map
  devtool: 'cheap-eval-source-map',
  resolve: {
    extensions: ['.js', '.jsx'],
  },
  performance: {
    // Shows warning message if assets too large
    hints: 'warning',
  },
  // Don;t bundle these modules. Request them at runtime
  // by adding script tag in html file
  externals: {
    react: {
      root: 'React',
      commonjs2: 'react',
      commonjs: 'react',
      amd: 'react',
    },
    'react-dom': {
      root: 'ReactDOM',
      commonjs2: 'react-dom',
      commonjs: 'react-dom',
      amd: 'react-dom',
    },
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        loader: 'babel-loader',
        exclude: /node_modules/,
        options: {
          presets: ['babel-preset-es2015', 'babel-preset-react'],
        },
      },
      {
        test: /\.html$/,
        loader: 'html-loader',
        exclude: /node_modules/,
      },
      {
        test: /\.scss$/,
        use: [
          {
            loader: 'style-loader', // Create Style node from JS strings
          },
          {
            loader: 'css-loader', // Translate CSS into CommmonJS
          },
          {
            loader: 'sass-loader', // Compile to Sass to CSS
          },
        ],
      },
      {
        test: /\.json$/,
        loader: 'json-loader',
        exclude: /node_modules/,
      },
    ],
  },
  plugins: [
    new UglifyJSPlugin(),
  ],
};
<|endoftext|>


<commit_before>var stringify     = require("querystring").stringify,
		hmac          = require("crypto").createHmac,
		request       = require("request"),
		publicMethods = ['marketdata','marketdatav2','orderdata','orderdatav2','singleorderdata','singlemarketdata'];

function CryptsyClient(key, secret) {
	var self    = this;
	self.key    = key;
	self.secret = secret;
	self.jar    = request.jar();

	function api_query(method, callback, args)
	{
		var args_tmp = {};

		for(var i in args) {
			if(args[i]) {
				args_tmp[i] = args[i];
			}
		}

		args = args_tmp;

		var options = {
			uri     : 'https://api.cryptsy.com/api',
			agent   : false,
			method  : 'POST',
			jar     : self.jar,
			headers : {
				"User-Agent": "Mozilla/4.0 (compatible; Cryptsy API node client)",
				"Content-type": "application/x-www-form-urlencoded"
			}
		};

		args.method = method;

		if(publicMethods.indexOf(method) > -1)
		{
			options.method = 'GET';
			options.uri    = 'http://pubapi.cryptsy.com/api.php?' + stringify(args);
		}
		else
		{
			if (!self.key || !self.secret) {
				throw new Error("Must provide key and secret to make this API request.");
			}
			else
			{
				args.nonce = new Date().getTime();

				var message        = stringify(args);
				var signed_message = new hmac("sha512", self.secret);

				signed_message.update(message);

				options.headers.Key  = self.key;
				options.headers.Sign = signed_message.digest('hex');
				options.body         = message;
			}
		}
		request(options, function(err, res, body) {
			var error = null;

			if(!body || !res || res.statusCode != 200) {
				error = "Error in server response.";

				setTimeout(function() {
					api_query(method, callback, args);
				}, 500);
			}
			else {
				var response = JSON.parse(body);

				if(response.error) {
					error = response.error;
				}
			}

			if(typeof callback === 'function') {
				if(error) {
					callback.call(this, error, null);
				}
				else {
					callback.call(this, null, response.return);
				}
			}
		});
	}

	// This function gets the market id for a market in the format 'LTCBTC'
	self.getmarketid = function(marketname, callback) {
		if(typeof callback !== 'function') {
			throw new Error("'callback' argument must be a function.");
		}

		if(!self.markets || !Object.keys(self.markets).length) {
			self.getmarkets(function(error, markets) {
				callback.call(this, error, markets[marketname]);
			});
		}
		else {
			callback.call(this, null, self.markets[marketname]);
		}
	};

	// Old API method
	self.marketdata = function(callback) {
		api_query('marketdata', callback);
	}

	// New API method
	self.marketdatav2 = function(callback) {
		api_query('marketdatav2', callback);
	}

	self.singlemarketdata = function(marketid, callback) {
		api_query('singlemarketdata', callback, { marketid: marketid });
	}

	self.orderdata = function(callback) {
		api_query('orderdata', callback);
	}

	self.orderdatav2 = function(callback) {
		api_query('orderdatav2', callback);
	}

	self.singleorderdata = function(marketid, callback) {
		api_query('singleorderdata', callback, { marketid: marketid });
	}

	self.getinfo = function(callback) {
		api_query("getinfo", callback);
	}

	self.getmarkets = function(callback) {
		callback2 = function(error, markets) {
			self.markets = {};
			for(var i in markets)
			{
				var primary   = markets[i].primary_currency_code;
				var secondary = markets[i].secondary_currency_code;

				self.markets[primary + secondary] = markets[i].marketid;
			}
			callback(error, self.markets);
		}
		api_query('getmarkets', callback2);
	}

	self.mytransactions = function(callback) {
		api_query('mytransactions', callback);
	}

	self.markettrades = function(marketid, callback) {
		api_query('markettrades', callback, { marketid: marketid });
	}

	self.marketorders = function(marketid, callback) {
		api_query('marketorders', callback, { marketid: marketid });
	}

	self.mytrades = function(marketid, limit, callback) {
		api_query('mytrades', callback, { marketid: marketid, limit: limit })
	}

	self.allmytrades = function(callback) {
		api_query('allmytrades', callback);
	}

	self.allmytradesdaterange = function(dates, callback) {
		api_query('allmytrades', callback, { startdate: dates.startdate, enddate: dates.enddate });
	}

	self.myorders = function(marketid, callback) {
		api_query('myorders', callback, { marketid: marketid });
	}

	self.depth = function(marketid, callback) {
		api_query('depth', callback, { marketid: marketid });
	}

	self.allmyorders = function(callback) {
		api_query('allmyorders', callback);
	}

	self.createorder = function(marketid, ordertype, quantity, price, callback) {
		api_query('createorder', callback, { marketid: marketid, ordertype: ordertype, quantity: quantity, price: price });
	}

	self.cancelorder = function(orderid, callback) {
		api_query('cancelorder', callback, { orderid: orderid });
	}

	self.cancelmarketorders = function(marketid, callback) {
		api_query('cancelmarketorders', callback, { marketid: marketid });
	}

	self.calculatefees = function(ordertype, quantity, price, callback) {
		api_query('calculatefees', callback, { ordertype: ordertype, quantity: quantity, price: price });
	}

	self.mytransfers = function(callback) {
		api_query('mytransfers', callback);
	}

	self.getwalletstatus = function(callback) {
		api_query('getwalletstatus', callback);
	}

	self.makewithdrawal = function(address, amount, callback) {
		api_query('makewithdrawal', callback, { address: address, amount: amount });
	}
}

module.exports = CryptsyClient;
<commit_msg>made requeue optional, fixed duplicate callback calls<commit_after>var stringify     = require("querystring").stringify,
		hmac          = require("crypto").createHmac,
		request       = require("request"),
		publicMethods = ['marketdata','marketdatav2','orderdata','orderdatav2','singleorderdata','singlemarketdata'];

function CryptsyClient(key, secret, requeue) {
	var self    = this;

	self.key     = key;
	self.secret  = secret;
	self.jar     = request.jar();
	self.requeue = requeue || false;

	function api_query(method, callback, args)
	{
		var args_tmp = {};

		for(var i in args) {
			if(args[i]) {
				args_tmp[i] = args[i];
			}
		}

		args = args_tmp;

		var options = {
			uri     : 'https://api.cryptsy.com/api',
			agent   : false,
			method  : 'POST',
			jar     : self.jar,
			headers : {
				"User-Agent": "Mozilla/4.0 (compatible; Cryptsy API node client)",
				"Content-type": "application/x-www-form-urlencoded"
			}
		};

		args.method = method;

		if(publicMethods.indexOf(method) > -1)
		{
			options.method = 'GET';
			options.uri    = 'http://pubapi.cryptsy.com/api.php?' + stringify(args);
		}
		else
		{
			if (!self.key || !self.secret) {
				throw new Error("Must provide key and secret to make this API request.");
			}
			else
			{
				args.nonce = new Date().getTime();

				var message        = stringify(args);
				var signed_message = new hmac("sha512", self.secret);

				signed_message.update(message);

				options.headers.Key  = self.key;
				options.headers.Sign = signed_message.digest('hex');
				options.body         = message;
			}
		}
		request(options, function(err, res, body) {
			if(!body || !res || res.statusCode != 200) {
				error = "Error in server response.";

				if(requeue) {
					setTimeout(function() {
						api_query(method, callback, args);
					}, 500);
				}
			}
			else {
				var error  = null;
				var result = null;

				try {
					var response = JSON.parse(body);

					if(response.error) {
						error = response.error;
					}
					else {
						result = response.return || response;
					}
				}
				catch(e) {
					error = "Error parsing server response: " + e.message;
				}

				if(typeof callback === 'function') {
					callback.call(this, error, result);
				}
			}
		});
	}

	// This function gets the market id for a market in the format 'LTCBTC'
	self.getmarketid = function(marketname, callback) {
		if(typeof callback !== 'function') {
			throw new Error("'callback' argument must be a function.");
		}

		if(!self.markets || !Object.keys(self.markets).length) {
			self.getmarkets(function(error, markets) {
				callback.call(this, error, markets[marketname]);
			});
		}
		else {
			callback.call(this, null, self.markets[marketname]);
		}
	};

	// Old API method
	self.marketdata = function(callback) {
		api_query('marketdata', callback);
	}

	// New API method
	self.marketdatav2 = function(callback) {
		api_query('marketdatav2', callback);
	}

	self.singlemarketdata = function(marketid, callback) {
		api_query('singlemarketdata', callback, { marketid: marketid });
	}

	self.orderdata = function(callback) {
		api_query('orderdata', callback);
	}

	self.orderdatav2 = function(callback) {
		api_query('orderdatav2', callback);
	}

	self.singleorderdata = function(marketid, callback) {
		api_query('singleorderdata', callback, { marketid: marketid });
	}

	self.getinfo = function(callback) {
		api_query("getinfo", callback);
	}

	self.getmarkets = function(callback) {
		callback2 = function(error, markets) {
			self.markets = {};
			for(var i in markets)
			{
				var primary   = markets[i].primary_currency_code;
				var secondary = markets[i].secondary_currency_code;

				self.markets[primary + secondary] = markets[i].marketid;
			}
			callback(error, self.markets);
		}
		api_query('getmarkets', callback2);
	}

	self.mytransactions = function(callback) {
		api_query('mytransactions', callback);
	}

	self.markettrades = function(marketid, callback) {
		api_query('markettrades', callback, { marketid: marketid });
	}

	self.marketorders = function(marketid, callback) {
		api_query('marketorders', callback, { marketid: marketid });
	}

	self.mytrades = function(marketid, limit, callback) {
		api_query('mytrades', callback, { marketid: marketid, limit: limit })
	}

	self.allmytrades = function(callback) {
		api_query('allmytrades', callback);
	}

	self.allmytradesdaterange = function(dates, callback) {
		api_query('allmytrades', callback, { startdate: dates.startdate, enddate: dates.enddate });
	}

	self.myorders = function(marketid, callback) {
		api_query('myorders', callback, { marketid: marketid });
	}

	self.depth = function(marketid, callback) {
		api_query('depth', callback, { marketid: marketid });
	}

	self.allmyorders = function(callback) {
		api_query('allmyorders', callback);
	}

	self.createorder = function(marketid, ordertype, quantity, price, callback) {
		api_query('createorder', callback, { marketid: marketid, ordertype: ordertype, quantity: quantity, price: price });
	}

	self.cancelorder = function(orderid, callback) {
		api_query('cancelorder', callback, { orderid: orderid });
	}

	self.cancelmarketorders = function(marketid, callback) {
		api_query('cancelmarketorders', callback, { marketid: marketid });
	}

	self.calculatefees = function(ordertype, quantity, price, callback) {
		api_query('calculatefees', callback, { ordertype: ordertype, quantity: quantity, price: price });
	}

	self.mytransfers = function(callback) {
		api_query('mytransfers', callback);
	}

	self.getwalletstatus = function(callback) {
		api_query('getwalletstatus', callback);
	}

	self.makewithdrawal = function(address, amount, callback) {
		api_query('makewithdrawal', callback, { address: address, amount: amount });
	}
}

module.exports = CryptsyClient;
<|endoftext|>


<commit_before>/**
 * Copyright (c) 2017-present, Facebook, Inc.
 * All rights reserved.
 *
 * This source code is licensed under the BSD-style license found in the
 * LICENSE file in the root directory of this source tree. An additional grant
 * of patent rights can be found in the PATENTS file in the same directory.
 */

const React = require("react");

const highlighterCode = `
function fn() {
  Array.prototype.forEach.call(
    document.querySelectorAll("pre"),
    hljs.highlightBlock
  );
};
if (document.attachEvent ? document.readyState === "complete" : document.readyState !== "loading"){
  fn();
} else {
  document.addEventListener('DOMContentLoaded', fn);
}
`;

class Footer extends React.Component {
  render() {
    return (

    );
    const currentYear = new Date().getFullYear();
    return (

Docs

              Getting Started

              Examples

              FAQ

Community

              Discord

              Twitter

              Stack Overflow

More

            Blog
            GitHub

    );
  }
}

module.exports = Footer;
<commit_msg>[Docs] clean up footer<commit_after>/**
 * Copyright (c) 2017-present, Facebook, Inc.
 * All rights reserved.
 *
 * This source code is licensed under the BSD-style license found in the
 * LICENSE file in the root directory of this source tree. An additional grant
 * of patent rights can be found in the PATENTS file in the same directory.
 */

const React = require("react");

class Footer extends React.Component {
  render() {
    return (

    );
  }
}

module.exports = Footer;
<|endoftext|>


<commit_before>function ParseFiles(){
     //node js modules
    var fs = require('fs'),
        PEG = require('pegjs'),
		wrench = require('wrench');
    //_________________________________________________

    //parcer for idl files
    var parser = PEG.buildParser(fs.readFileSync('./lib/grammar.peg', 'utf8'));

    var idlparser;

    this.options = {
        idlExtension: '.idl',
        jsExtension: '.js',
        jsParcerFolder: './node_modules/',
        idlFolder: 'idlFolder/',
        jsStubsFolder: 'output/jsStubs/',
		outputFolder: 'output/',
        dependenciesPaths: 'Ti/Tizen/'

    };

    this.init = function(){
        var self = this;
        var code = parser.toSource();

        //create js parser
        fs.writeFile(this.options.jsParcerFolder + 'WebIDLParser.js', 'exports.Parser = ' + code,

        //callback when js parser is ready
        function(){
			var failSilently = function() {
				console.log('Some problems');
			}
			wrench.rmdirSyncRecursive('output', failSilently);
            fs.mkdirSync('output', 0755);
			fs.mkdirSync('output/jsStubs', 0755);
            //when js parser created we can use this module
            idlparser = require(self.options.jsParcerFolder + 'WebIDLParser');

            //create all js stubs
            self.createAllStubs(self.options.idlFolder);
        });
    };

    //create all stubs from folder
    var ti = require('./TitaniumInterface');

	this.getAllPrimitives = function(folder) {
		var files = fs.readdirSync(folder),
			i = 0,
			filesCount = files.length;

		if (filesCount > 0) {
			for (; i < filesCount; i++) {

			}
		}
	}

    this.createAllStubs = function(folder){
        var idlFiles = fs.readdirSync(folder);

        if(idlFiles.length > 0) {
            for(var i = 0, len = idlFiles.length; i<len; i++ ) {
                var name = idlFiles[i].replace(this.options.idlExtension, '');

                try {
                    this.createStub(name, true); // if second parameter = true then we'll save json obects to array
												 // get all tizen's primitive types and save inheritance tree for interfaces
                } catch(err) {
                    console.log('Something wrong with ' +idlFiles[i] + '-->' + err + (err.name=='SyntaxError'?' (line=' + err.line + ', column=' + err.column + ')':''));
                }
            }

            //Generate auxiliary files
            //fs.writeFileSync(this.options.jsStubsFolder + 'path.txt', ti.TitaniumInterface.pathes.get());
        } else {
            console.log('Folder with .idl files is empty');
        }

        if(idlFiles.length > 0) {
            for(var i = 0, len = idlFiles.length; i<len; i++ ) {
                var name = idlFiles[i].replace(this.options.idlExtension, '');

                try {
                    this.createStub(name);
                } catch(err) {
                    console.log('Something wrong with ' +idlFiles[i] + '-->' + err + (err.name=='SyntaxError'?' (line=' + err.line + ', column=' + err.column + ')':''));
                }
            }

            //Generate auxiliary files
           	fs.writeFileSync(this.options.outputFolder + 'path.txt', ti.TitaniumInterface.pathes.get());
        } else {
            console.log('Folder with .idl files is empty');
        }
    };

    //create one file
    this.createStub = function(name, saveFlag /*if true - save json objects*/){
        var idltext = fs.readFileSync(this.options.idlFolder + name + this.options.idlExtension, 'utf8');
        var realObject = idlparser.Parser.parse(idltext);

		if (saveFlag) {
			ti.TitaniumInterface.jsonObjects.push(realObject);
			ti.TitaniumInterface.getPrimitives(realObject);
			ti.TitaniumInterface.getInheritanceTree(realObject);
		} else {
			// Write out the resulting stub
			ti.TitaniumInterface.genStub(realObject);

			// Auxiliary information for dependencies
			ti.TitaniumInterface.pathes.add('"'+this.options.dependenciesPaths + name.replace(/\s/g,'')+'": []');
		}
    };
}

var parseFiles = new ParseFiles();
parseFiles.init();<commit_msg>"node_modules" folder fix<commit_after>function ParseFiles(){
     //node js modules
    var fs = require('fs'),
        PEG = require('pegjs'),
		wrench = require('wrench');
    //_________________________________________________

    //parcer for idl files
    var parser = PEG.buildParser(fs.readFileSync('./lib/grammar.peg', 'utf8'));

    var idlparser;

    this.options = {
        idlExtension: '.idl',
        jsExtension: '.js',
        jsParcerFolder: './node_modules/',
        idlFolder: 'idlFolder/',
        jsStubsFolder: 'output/jsStubs/',
		outputFolder: 'output/',
        dependenciesPaths: 'Ti/Tizen/'

    };

    this.init = function(){
        var self = this;
        var code = parser.toSource();

        try {
                fs.mkdirSync(this.options.jsParcerFolder, 0755);
        } catch(err) {
                console.log('Folder '+this.options.jsParcerFolder+' not created. Reason:' + err.code);
        }

        //create js parser
        fs.writeFile(this.options.jsParcerFolder + 'WebIDLParser.js', 'exports.Parser = ' + code,

        //callback when js parser is ready
        function(){
			var failSilently = function() {
				console.log('Some problems');
			}
			wrench.rmdirSyncRecursive('output', failSilently);
            fs.mkdirSync('output', 0755);
			fs.mkdirSync('output/jsStubs', 0755);
            //when js parser created we can use this module
            idlparser = require(self.options.jsParcerFolder + 'WebIDLParser');

            //create all js stubs
            self.createAllStubs(self.options.idlFolder);
        });
    };

    //create all stubs from folder
    var ti = require('./TitaniumInterface');

	this.getAllPrimitives = function(folder) {
		var files = fs.readdirSync(folder),
			i = 0,
			filesCount = files.length;

		if (filesCount > 0) {
			for (; i < filesCount; i++) {

			}
		}
	}

    this.createAllStubs = function(folder){
        var idlFiles = fs.readdirSync(folder);

        if(idlFiles.length > 0) {
            for(var i = 0, len = idlFiles.length; i<len; i++ ) {
                var name = idlFiles[i].replace(this.options.idlExtension, '');

                try {
                    this.createStub(name, true); // if second parameter = true then we'll save json obects to array
												 // get all tizen's primitive types and save inheritance tree for interfaces
                } catch(err) {
                    console.log('Something wrong with ' +idlFiles[i] + '-->' + err + (err.name=='SyntaxError'?' (line=' + err.line + ', column=' + err.column + ')':''));
                }
            }

            //Generate auxiliary files
            //fs.writeFileSync(this.options.jsStubsFolder + 'path.txt', ti.TitaniumInterface.pathes.get());
        } else {
            console.log('Folder with .idl files is empty');
        }

        if(idlFiles.length > 0) {
            for(var i = 0, len = idlFiles.length; i<len; i++ ) {
                var name = idlFiles[i].replace(this.options.idlExtension, '');

                try {
                    this.createStub(name);
                } catch(err) {
                    console.log('Something wrong with ' +idlFiles[i] + '-->' + err + (err.name=='SyntaxError'?' (line=' + err.line + ', column=' + err.column + ')':''));
                }
            }

            //Generate auxiliary files
           	fs.writeFileSync(this.options.outputFolder + 'path.txt', ti.TitaniumInterface.pathes.get());
        } else {
            console.log('Folder with .idl files is empty');
        }
    };

    //create one file
    this.createStub = function(name, saveFlag /*if true - save json objects*/){
        var idltext = fs.readFileSync(this.options.idlFolder + name + this.options.idlExtension, 'utf8');
        var realObject = idlparser.Parser.parse(idltext);

		if (saveFlag) {
			ti.TitaniumInterface.jsonObjects.push(realObject);
			ti.TitaniumInterface.getPrimitives(realObject);
			ti.TitaniumInterface.getInheritanceTree(realObject);
		} else {
			// Write out the resulting stub
			ti.TitaniumInterface.genStub(realObject);

			// Auxiliary information for dependencies
			ti.TitaniumInterface.pathes.add('"'+this.options.dependenciesPaths + name.replace(/\s/g,'')+'": []');
		}
    };
}

var parseFiles = new ParseFiles();
parseFiles.init();<|endoftext|>


<commit_before>define(function(){if("undefined"==typeof window)return{load:function(e,t,n){n()}};var e=document.getElementsByTagName("head")[0],t=window.navigator.userAgent.match(/Trident\/([^ ;]*)|AppleWebKit\/([^ ;]*)|Opera\/([^ ;]*)|rv\:([^ ;]*)(.*?)Gecko\/([^ ;]*)|MSIE\s([^ ;]*)|AndroidWebKit\/([^ ;]*)/)||0,n=!1,r=!0;t[1]||t[7]?n=parseInt(t[1])<6||parseInt(t[7])<=9:t[2]||t[8]?r=!1:t[4]&&(n=parseInt(t[4])<18);var o={};o.pluginBuilder="./css-builder";var a,i,s,l=function(){a=document.createElement("style"),e.appendChild(a),i=a.styleSheet||a.sheet},u=0,d=[],c=function(e){u++,32==u&&(l(),u=0),i.addImport(e),a.onload=function(){f()}},f=function(){s();var e=d.shift();return e?(s=e[1],void c(e[0])):void(s=null)},h=function(e,t){if(i&&i.addImport||l(),i&&i.addImport)s?d.push([e,t]):(c(e),s=t);else{a.textContent='@import "'+e+'";';var n=setInterval(function(){try{a.sheet.cssRules,clearInterval(n),t()}catch(e){}},10)}},p=function(t,n){var o=document.createElement("link");if(o.type="text/css",o.rel="stylesheet",r)o.onload=function(){o.onload=function(){},setTimeout(n,7)};else var a=setInterval(function(){for(var e=0;e<document.styleSheets.length;e++){var t=document.styleSheets[e];if(t.href==o.href)return clearInterval(a),n()}},10);o.href=t,e.appendChild(o)};return o.normalize=function(e,t){return".css"==e.substr(e.length-4,4)&&(e=e.substr(0,e.length-4)),t(e)},o.load=function(e,t,r){(n?h:p)(t.toUrl(e+".css"),r)},o});<commit_msg>Reminified css.min.js with uglifyjs so that to contain latest 0.1.8 release changes.<commit_after>define(function(){if("undefined"==typeof window)return{load:function(a,b,c){c()}};var a=document.getElementsByTagName("head")[0],b=window.navigator.userAgent.match(/Trident\/([^ ;]*)|AppleWebKit\/([^ ;]*)|Opera\/([^ ;]*)|rv\:([^ ;]*)(.*?)Gecko\/([^ ;]*)|MSIE\s([^ ;]*)|AndroidWebKit\/([^ ;]*)/)||0,c=!1,d=!0;b[1]||b[7]?c=parseInt(b[1])<6||parseInt(b[7])<=9:b[2]||b[8]?d=!1:b[4]&&(c=parseInt(b[4])<18);var e={};e.pluginBuilder="./css-builder";var f,g,h,i=function(){f=document.createElement("style"),a.appendChild(f),g=f.styleSheet||f.sheet},j=0,k=[],l=function(a){g.addImport(a),f.onload=function(){m()},j++,31==j&&(i(),j=0)},m=function(){h();var a=k.shift();return a?(h=a[1],void l(a[0])):void(h=null)},n=function(a,b){if(g&&g.addImport||i(),g&&g.addImport)h?k.push([a,b]):(l(a),h=b);else{f.textContent='@import "'+a+'";';var c=setInterval(function(){try{f.sheet.cssRules,clearInterval(c),b()}catch(a){}},10)}},o=function(b,c){var e=document.createElement("link");if(e.type="text/css",e.rel="stylesheet",d)e.onload=function(){e.onload=function(){},setTimeout(c,7)};else var f=setInterval(function(){for(var a=0;a<document.styleSheets.length;a++){var b=document.styleSheets[a];if(b.href==e.href)return clearInterval(f),c()}},10);e.href=b,a.appendChild(e)};return e.normalize=function(a,b){return".css"==a.substr(a.length-4,4)&&(a=a.substr(0,a.length-4)),b(a)},e.load=function(a,b,d,e){(c?n:o)(b.toUrl(a+".css"),d)},e});<|endoftext|>


<commit_before>// Package of defining Vegalite Specification's json schema

var schema = module.exports = {},
  util = require('../util');

schema.util = require('./schemautil');

schema.marktype = {
  type: 'string',
  enum: ['point', 'bar', 'line', 'area', 'circle', 'square', 'text']
};

schema.aggr = {
  type: 'string',
  enum: ['avg', 'sum', 'min', 'max', 'count'],
  supportedEnums: {
    Q: ['avg', 'sum', 'min', 'max', 'count'],
    O: [],
    T: ['avg', 'min', 'max'],
    '': ['count']
  },
  supportedTypes: {'Q': true, 'O': true, 'T': true, '': true}
};

schema.band = {
  type: 'object',
  properties: {
    size: {
      type: 'integer',
      minimum: 0
    },
    padding: {
      type: 'integer',
      minimum: 0,
      default: 1
    }
  }
};

schema.timefns = ['month', 'year', 'dayofweek', 'date', 'hour', 'minute', 'second'];

schema.fn = {
  type: 'string',
  enum: schema.timefns,
  supportedTypes: {'T': true}
};

//TODO(kanitw): add other type of function here

schema.scale_type = {
  type: 'string',
  enum: ['linear', 'log', 'pow', 'sqrt', 'quantile'],
  default: 'linear',
  supportedTypes: {'Q': true}
};

schema.field = {
  type: 'object',
  properties: {
    name: {
      type: 'string'
    }
  }
};

var clone = util.duplicate;
var merge = schema.util.merge;

var typicalField = merge(clone(schema.field), {
  type: 'object',
  properties: {
    type: {
      type: 'string',
      enum: ['O', 'Q', 'T']
    },
    bin: {
      type: 'boolean',
      default: false,
      supportedTypes: {'Q': true} // TODO: add 'O' after finishing #81
    },
    aggr: schema.aggr,
    fn: schema.fn,
    scale: {
      type: 'object',
      properties: {
        type: schema.scale_type,
        reverse: { type: 'boolean', default: false },
        zero: {
          type: 'boolean',
          description: 'Include zero',
          supportedTypes: {'Q': true}
        },
        nice: {
          type: 'string',
          enum: ['second', 'minute', 'hour', 'day', 'week', 'month', 'year'],
          supportedTypes: {'T': true}
        }
      }
    }
  }
});

var onlyOrdinalField = merge(clone(schema.field), {
  type: 'object',
  properties: {
    type: {
      type: 'string',
      enum: ['O','Q'] // ordinal-only field supports Q when bin is applied
    },
    bin: {
      type: 'boolean',
      default: false,
      supportedTypes: {'Q': true} // TODO: add 'O' after finishing #81
    },
    aggr: {
      type: 'string',
      enum: ['count'],
      supportedTypes: {'O': true}
    }
  }
});

var axisMixin = {
  type: 'object',
  properties: {
    axis: {
      type: 'object',
      properties: {
        grid: {
          type: 'boolean',
          default: false,
          description: 'A flag indicate if gridlines should be created in addition to ticks.'
        },
        title: {
          type: 'boolean',
          default: true,
          description: 'A title for the axis.'
        },
        titleOffset: {
          type: 'integer',
          description: 'A title offset value for the axis.'
        },
        format: {
          type: 'string',
          description: 'The formatting pattern for axis labels.'
        }
      }
    }
  }
};

var bandMixin = {
  type: 'object',
  properties: {
    band: schema.band
  }
};

var legendMixin = {
  type: 'object',
  properties: {
    legend: {
      type: 'boolean',
      default: true
    }
  }
};

var textMixin = {
  type: 'object',
  properties: {
    text: {
      type: 'object',
      properties: {
        text: {
          type: 'object',
          properties: {
            align: {
              type: 'string',
              default: 'left'
            },
            baseline: {
              type: 'string',
              default: 'middle'
            },
            margin: {
              type: 'integer',
              default: 4,
              minimum: 0
            }
          }
        },
        font: {
          type: 'object',
          properties: {
            weight: {
              type: 'string',
              enum: ['normal', 'bold'],
              default: 'normal'
            },
            size: {
              type: 'integer',
              default: 10,
              minimum: 0
            },
            family: {
              type: 'string',
              default: 'Helvetica Neue'
            },
            style: {
              type: 'string',
              default: 'normal',
              enum: ['normal', 'italic']
            }
          }
        }
      }
    }
  }
};

var sizeMixin = {
  type: 'object',
  properties: {
    value: {
      type: 'integer',
      default: 30,
      minimum: 0
    }
  }
};

var colorMixin = {
  type: 'object',
  properties: {
    value: {
      type: 'string',
      role: 'color',
      default: 'steelblue'
    },
    scale: {
      type: 'object',
      properties: {
        range: {
          type: ['string', 'array']
        }
      }
    }
  }
};

var alphaMixin = {
  type: 'object',
  properties: {
    value: {
      type: 'number',
      default: 1,
      minimum: 0,
      maximum: 1
    }
  }
};

var shapeMixin = {
  type: 'object',
  properties: {
    value: {
      type: 'string',
      enum: ['circle', 'square', 'cross', 'diamond', 'triangle-up', 'triangle-down'],
      default: 'circle'
    }
  }
};

var rowMixin = {
  properties: {
    height: {
      type: 'number',
      minimum: 0,
      default: 150
    },
    padding: {
      type: 'number',
      minimum: 0,
      maximum: 1,
      default: 0.1
    }
  }
};

var colMixin = {
  properties: {
    width: {
      type: 'number',
      minimum: 0,
      default: 150
    },
    padding: {
      type: 'number',
      minimum: 0,
      maximum: 1,
      default: 0.1
    }
  }
};

var requiredNameType = {
  required: ['name', 'type']
};

var x = merge(merge(merge(clone(typicalField), axisMixin), bandMixin), requiredNameType);
var y = clone(x);

var facet = merge(clone(onlyOrdinalField), requiredNameType);
var row = merge(clone(facet), rowMixin);
var col = merge(clone(facet), colMixin);

var size = merge(merge(clone(typicalField), legendMixin), sizeMixin);
var color = merge(merge(clone(typicalField), legendMixin), colorMixin);
var alpha = merge(clone(typicalField), alphaMixin);
var shape = merge(merge(clone(onlyOrdinalField), legendMixin), shapeMixin);

var text = merge(clone(typicalField), textMixin);

var cfg = {
  type: 'object',
  properties: {
    // template
    width: {
      type: 'integer',
      default: undefined
    },
    height: {
      type: 'integer',
      default: undefined
    },
    viewport: {
      type: 'array',
      items: {
        type: ['integer']
      },
      default: undefined
    },
    //binning
    maxbins: {
      type: 'integer',
      default: 10,
      minimum: 2
    },

    // single plot
    singleHeight: {
      // will be overwritten by bandWidth * (cardinality + padding)
      type: 'integer',
      default: 200,
      minimum: 0
    },
    singleWidth: {
      // will be overwritten by bandWidth * (cardinality + padding)
      type: 'integer',
      default: 200,
      minimum: 0
    },
    // band size
    largeBandSize: {
      type: 'integer',
      default: 19,
      minimum: 0
    },
    smallBandSize: {
      //small multiples or single plot with high cardinality
      type: 'integer',
      default: 12,
      minimum: 0
    },
    largeBandMaxCardinality: {
      type: 'integer',
      default: 10
    },
    // small multiples
    cellPadding: {
      type: 'number',
      default: 0.1
    },
    cellBackgroundColor: {
      type: 'string',
      role: 'color',
      default: '#fdfdfd'
    },
    textCellWidth: {
      type: 'integer',
      default: 90,
      minimum: 0
    },

    // marks
    strokeWidth: {
      type: 'integer',
      default: 2,
      minimum: 0
    },

    // scales
    timeScaleLabelLength: {
      type: 'integer',
      default: 3,
      minimum: 0
    },
    // other
    characterWidth: {
      type: 'integer',
      default: 6
    },

    // data source
    dataFormatType: {
      type: 'string',
      enum: ['json', 'csv'],
      default: 'json'
    },
    useVegaServer: {
      type: 'boolean',
      default: false
    },
    dataUrl: {
      type: 'string',
      default: undefined
    },
    vegaServerTable: {
      type: 'string',
      default: undefined
    },
    vegaServerUrl: {
      type: 'string',
      default: 'http://localhost:3001'
    }
  }
};

/** @type Object Schema of a vegalite specification */
schema.schema = {
  $schema: 'http://json-schema.org/draft-04/schema#',
  type: 'object',
  required: ['marktype', 'enc', 'cfg'],
  properties: {
    marktype: schema.marktype,
    enc: {
      type: 'object',
      properties: {
        x: x,
        y: y,
        row: row,
        col: col,
        size: size,
        color: color,
        alpha: alpha,
        shape: shape,
        text: text
      }
    },
    cfg: cfg
  }
};

/** Instantiate a verbose vl spec from the schema */
schema.instantiate = function() {
  return schema.util.instantiate(schema.schema);
};
<commit_msg>add titleAlign & change bin size to 15<commit_after>// Package of defining Vegalite Specification's json schema

var schema = module.exports = {},
  util = require('../util');

schema.util = require('./schemautil');

schema.marktype = {
  type: 'string',
  enum: ['point', 'bar', 'line', 'area', 'circle', 'square', 'text']
};

schema.aggr = {
  type: 'string',
  enum: ['avg', 'sum', 'min', 'max', 'count'],
  supportedEnums: {
    Q: ['avg', 'sum', 'min', 'max', 'count'],
    O: [],
    T: ['avg', 'min', 'max'],
    '': ['count']
  },
  supportedTypes: {'Q': true, 'O': true, 'T': true, '': true}
};

schema.band = {
  type: 'object',
  properties: {
    size: {
      type: 'integer',
      minimum: 0
    },
    padding: {
      type: 'integer',
      minimum: 0,
      default: 1
    }
  }
};

schema.timefns = ['month', 'year', 'dayofweek', 'date', 'hour', 'minute', 'second'];

schema.fn = {
  type: 'string',
  enum: schema.timefns,
  supportedTypes: {'T': true}
};

//TODO(kanitw): add other type of function here

schema.scale_type = {
  type: 'string',
  enum: ['linear', 'log', 'pow', 'sqrt', 'quantile'],
  default: 'linear',
  supportedTypes: {'Q': true}
};

schema.field = {
  type: 'object',
  properties: {
    name: {
      type: 'string'
    }
  }
};

var clone = util.duplicate;
var merge = schema.util.merge;

var typicalField = merge(clone(schema.field), {
  type: 'object',
  properties: {
    type: {
      type: 'string',
      enum: ['O', 'Q', 'T']
    },
    bin: {
      type: 'boolean',
      default: false,
      supportedTypes: {'Q': true} // TODO: add 'O' after finishing #81
    },
    aggr: schema.aggr,
    fn: schema.fn,
    scale: {
      type: 'object',
      properties: {
        type: schema.scale_type,
        reverse: { type: 'boolean', default: false },
        zero: {
          type: 'boolean',
          description: 'Include zero',
          supportedTypes: {'Q': true}
        },
        nice: {
          type: 'string',
          enum: ['second', 'minute', 'hour', 'day', 'week', 'month', 'year'],
          supportedTypes: {'T': true}
        }
      }
    }
  }
});

var onlyOrdinalField = merge(clone(schema.field), {
  type: 'object',
  properties: {
    type: {
      type: 'string',
      enum: ['O','Q'] // ordinal-only field supports Q when bin is applied
    },
    bin: {
      type: 'boolean',
      default: false,
      supportedTypes: {'Q': true} // TODO: add 'O' after finishing #81
    },
    aggr: {
      type: 'string',
      enum: ['count'],
      supportedTypes: {'O': true}
    }
  }
});

var axisMixin = {
  type: 'object',
  properties: {
    axis: {
      type: 'object',
      properties: {
        grid: {
          type: 'boolean',
          default: false,
          description: 'A flag indicate if gridlines should be created in addition to ticks.'
        },
        title: {
          type: 'boolean',
          default: true,
          description: 'A title for the axis.'
        },
        titleAlign: {
          type: 'string',
          enum: ['left', 'right', 'center']
        },
        titleOffset: {
          type: 'integer',
          description: 'A title offset value for the axis.'
        },
        format: {
          type: 'string',
          description: 'The formatting pattern for axis labels.'
        }
      }
    }
  }
};

var bandMixin = {
  type: 'object',
  properties: {
    band: schema.band
  }
};

var legendMixin = {
  type: 'object',
  properties: {
    legend: {
      type: 'boolean',
      default: true
    }
  }
};

var textMixin = {
  type: 'object',
  properties: {
    text: {
      type: 'object',
      properties: {
        text: {
          type: 'object',
          properties: {
            align: {
              type: 'string',
              default: 'left'
            },
            baseline: {
              type: 'string',
              default: 'middle'
            },
            margin: {
              type: 'integer',
              default: 4,
              minimum: 0
            }
          }
        },
        font: {
          type: 'object',
          properties: {
            weight: {
              type: 'string',
              enum: ['normal', 'bold'],
              default: 'normal'
            },
            size: {
              type: 'integer',
              default: 10,
              minimum: 0
            },
            family: {
              type: 'string',
              default: 'Helvetica Neue'
            },
            style: {
              type: 'string',
              default: 'normal',
              enum: ['normal', 'italic']
            }
          }
        }
      }
    }
  }
};

var sizeMixin = {
  type: 'object',
  properties: {
    value: {
      type: 'integer',
      default: 30,
      minimum: 0
    }
  }
};

var colorMixin = {
  type: 'object',
  properties: {
    value: {
      type: 'string',
      role: 'color',
      default: 'steelblue'
    },
    scale: {
      type: 'object',
      properties: {
        range: {
          type: ['string', 'array']
        }
      }
    }
  }
};

var alphaMixin = {
  type: 'object',
  properties: {
    value: {
      type: 'number',
      default: 1,
      minimum: 0,
      maximum: 1
    }
  }
};

var shapeMixin = {
  type: 'object',
  properties: {
    value: {
      type: 'string',
      enum: ['circle', 'square', 'cross', 'diamond', 'triangle-up', 'triangle-down'],
      default: 'circle'
    }
  }
};

var rowMixin = {
  properties: {
    height: {
      type: 'number',
      minimum: 0,
      default: 150
    },
    padding: {
      type: 'number',
      minimum: 0,
      maximum: 1,
      default: 0.1
    }
  }
};

var colMixin = {
  properties: {
    width: {
      type: 'number',
      minimum: 0,
      default: 150
    },
    padding: {
      type: 'number',
      minimum: 0,
      maximum: 1,
      default: 0.1
    }
  }
};

var requiredNameType = {
  required: ['name', 'type']
};

var x = merge(merge(merge(clone(typicalField), axisMixin), bandMixin), requiredNameType);
var y = clone(x);

var facet = merge(clone(onlyOrdinalField), requiredNameType);
var row = merge(clone(facet), rowMixin);
var col = merge(clone(facet), colMixin);

var size = merge(merge(clone(typicalField), legendMixin), sizeMixin);
var color = merge(merge(clone(typicalField), legendMixin), colorMixin);
var alpha = merge(clone(typicalField), alphaMixin);
var shape = merge(merge(clone(onlyOrdinalField), legendMixin), shapeMixin);

var text = merge(clone(typicalField), textMixin);

var cfg = {
  type: 'object',
  properties: {
    // template
    width: {
      type: 'integer',
      default: undefined
    },
    height: {
      type: 'integer',
      default: undefined
    },
    viewport: {
      type: 'array',
      items: {
        type: ['integer']
      },
      default: undefined
    },
    //binning
    maxbins: {
      type: 'integer',
      default: 15,
      minimum: 2
    },

    // single plot
    singleHeight: {
      // will be overwritten by bandWidth * (cardinality + padding)
      type: 'integer',
      default: 200,
      minimum: 0
    },
    singleWidth: {
      // will be overwritten by bandWidth * (cardinality + padding)
      type: 'integer',
      default: 200,
      minimum: 0
    },
    // band size
    largeBandSize: {
      type: 'integer',
      default: 19,
      minimum: 0
    },
    smallBandSize: {
      //small multiples or single plot with high cardinality
      type: 'integer',
      default: 12,
      minimum: 0
    },
    largeBandMaxCardinality: {
      type: 'integer',
      default: 10
    },
    // small multiples
    cellPadding: {
      type: 'number',
      default: 0.1
    },
    cellBackgroundColor: {
      type: 'string',
      role: 'color',
      default: '#fdfdfd'
    },
    textCellWidth: {
      type: 'integer',
      default: 90,
      minimum: 0
    },

    // marks
    strokeWidth: {
      type: 'integer',
      default: 2,
      minimum: 0
    },

    // scales
    timeScaleLabelLength: {
      type: 'integer',
      default: 3,
      minimum: 0
    },
    // other
    characterWidth: {
      type: 'integer',
      default: 6
    },

    // data source
    dataFormatType: {
      type: 'string',
      enum: ['json', 'csv'],
      default: 'json'
    },
    useVegaServer: {
      type: 'boolean',
      default: false
    },
    dataUrl: {
      type: 'string',
      default: undefined
    },
    vegaServerTable: {
      type: 'string',
      default: undefined
    },
    vegaServerUrl: {
      type: 'string',
      default: 'http://localhost:3001'
    }
  }
};

/** @type Object Schema of a vegalite specification */
schema.schema = {
  $schema: 'http://json-schema.org/draft-04/schema#',
  type: 'object',
  required: ['marktype', 'enc', 'cfg'],
  properties: {
    marktype: schema.marktype,
    enc: {
      type: 'object',
      properties: {
        x: x,
        y: y,
        row: row,
        col: col,
        size: size,
        color: color,
        alpha: alpha,
        shape: shape,
        text: text
      }
    },
    cfg: cfg
  }
};

/** Instantiate a verbose vl spec from the schema */
schema.instantiate = function() {
  return schema.util.instantiate(schema.schema);
};
<|endoftext|>


<commit_before>/*jslint indent: 2 */
/*global window, jQuery, angular, cordova */
"use strict";

// Returns a jQuery or AngularJS deferred object, or pass a success and fail callbacks if you don't want to use jQuery or AngularJS
var getPromisedCordovaExec = function (command, success, fail) {
  var toReturn, deferred, injector, $q;
  if (success === undefined) {
    if (window.jQuery) {
      deferred = jQuery.Deferred();
      success = deferred.resolve;
      fail = deferred.reject;
      toReturn = deferred;
    } else if (window.angular) {
      injector = angular.injector(["ng"]);
      $q = injector.get("$q");
      deferred = $q.defer();
      success = deferred.resolve;
      fail = deferred.reject;
      toReturn = deferred.promise;
    } else if (window.Promise) {
      toReturn = new Promise(function(c, e) {
        success = c;
        fail = e;
      });
    } else if (window.WinJS && window.WinJS.Promise) {
      toReturn = new WinJS.Promise(function(c, e) {
        success = c;
        fail = e;
      });
    } else {
      return console.error('AppVersion either needs a success callback, or jQuery/AngularJS/Promise/WinJS.Promise defined for using promises');
    }
  }
  // 5th param is NOT optional. must be at least empty array
  cordova.exec(success, fail, "AppVersion", command, []);
  return toReturn;
};

var getAppVersion = function (success, fail) {
  return getPromisedCordovaExec('getVersionNumber', success, fail);
};

getAppVersion.getAppName = function (success, fail) {
  return getPromisedCordovaExec('getAppName', success, fail);
};

getAppVersion.getPackageName = function (success, fail) {
  return getPromisedCordovaExec('getPackageName', success, fail);
};

getAppVersion.getVersionNumber = function (success, fail) {
  return getPromisedCordovaExec('getVersionNumber', success, fail);
};

getAppVersion.getVersionCode = function (success, fail) {
  return getPromisedCordovaExec('getVersionCode', success, fail);
};

module.exports = getAppVersion;
<commit_msg>Add support for WhenJS<commit_after>/*jslint indent: 2 */
/*global window, jQuery, angular, cordova */
"use strict";

// Returns a jQuery or AngularJS deferred object, or pass a success and fail callbacks if you don't want to use jQuery or AngularJS
var getPromisedCordovaExec = function (command, success, fail) {
  var toReturn, deferred, injector, $q;
  if (success === undefined) {
    if (window.jQuery) {
      deferred = jQuery.Deferred();
      success = deferred.resolve;
      fail = deferred.reject;
      toReturn = deferred;
    } else if (window.angular) {
      injector = angular.injector(["ng"]);
      $q = injector.get("$q");
      deferred = $q.defer();
      success = deferred.resolve;
      fail = deferred.reject;
      toReturn = deferred.promise;
    } else if (window.when && window.when.promise) {
      deferred = when.defer();
      success = deferred.resolve;
      fail = deferred.reject;
      toReturn = deferred;
    } else if (window.Promise) {
      toReturn = new Promise(function(c, e) {
        success = c;
        fail = e;
      });
    } else if (window.WinJS && window.WinJS.Promise) {
      toReturn = new WinJS.Promise(function(c, e) {
        success = c;
        fail = e;
      });
    } else {
      return console.error('AppVersion either needs a success callback, or jQuery/AngularJS/Promise/WinJS.Promise defined for using promises');
    }
  }
  // 5th param is NOT optional. must be at least empty array
  cordova.exec(success, fail, "AppVersion", command, []);
  return toReturn;
};

var getAppVersion = function (success, fail) {
  return getPromisedCordovaExec('getVersionNumber', success, fail);
};

getAppVersion.getAppName = function (success, fail) {
  return getPromisedCordovaExec('getAppName', success, fail);
};

getAppVersion.getPackageName = function (success, fail) {
  return getPromisedCordovaExec('getPackageName', success, fail);
};

getAppVersion.getVersionNumber = function (success, fail) {
  return getPromisedCordovaExec('getVersionNumber', success, fail);
};

getAppVersion.getVersionCode = function (success, fail) {
  return getPromisedCordovaExec('getVersionCode', success, fail);
};

module.exports = getAppVersion;
<|endoftext|>