Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

moved cirq and df to own modules

  • Loading branch information...
commit b891a1b27c1e5d843a4095255aae2c0c76f6add6 1 parent 9a3a872
@coolaj86 authored
View
6 .gitmodules
@@ -19,3 +19,9 @@
[submodule "dom-storage"]
path = dom-storage
url = https://github.com/coolaj86/node-dom-storage.git
+[submodule "df"]
+ path = df
+ url = https://github.com/coolaj86/node-df-js.git
+[submodule "cirq"]
+ path = cirq
+ url = https://github.com/coolaj86/cirqjs.git
1  cirq
@@ -0,0 +1 @@
+Subproject commit 1dde5b95c0ef5cd2b31f307685ac2b6a93e06244
View
98 cirq/README.md
@@ -1,98 +0,0 @@
-CirQ
-====
-
-A simple Circular Buffer / Queue with great test coverage.
-
- var CirQ = require('cirq')
- , maxLength = 1
- , cirq = new CirQ(maxLength)
- , assert = require('assert')
- ;
-
- // the default maxLength is `4294967295`, which is `Math.pow(2,32) - 1);`
- // this is the maximum safe integer value
- cirq.push('a');
- cirq.push('b');
-
- assert.deepEqual(['b'], cirq.toArray());
-
- assert.strictEqual('b', cirq.pop());
-
- assert.deepEqual([], cirq.toArray());
-
-API
-===
-
- * `new CirQ(maxLength)`
- * `push(item)`
- * `pop()`
- * `toArray()`
-
-Why
-===
-
-Because I didn't run a performance test first.
-
-Despite rumors, `[].shift()` is probably efficient enough (until about 500,000 elements).
-
-:'(
-
- function bench(max, postMax) {
- console.log(max, postMax);
-
- var now = new Date().valueOf()
- , q = new CirQ(max)
- , i
- ;
-
- for (i = 0; i < max; i += 1) {
- q.push('xyz');
- }
- console.log(new Date().valueOf() - now);
- now = new Date().valueOf();
-
- for (i = 0; i < postMax; i += 1) {
- // q.shift(); // for Array
- q.push('abc');
- }
- console.log(new Date().valueOf() - now);
-
- console.log();
- }
-
-CirQ
-
- 5000 1000
- 1 ms
- 0 ms
-
- 50000 10000
- 19 ms
- 2 ms
-
- 500000 100000
- 146 ms
- 26 ms
-
-
-Array (shift and push)
-
- 5000 1000
- 0 ms
- 0 ms
-
- 50000 10000
- 11 ms
- 1 ms
-
- 500000 100
- 57 ms
- 167 ms
-
- 500000 1000
- 67 ms
- 1631 ms
-
- 5000000 1
- 407 ms
- 11 ms
View
61 cirq/lib/cirq.js
@@ -1,61 +0,0 @@
-(function () {
- "use strict";
-
- // wtfjs x == x+1
- var MAX_INT = 4294967295; // Math.pow(2, 32) - 1;
-
- function CirQ(maxlen) {
- if (!maxlen) {
- maxlen = MAX_INT;
- }
- this.maxlen = maxlen;
- this.cirq = {};
- this.oldest = 0;
- this.next = 0;
- this.length = 0;
- }
-
- // wrapping addition
- function wadd(i, max) {
- return (i + 1) % max;
- }
-
- CirQ.prototype.push = function (item) {
- if (this.next === this.oldest && this.length) {
- this.oldest = wadd(this.oldest, this.maxlen);
- }
- this.cirq[this.next] = item;
- this.length = Math.min(this.length + 1, this.maxlen);
- this.next = wadd(this.next, this.maxlen);
- //console.log('<<', this.oldest, this.next, this.cirq);
- };
-
- CirQ.prototype.pop = function () {
- var res = this.cirq[this.oldest];
- delete this.cirq[this.oldest];
-
- // stuck at head, can't go further
- if (this.length) {
- this.oldest = wadd(this.oldest, this.maxlen);
- }
- this.length = Math.max(this.length - 1, 0);
-
- //console.log('^^', this.oldest, this.next, this.cirq);
- return res;
- };
-
- CirQ.prototype.toArray = function () {
- var res = []
- , i = this.oldest
- ;
-
- while (res.length !== this.length) {
- res.push(this.cirq[i]);
- i = wadd(i, this.maxlen);
- }
-
- return res;
- };
-
- module.exports = CirQ;
-}());
View
24 cirq/max-int.js
@@ -1,24 +0,0 @@
-(function () {
- "use strict";
-
- var x = 0
- , scale = 1
- , start = new Date().valueOf()
- ;
-
- while (x + 1 != x) {
- // 10000000
- if (!(x % 10000000)) {
- console.log(x);
- }
-
- if (x >= scale) {
- console.log(x);
- scale *= 10;
- }
-
- x += 1
- }
-
- console.log(x, new Date().valueOf() - start);
-}());
View
41 cirq/test/bench-cirq.js
@@ -1,41 +0,0 @@
-(function () {
- "use strict";
-
- var CirQ = require(__dirname + '/../lib/cirq')
- ;
-
- function benchCirQ(max, postMax) {
- console.log(max, postMax);
-
- var now = new Date().valueOf()
- , cirq = new CirQ(max)
- , i
- ;
-
- for (i = 0; i < max; i += 1) {
- cirq.push('xyz');
- }
- console.log(new Date().valueOf() - now);
- now = new Date().valueOf();
-
- for (i = 0; i < postMax; i += 1) {
- cirq.push('abc');
- }
- console.log(new Date().valueOf() - now);
-
- console.log();
- }
-
- // warm-up
- benchCirQ(5000, 1000);
-
- benchCirQ(5000, 1000);
- // 1
- // 1
-
- benchCirQ(50000, 10000);
- // 20
- // 2
-
- benchCirQ(500000, 100000);
-}());
View
45 cirq/test/bench-shift.js
@@ -1,45 +0,0 @@
-(function () {
- "use strict";
-
- function benchShift(max, postMax) {
- console.log(max, postMax);
-
- var arr = []
- , now
- , i
- ;
-
- now = new Date().valueOf()
- for (i = 0; i < max; i += 1) {
- arr.push('xyz');
- }
- console.log(new Date().valueOf() - now);
-
- now = new Date().valueOf();
- for (i = 0; i < postMax; i += 1) {
- arr.shift();
- arr.push('abc');
- }
- console.log(new Date().valueOf() - now);
-
- console.log();
- }
-
- // warm-up run
- benchShift(5000, 1000);
-
- benchShift(5000, 1000);
- // 0 ~ 1 ms
- // 0 ~ 1 ms
-
- benchShift(50000, 10000);
- // 10 ~ 13 ms
- // 0 ~ 2 ms
-
- benchShift(500000, 1000);
- // ~ 60 ms
- // ~ 1200 ms
-
- benchShift(5000000, 1);
-
-}());
View
86 cirq/test/cirq-test.js
@@ -1,86 +0,0 @@
-(function () {
- "use strict";
-
- var assert = require('assert')
- , CirQ = require(__dirname + '/../lib/cirq')
- , cirq
- ;
-
- cirq = new CirQ(4);
-
- assert.ok(undefined === cirq.pop());
- assert.ok(undefined === cirq.pop());
-
- cirq.push('a');
- cirq.push('b');
- cirq.push('c');
-
- assert.deepEqual(['a','b','c'], cirq.toArray());
-
- assert.strictEqual('a', cirq.pop());
- assert.strictEqual('b', cirq.pop());
- assert.strictEqual('c', cirq.pop());
- assert.ok(undefined === cirq.pop());
- assert.ok(undefined === cirq.pop());
-
- cirq.push('d');
- cirq.push('e');
- cirq.push('f');
- cirq.push('g');
-
- assert.deepEqual(['d','e','f', 'g'], cirq.toArray());
-
- assert.strictEqual('d', cirq.pop());
- assert.strictEqual('e', cirq.pop());
- assert.strictEqual('f', cirq.pop());
- assert.strictEqual('g', cirq.pop());
- assert.ok(undefined === cirq.pop());
- assert.ok(undefined === cirq.pop());
-
- cirq.push('h'); // gets overwritten
- cirq.push('i');
- cirq.push('j');
- cirq.push('k');
- cirq.push('l');
-
- assert.strictEqual('i', cirq.pop());
- assert.strictEqual('j', cirq.pop());
- assert.strictEqual('k', cirq.pop());
- assert.strictEqual('l', cirq.pop());
- assert.ok(undefined === cirq.pop());
- assert.ok(undefined === cirq.pop());
-
- cirq.push('m'); // overwritten
- cirq.push('n'); //
- cirq.push('o'); //
- cirq.push('p'); //
- cirq.push('q');
- cirq.push('r');
- cirq.push('s');
- cirq.push('t');
-
- assert.deepEqual(['q','r','s', 't'], cirq.toArray());
-
- assert.strictEqual('q', cirq.pop());
- assert.strictEqual('r', cirq.pop());
- assert.strictEqual('s', cirq.pop());
- assert.strictEqual('t', cirq.pop());
- assert.ok(undefined === cirq.pop());
- assert.ok(undefined === cirq.pop());
-
- // might as well go to z
- cirq.push('u');
- assert.strictEqual('u', cirq.pop());
- cirq.push('v');
- assert.strictEqual('v', cirq.pop());
- cirq.push('w');
- assert.strictEqual('w', cirq.pop());
- cirq.push('x');
- assert.strictEqual('x', cirq.pop());
- cirq.push('y');
- assert.strictEqual('y', cirq.pop());
- cirq.push('z');
- assert.strictEqual('z', cirq.pop());
-
- console.log('PASS');
-}());
1  df
@@ -0,0 +1 @@
+Subproject commit c3e3fffd55f1a5c85ae396d725ad2712f3a3fd14
View
53 df/README.md
@@ -1,53 +0,0 @@
-df
-===
-
-Wraps `df -B 512` (Linux and Cygwin) or `df -b` (OS X) and produces pretty output.
-
-Gives output for both real and virtual filesystems.
-
-Installation
-===
-
-To install both module and commandline versions:
-
- npm install df
- npm install -g df
-
-Usage
-===
-
-Command-line:
-
- df-json
-
-Module:
-
- (function () {
- "use strict";
-
- var df = require('df')
- ;
-
- df(function (err, table) {
- if (err) {
- console.error(err.stack);
- return;
- }
-
- console.log(JSON.stringify(table, null, ' '));
- });
- }());
-
-Output:
-===
-
- [
- {
- "filesystem": "/dev/disk0s2",
- "blocks": 488555536,
- "used": 472631632,
- "available": 15411904,
- "percent": 97,
- "mountpoint": "/"
- }
- ]
View
15 df/example.js
@@ -1,15 +0,0 @@
-(function () {
- "use strict";
-
- var df = require('df')
- ;
-
- df(function (err, table) {
- if (err) {
- console.error(err.stack);
- return;
- }
-
- console.log(JSON.stringify(table, null, ' '));
- });
-}());
View
12 df/example.linux.txt
@@ -1,12 +0,0 @@
-Filesystem 1K-blocks Used Available Use% Mounted on
-/dev/mmcblk0p2 15235308 4179260 10282120 29% /
-none 107116 236 106880 1% /dev
-none 109076 0 109076 0% /dev/shm
-none 109076 56 109020 1% /var/run
-none 109076 0 109076 0% /var/lock
-/dev/sda1 961432072 738130260 174463812 81% /mnt/seagate-1tb
-/dev/sdc1 961432072 810219892 102374180 89% /mnt/wd-1tb
-/dev/sdf1 961432072 810364788 102229284 89% /mnt/wd-large-1tb
-/dev/sdd1 480719056 173425968 282873888 39% /mnt/hitachi-500gb
-/dev/sde1 480719056 187378468 268921388 42% /mnt/wd-500gb
-/dev/sdb1 961432072 810219744 102374328 89% /mnt/wd-new-1tb
View
5 df/example.osx.txt
@@ -1,5 +0,0 @@
-Filesystem 512-blocks Used Available Capacity Mounted on
-/dev/disk0s2 488555536 472617240 15426296 97% /
-devfs 365 365 0 100% /dev
-map -hosts 0 0 0 100% /net
-map auto_home 0 0 0 100% /home
View
90 df/index.js
@@ -1,90 +0,0 @@
-#!/usr/bin/env node
-(function () {
- "use strict";
-
- // map auto_home 0 0 0 100% /home
- var exec = require('child_process').exec
- , os = require('os')
- , reCaptureCells = /^([^\s]+\s?[^\s]+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)%\s+(.*?)\s*$/
- , cmdMap = {
- "Darwin": "df -b"
- , "Linux": "df -B 512"
- }
- , reMap = {
- "Darwin": reCaptureCells
- , "Linux": reCaptureCells
- }
- , cmdDf = cmdMap[os.type()]
- , reDf = reMap[os.type()]
- ;
-
- function init() {
- // TODO test default block size
- }
-
- function df(cb) {
- function formatDf(err, stdout, stderr) {
- var table
- , infos = []
- ;
-
- function parseRow(row) {
- var cells = row.match(reDf)
- ;
-
- if (!cells) {
- return;
- }
-
- // FYI
- // It seems that RegExp Match isn't a true array
- // popping it deos weird things
- infos.push({
- filesystem: cells[1]
- , blocks: parseInt(cells[2], 10)
- , used: parseInt(cells[3], 10)
- , available: parseInt(cells[4], 10)
- , percent: parseInt(cells[5], 10)
- , mountpoint: cells[6]
- });
- }
-
- if (err) {
- cb(err);
- return;
- }
-
- if (stderr) {
- cb(new Error(stderr));
- return;
- }
-
- table = stdout.split(/\n/g);
- // get rid of header
-
- table.pop();
- table.forEach(parseRow);
-
- cb(null, infos);
- }
-
- exec('df', formatDf);
- }
-
- function main () {
- df(function (err, table) {
- if (err) {
- console.error(err.stack);
- return;
- }
-
- console.log(JSON.stringify(table, null, ' '));
- })
- }
-
- if (require.main === module) {
- main();
- }
-
- module.exports = df;
-}());
View
17 df/package.json
@@ -1,17 +0,0 @@
-{
- "author": "AJ ONeal <coolaj86@gmail.com> (http://coolaj86.info)",
- "name": "df",
- "description": "wraps and parses `df` - OS X and Linux variants",
- "version": "1.0.0",
- "main": "index.js",
- "bin": {
- "df-json": "./index.js"
- },
- "engines": {
- "node": ">= 0.2.0"
- },
- "test": ["node tests.js"],
- "dependencies": {},
- "devDependencies": {},
- "preferGlobal": true
-}
View
31 df/tests.js
@@ -1,31 +0,0 @@
-(function () {
- "use strict";
-
- var df = require('./index')
- , assert = require('assert')
- ;
-
- /*
- {
- "filesystem": "/dev/disk0s2",
- "blocks": 488555536,
- "used": 472631632,
- "available": 15411904,
- "percent": 97,
- "mountpoint": "/"
- }
- */
-
- df(function (err, devices) {
- devices.forEach(function (dev) {
- assert.ok(dev.filesystem.match(/^[^\s]+\s?[^\s]+$/), "doesn't look like a filesystem");
- assert.ok(dev.blocks >= 0, 'blocks < 0 || NaN');
- assert.ok(dev.used >= 0, 'used < 0 || NaN');
- assert.ok(dev.available >= 0, 'available < 0 || NaN');
- //assert.strictEqual(dev.blocks, dev.used + dev.available, 'blacks != used + avaiable');
- assert.ok(dev.percent >= 0 && dev.percent <= 100, 'not between 0 and 100 percent');
- });
- console.log(JSON.stringify(devices, null, ' '));
- console.info('[PASS] all attributes match expected patterns');
- });
-}());
Please sign in to comment.
Something went wrong with that request. Please try again.