Permalink
Browse files

added basic monitorin app

  • Loading branch information...
jamuhl committed Aug 31, 2011
1 parent 47acb3a commit cdb43f0ff6ca5c3289c9f1049564e6b8e5582538
Showing 1,632 changed files with 142,243 additions and 0 deletions.
View
@@ -0,0 +1,58 @@
+#-----------------------------------------------------------------
+# BUILD WITH CAKE
+#
+# source: https://github.com/jashkenas/coffee-script/wiki/%5BHowTo%5D-Compiling-and-Setting-Up-Build-Tools
+
+fs = require 'fs'
+{exec} = require 'child_process'
+
+
+task 'module', 'loads needed node.js modules', ->
+
+ out = (err, stdout, stderr) ->
+ throw err if err
+ console.log stdout + stderr
+
+ exec 'npm install express', out
+ exec 'npm install jade', out
+ exec 'npm install stylus', out
+ exec 'npm install coffee-script', out
+ exec 'npm install socket.io', out
+ exec 'npm install redis', out
+ exec 'npm install hiredis', out
+ exec 'npm install async', out
+
+
+
+
+
+# todo:
+
+appFiles = [
+ # omit src/ and .coffee to make the below lines a little shorter
+ 'content/scripts/statusbar'
+ 'content/scripts/command/quickMacro'
+ 'content/scripts/command/selectionTools/general'
+]
+
+task 'build', 'Build single application file from source files', ->
+ appContents = new Array remaining = appFiles.length
+ for file, index in appFiles then do (file, index) ->
+ fs.readFile "src/#{file}.coffee", 'utf8', (err, fileContents) ->
+ throw err if err
+ appContents[index] = fileContents
+ process() if --remaining is 0
+ process = ->
+ fs.writeFile 'lib/app.coffee', appContents.join('\n\n'), 'utf8', (err) ->
+ throw err if err
+ exec 'coffee --compile lib/app.coffee', (err, stdout, stderr) ->
+ throw err if err
+ console.log stdout + stderr
+ fs.unlink 'lib/app.coffee', (err) ->
+ throw err if err
+ console.log 'Done.'
+
+task 'minify', 'Minify the resulting application file after build', ->
+ exec 'java -jar "/home/stan/public/compiler.jar" --js lib/app.js --js_output_file lib/app.production.js', (err, stdout, stderr) ->
+ throw err if err
+ console.log stdout + stderr
@@ -0,0 +1,27 @@
+#-----------------------------------------------------------------
+# ROOT
+root = exports ? this
+
+# append some objects
+#scqrs = if root.scqrs then root.scqrs else {}
+#scqrs.messaging = if scqrs.messaging then scqrs.messaging else {}
+
+socket = io.connect('http://localhost:3031');
+
+#-----------------------------------------------------------------
+# EVENTS
+
+# receive event from socket.io
+socket.on 'events', (data) ->
+ # publish to clientside bus
+ PubSub.publish('events', data)
+
+# receive event from socket.io
+socket.on 'commands', (data) ->
+ # publish to clientside bus
+ PubSub.publish('commands', data)
+
+
+
+
+
@@ -0,0 +1,80 @@
+#-----------------------------------------------------------------
+# ROOT
+root = exports ? this
+
+# append some objects
+#scqrs = if root.scqrs then root.scqrs else {}
+#scqrs.messaging = if scqrs.messaging then scqrs.messaging else {}
+
+# http://stackoverflow.com/questions/4825812/clean-way-to-remove-element-from-javascript-array-with-jquery-coffeescript
+# Array::removeElement = (e) -> @[t..t] = [] if (t = @.indexOf(e)) > -1
+
+class Message
+
+ constructor: (message, elapsed) ->
+ @id = message.id
+ @name = message.command ? message.event
+ @time = message.time
+ @sender = message.sender
+ @raw = message
+ @raw_str = JSON.stringify(message)
+ @payload = message.payload
+ @payload_str = JSON.stringify(message.payload)
+ @elapsed = elapsed ? 'unkown'
+
+class MessageRoundTrip
+
+ constructor: (command) ->
+ @id = command.id
+ @command = new Message(command)
+ @events = ko.observableArray([])
+
+class ViewModel
+
+ constructor: ->
+ @items = ko.observableArray([])
+ @last = ko.observable(0)
+ @_avg = ko.observable(0)
+ @_avg_event_count = ko.observable(0)
+ @average = ko.dependentObservable =>
+ return Math.ceil(@_avg())
+
+ addCommand: (command) ->
+ @items.push(new MessageRoundTrip(command))
+
+
+
+#-----------------------------------------------------------------
+# BOOTSTRAPPER
+
+# add a viewmodel to root
+root.viewmodel = viewmodel = new ViewModel()
+root.msgRoundTrip = MessageRoundTrip
+
+# bind
+ko.applyBindings(root.viewmodel)
+
+# Update viewmodel
+PubSub.subscribe 'commands', (msg, data) ->
+ data.time = new Date(data.time)
+ viewmodel.addCommand(data)
+
+PubSub.subscribe 'events', (msg, data) ->
+ data.time = new Date(data.time)
+ match = null
+ for c in viewmodel.items()
+ if match
+ break
+
+ match = c if data.id.indexOf(c.id) > -1
+
+ if match
+ milliseconds = data.time.getTime() - match.command.time.getTime()
+ viewmodel.last(milliseconds)
+
+ avg = (viewmodel._avg() * viewmodel._avg_event_count() + milliseconds) / (viewmodel._avg_event_count() + 1)
+ viewmodel._avg(avg)
+ viewmodel._avg_event_count(viewmodel._avg_event_count() + 1)
+
+ match.events.push(new Message(data, milliseconds))
+
View
@@ -0,0 +1,228 @@
+/*
+colors.js
+
+Copyright (c) 2010 Alexis Sellier (cloudhead) , Marak Squires
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+
+*/
+
+exports.mode = "console";
+
+// prototypes the string object to have additional method calls that add terminal colors
+
+var addProperty = function (color, func) {
+ exports[color] = function(str) {
+ return func.apply(str);
+ };
+ String.prototype.__defineGetter__(color, func);
+}
+
+var isHeadless = (typeof module !== 'undefined');
+['bold', 'underline', 'italic', 'inverse', 'grey', 'black', 'yellow', 'red', 'green', 'blue', 'white', 'cyan', 'magenta'].forEach(function (style) {
+
+ // __defineGetter__ at the least works in more browsers
+ // http://robertnyman.com/javascript/javascript-getters-setters.html
+ // Object.defineProperty only works in Chrome
+ addProperty(style, function () {
+ return isHeadless ?
+ stylize(this, style) : // for those running in node (headless environments)
+ this.replace(/( )/, '$1'); // and for those running in browsers:
+ // re: ^ you'd think 'return this' works (but doesn't) so replace coerces the string to be a real string
+ });
+});
+
+// prototypes string with method "rainbow"
+// rainbow will apply a the color spectrum to a string, changing colors every letter
+addProperty('rainbow', function () {
+ if (!isHeadless) {
+ return this.replace(/( )/, '$1');
+ }
+ var rainbowcolors = ['red','yellow','green','blue','magenta']; //RoY G BiV
+ var exploded = this.split("");
+ var i=0;
+ exploded = exploded.map(function(letter) {
+ if (letter==" ") {
+ return letter;
+ }
+ else {
+ return stylize(letter,rainbowcolors[i++ % rainbowcolors.length]);
+ }
+ });
+ return exploded.join("");
+});
+
+function stylize(str, style) {
+ if (exports.mode == 'console') {
+ var styles = {
+ //styles
+ 'bold' : ['\033[1m', '\033[22m'],
+ 'italic' : ['\033[3m', '\033[23m'],
+ 'underline' : ['\033[4m', '\033[24m'],
+ 'inverse' : ['\033[7m', '\033[27m'],
+ //grayscale
+ 'white' : ['\033[37m', '\033[39m'],
+ 'grey' : ['\033[90m', '\033[39m'],
+ 'black' : ['\033[30m', '\033[39m'],
+ //colors
+ 'blue' : ['\033[34m', '\033[39m'],
+ 'cyan' : ['\033[36m', '\033[39m'],
+ 'green' : ['\033[32m', '\033[39m'],
+ 'magenta' : ['\033[35m', '\033[39m'],
+ 'red' : ['\033[31m', '\033[39m'],
+ 'yellow' : ['\033[33m', '\033[39m']
+ };
+ } else if (exports.mode == 'browser') {
+ var styles = {
+ //styles
+ 'bold' : ['<b>', '</b>'],
+ 'italic' : ['<i>', '</i>'],
+ 'underline' : ['<u>', '</u>'],
+ 'inverse' : ['<span style="background-color:black;color:white;">', '</span>'],
+ //grayscale
+ 'white' : ['<span style="color:white;">', '</span>'],
+ 'grey' : ['<span style="color:grey;">', '</span>'],
+ 'black' : ['<span style="color:black;">', '</span>'],
+ //colors
+ 'blue' : ['<span style="color:blue;">', '</span>'],
+ 'cyan' : ['<span style="color:cyan;">', '</span>'],
+ 'green' : ['<span style="color:green;">', '</span>'],
+ 'magenta' : ['<span style="color:magenta;">', '</span>'],
+ 'red' : ['<span style="color:red;">', '</span>'],
+ 'yellow' : ['<span style="color:yellow;">', '</span>']
+ };
+ } else {
+ console.log('unsupported mode, try "browser" or "console"');
+ }
+
+ return styles[style][0] + str + styles[style][1];
+};
+
+// don't summon zalgo
+addProperty('zalgo', function () {
+ return zalgo(this);
+});
+
+// please no
+function zalgo(text, options) {
+ var soul = {
+ "up" : [
+ '̍','̎','̄','̅',
+ '̿','̑','̆','̐',
+ '͒','͗','͑','̇',
+ '̈','̊','͂','̓',
+ '̈','͊','͋','͌',
+ '̃','̂','̌','͐',
+ '̀','́','̋','̏',
+ '̒','̓','̔','̽',
+ '̉','ͣ','ͤ','ͥ',
+ 'ͦ','ͧ','ͨ','ͩ',
+ 'ͪ','ͫ','ͬ','ͭ',
+ 'ͮ','ͯ','̾','͛',
+ '͆','̚'
+ ],
+ "down" : [
+ '̖','̗','̘','̙',
+ '̜','̝','̞','̟',
+ '̠','̤','̥','̦',
+ '̩','̪','̫','̬',
+ '̭','̮','̯','̰',
+ '̱','̲','̳','̹',
+ '̺','̻','̼','ͅ',
+ '͇','͈','͉','͍',
+ '͎','͓','͔','͕',
+ '͖','͙','͚','̣'
+ ],
+ "mid" : [
+ '̕','̛','̀','́',
+ '͘','̡','̢','̧',
+ '̨','̴','̵','̶',
+ '͜','͝','͞',
+ '͟','͠','͢','̸',
+ '̷','͡',' ҉'
+ ]
+ },
+ all = [].concat(soul.up, soul.down, soul.mid),
+ zalgo = {};
+
+ function randomNumber(range) {
+ r = Math.floor(Math.random()*range);
+ return r;
+ };
+
+ function is_char(character) {
+ var bool = false;
+ all.filter(function(i){
+ bool = (i == character);
+ });
+ return bool;
+ }
+
+ function heComes(text, options){
+ result = '';
+ options = options || {};
+ options["up"] = options["up"] || true;
+ options["mid"] = options["mid"] || true;
+ options["down"] = options["down"] || true;
+ options["size"] = options["size"] || "maxi";
+ var counts;
+ text = text.split('');
+ for(var l in text){
+ if(is_char(l)) { continue; }
+ result = result + text[l];
+
+ counts = {"up" : 0, "down" : 0, "mid" : 0};
+
+ switch(options.size) {
+ case 'mini':
+ counts.up = randomNumber(8);
+ counts.min= randomNumber(2);
+ counts.down = randomNumber(8);
+ break;
+ case 'maxi':
+ counts.up = randomNumber(16) + 3;
+ counts.min = randomNumber(4) + 1;
+ counts.down = randomNumber(64) + 3;
+ break;
+ default:
+ counts.up = randomNumber(8) + 1;
+ counts.mid = randomNumber(6) / 2;
+ counts.down= randomNumber(8) + 1;
+ break;
+ }
+
+ var arr = ["up", "mid", "down"];
+ for(var d in arr){
+ var index = arr[d];
+ for (var i = 0 ; i <= counts[index]; i++)
+ {
+ if(options[index]) {
+ result = result + soul[index][randomNumber(soul[index].length)];
+ }
+ }
+ }
+ }
+ return result;
+ };
+ return heComes(text);
+}
+
+addProperty('stripColors', function() {
+ return ("" + this).replace(/\u001b\[\d+m/g,'');
+});
Oops, something went wrong.

0 comments on commit cdb43f0

Please sign in to comment.