-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from ashpool/editorconfig
Editorconfig
- Loading branch information
Showing
10 changed files
with
219 additions
and
195 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# http://editorconfig.org | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
indent_size = 2 | ||
indent_style = space | ||
insert_final_newline = true | ||
max_line_length = 80 | ||
trim_trailing_whitespace = true | ||
|
||
[*.md] | ||
max_line_length = 0 | ||
trim_trailing_whitespace = false | ||
|
||
[COMMIT_EDITMSG] | ||
max_line_length = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,31 @@ | ||
var gulp = require('gulp'), | ||
jshint = require('gulp-jshint'), | ||
mocha = require('gulp-mocha'), | ||
cover = require('gulp-coverage'), | ||
jscs = require('gulp-jscs'); | ||
jshint = require('gulp-jshint'), | ||
mocha = require('gulp-mocha'), | ||
cover = require('gulp-coverage'), | ||
jscs = require('gulp-jscs'); | ||
|
||
gulp.task('default', ['jscs', 'lint', 'test'], function () { | ||
}); | ||
|
||
gulp.task('lint', function () { | ||
return gulp.src(['./lib/*.js', './test/*.js']) | ||
.pipe(jshint()) | ||
.pipe(jshint.reporter('default', {verbose: true})); | ||
return gulp.src(['./lib/*.js', './test/*.js']) | ||
.pipe(jshint()) | ||
.pipe(jshint.reporter('default', {verbose: true})); | ||
}); | ||
|
||
gulp.task('test', ['jscs', 'lint'], function () { | ||
return gulp.src('./test', {read: false}) | ||
.pipe(cover.instrument({ | ||
pattern: ['*lib/*.js'], | ||
debugDirectory: 'debug' | ||
})) | ||
.pipe(mocha({reporter: 'nyan'})) | ||
.pipe(cover.gather()) | ||
.pipe(cover.format()) | ||
.pipe(gulp.dest('reports')); | ||
return gulp.src('./test', {read: false}) | ||
.pipe(cover.instrument({ | ||
pattern: ['*lib/*.js'], | ||
debugDirectory: 'debug' | ||
})) | ||
.pipe(mocha({reporter: 'nyan'})) | ||
.pipe(cover.gather()) | ||
.pipe(cover.format()) | ||
.pipe(gulp.dest('reports')); | ||
}); | ||
|
||
gulp.task('jscs', function () { | ||
return gulp.src(['./lib/*.js', './test/*.js']) | ||
.pipe(jscs()); | ||
return gulp.src(['./lib/*.js', './test/*.js']) | ||
.pipe(jscs()); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,80 @@ | ||
var net = require('net'), | ||
url = require('url'); | ||
url = require('url'); | ||
|
||
function CarbonClient (properties) { | ||
if (typeof(properties) === 'string') { | ||
properties = {url: properties}; | ||
} | ||
properties = properties || {}; | ||
this._url = properties.url; | ||
this._hostedGraphiteKey = ''; | ||
if (properties.hostedGraphiteKey) { | ||
this._hostedGraphiteKey = properties.hostedGraphiteKey + '.'; | ||
} | ||
this._socket = properties.socket || null; | ||
function CarbonClient(properties) { | ||
if (typeof(properties) === 'string') { | ||
properties = {url: properties}; | ||
} | ||
properties = properties || {}; | ||
this._url = properties.url; | ||
this._hostedGraphiteKey = ''; | ||
if (properties.hostedGraphiteKey) { | ||
this._hostedGraphiteKey = properties.hostedGraphiteKey + '.'; | ||
} | ||
this._socket = properties.socket || null; | ||
} | ||
|
||
CarbonClient.prototype.write = function (metrics, timestamp) { | ||
var self = this; | ||
return new Promise(function (resolve, reject) { | ||
self._connect().then(function (socket) { | ||
var lines = ''; | ||
for (var path in metrics) { | ||
if (metrics.hasOwnProperty(path)) { | ||
var value = metrics[path]; | ||
lines += [path, value, timestamp].join(' ') + '\n'; | ||
} | ||
} | ||
socket.write(self._hostedGraphiteKey + lines, 'utf-8', function (err) { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(lines); | ||
} | ||
}); | ||
}, function (error) { | ||
reject(error); | ||
}); | ||
var self = this; | ||
return new Promise(function (resolve, reject) { | ||
self._connect().then(function (socket) { | ||
var lines = ''; | ||
for (var path in metrics) { | ||
if (metrics.hasOwnProperty(path)) { | ||
var value = metrics[path]; | ||
lines += [path, value, timestamp].join(' ') + '\n'; | ||
} | ||
} | ||
socket.write(self._hostedGraphiteKey + lines, 'utf-8', function (err) { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(lines); | ||
} | ||
}); | ||
}, function (error) { | ||
reject(error); | ||
}); | ||
}); | ||
}; | ||
|
||
CarbonClient.prototype._connect = function () { | ||
var self = this; | ||
return new Promise(function (resolve, reject) { | ||
if (self._socket) { | ||
return resolve(self._socket); | ||
} | ||
var dsn = url.parse(self._url), | ||
port = parseInt(dsn.port, 10) || 2003, | ||
host = dsn.hostname, | ||
timeout = 1000, | ||
socket = new net.Socket(); | ||
socket.setTimeout(timeout, function () { | ||
socket.destroy(); | ||
reject(new Error('Socket timeout')); | ||
}); | ||
socket.on('error', function (err) { | ||
socket.destroy(); | ||
reject(err); | ||
}); | ||
self._socket = socket.connect(port, host, 1000, function (err) { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(self._socket); | ||
} | ||
}); | ||
var self = this; | ||
return new Promise(function (resolve, reject) { | ||
if (self._socket) { | ||
return resolve(self._socket); | ||
} | ||
var dsn = url.parse(self._url), | ||
port = parseInt(dsn.port, 10) || 2003, | ||
host = dsn.hostname, | ||
timeout = 1000, | ||
socket = new net.Socket(); | ||
socket.setTimeout(timeout, function () { | ||
socket.destroy(); | ||
reject(new Error('Socket timeout')); | ||
}); | ||
socket.on('error', function (err) { | ||
socket.destroy(); | ||
reject(err); | ||
}); | ||
self._socket = socket.connect(port, host, 1000, function (err) { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(self._socket); | ||
} | ||
}); | ||
}); | ||
}; | ||
|
||
CarbonClient.prototype.end = function () { | ||
var self = this; | ||
return new Promise(function (resolve) { | ||
if (self._socket) { | ||
self._socket.end(); | ||
} | ||
resolve(); | ||
}); | ||
var self = this; | ||
return new Promise(function (resolve) { | ||
if (self._socket) { | ||
self._socket.end(); | ||
} | ||
resolve(); | ||
}); | ||
}; | ||
|
||
module.exports = CarbonClient; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
module.exports = { | ||
flatten: function (obj, flat, prefix) { | ||
flat = flat || {}; | ||
prefix = prefix || ''; | ||
flatten: function (obj, flat, prefix) { | ||
flat = flat || {}; | ||
prefix = prefix || ''; | ||
|
||
for (var key in obj) { | ||
if (obj.hasOwnProperty(key)) { | ||
var value = obj[key]; | ||
if (typeof value === 'object') { | ||
this.flatten(value, flat, prefix + key + '.'); | ||
} else { | ||
flat[prefix + key] = value; | ||
} | ||
} | ||
for (var key in obj) { | ||
if (obj.hasOwnProperty(key)) { | ||
var value = obj[key]; | ||
if (typeof value === 'object') { | ||
this.flatten(value, flat, prefix + key + '.'); | ||
} else { | ||
flat[prefix + key] = value; | ||
} | ||
return flat; | ||
} | ||
} | ||
return flat; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.