diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 61a2938..0000000 --- a/LICENSE +++ /dev/null @@ -1,22 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2015 Borys Levytskyi - -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. - diff --git a/README.md b/README.md deleted file mode 100644 index 16614e7..0000000 --- a/README.md +++ /dev/null @@ -1,6 +0,0 @@ -# BitwiseCmd -[Bitwise Operations Visualised](http://bitwisecmd.com/) - -Web App that rolls on wheels that I most certainly had to reinvent myself. Nuff said. - -It helps better understand how bitwise operations are pefromed by displaying bytes in a way you can actually see what is going on there during AND, OR, XOR or shift operations. diff --git a/app/analytics.js b/app/analytics.js deleted file mode 100644 index 0520fc7..0000000 --- a/app/analytics.js +++ /dev/null @@ -1,33 +0,0 @@ -app.compose(function(){ - var trackedDomains = { 'bitwisecmd.com': 'UA-61569164-1', 'borislevitskiy.github.io': 'UA-61569164-1' }; - - var host = window.location.host.toLowerCase(); - - if(trackedDomains.hasOwnProperty(host)) { - var trackingCode = trackedDomains[host]; - setTimeout(doTrackAsync, 300); - } - - function doTrackAsync() { - try - { - doTrack(trackingCode); - console.info('View tracked successfully'); - } - catch(err) { - console.error('Failed to start tracking:', err); - } - } - - function doTrack(trackingCode) { - - (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ - (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), - m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) - })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); - - var ga = window.ga; - ga('create', trackingCode, 'auto'); - ga('send', 'pageview'); - } -}); diff --git a/app/app.js b/app/app.js deleted file mode 100644 index b53aa72..0000000 --- a/app/app.js +++ /dev/null @@ -1,23 +0,0 @@ -(function (core) { - "use strict"; - - var di = new core.Container(); - - var app = new core.AppShell(di); - - app.set('cmdConfig', core.ObservableObject.create({ - emphasizeBytes: true - })); - - app.debugMode = false; - - app.bootstrap = function(rootViewElement) { - this.rootViewElement = rootViewElement; - this.set('rootView', rootViewElement) - this.initialize(); - }; - - - window.app = app; - -})(window.core); \ No newline at end of file diff --git a/app/bitwise/calc.js b/app/bitwise/calc.js deleted file mode 100644 index 4be9450..0000000 --- a/app/bitwise/calc.js +++ /dev/null @@ -1,24 +0,0 @@ -app.compose(function() { - "use strict"; - - var should = app.get('should') - app.set('calc', { - - numberOfBits: function (num) { - should.bePositiveInteger(num); - return Math.floor(Math.log(num) / Math.log(2)) + 1; - }, - - maxNumberOfBits: function (arr) { - - var counts = [], num; - for (var i = 0; i < arr.length; i++) { - num = arr[i]; - counts.push(this.numberOfBits(num)); - } - - return Math.max.apply(null, counts); - } - }); - -}); diff --git a/app/bitwise/expression.js b/app/bitwise/expression.js deleted file mode 100644 index 0040fbe..0000000 --- a/app/bitwise/expression.js +++ /dev/null @@ -1,52 +0,0 @@ -app.compose(function() { - "use strict"; - - var twoOperandsRegex = /^(\d+)\s*(<<|>>|\||\&|\^)\s*(\d+)$/; - var numbersList = /^((\d*)+\s?)+$/; - - app.set('expression', { - canParse: function(string) { - return twoOperandsRegex.test(string) || numbersList.test(string); - }, - parse: function(string) { - var trimmed = string.replace(/^\s+|\s+$/, ''); - var matches = twoOperandsRegex.exec(trimmed); - - if(matches != null) { - return createCalculableExpression(matches); - } - - matches = numbersList.exec(string); - if(matches != null) { - return createListOfNumbersExpression(string) - } - } - }); - - function createCalculableExpression(matches) { - - var o1 = parseInt(matches[1], 10); - var o2 = parseInt(matches[3], 10); - - var m = new app.models.BitwiseOperation(); - m.operand1 = o1; - m.operand2 = o2; - m.sign = matches[2]; - m.string = matches.input; - m.result = eval(matches.input); - - return m; - } - - function createListOfNumbersExpression(input) { - var numbers = []; - input.split(' ').forEach(function(n){ - if(n.trim().length > 0) { - numbers.push(parseInt(n)); - } - - }); - - return new app.models.BitwiseNumbers(numbers); - } -}); \ No newline at end of file diff --git a/app/bitwise/formatter.js b/app/bitwise/formatter.js deleted file mode 100644 index 00d1123..0000000 --- a/app/bitwise/formatter.js +++ /dev/null @@ -1,27 +0,0 @@ -app.compose(function() { - "use strict"; - - var should = app.get('should'); - app.set("formatter", { - toBinaryString: function(num, totalLength) { - - var binaryStr = num.toString(2), - formatted = [], - i; - - if(totalLength != null) { - should.bePositiveInteger(totalLength); - } - - for(i = 0; i formatted.length) { - formatted.unshift('0'); - } - - return formatted.join(''); - } - }); -}) diff --git a/app/cmd/cmd.js b/app/cmd/cmd.js deleted file mode 100644 index 55ea549..0000000 --- a/app/cmd/cmd.js +++ /dev/null @@ -1,94 +0,0 @@ -app.compose(function() { - "use strict"; - - app.set('cmd', function() { - var handlers = []; - var is = app.get('is'); - var cmdController = app.controller('cmdController'); - - return { - execute: function(rawInput) { - var input = rawInput.trim().toLowerCase(); - var handler = findHandler(input); - - if(handler != null) { - if(app.debugMode) { - invokeHandler(input, handler); - } else { - try { - invokeHandler(input, handler); - } catch (e) { - displayCommandError(input, "Error: " + e); - } - } - } - else { - displayCommandError(input, "Unsupported expression: " + input.trim()); - } - }, - commands: function(catalog) { - for(var key in catalog) { - if(catalog.hasOwnProperty(key)) { - this.command(key, catalog[key]); - } - } - }, - command: function(cmd, handler) { - var h = createHandler(cmd, handler); - if(h == null){ - console.warn('unexpected set of arguments: ', Array.prototype.splice.call(arguments)); - return; - } - - if(!is.aFunction(h.canHandle)) { - console.warn('handler is missing "canHandle" function. registration denied.'); - return; - } - - if(!is.aFunction(h.handle)) { - console.warn('handler is missing "handle" function. registration denied.'); - return; - } - - handlers.push(h); - }, - clear: function() { - cmdController.clear(); - } - }; - - function displayCommandError(input, message) { - var error = new app.models.ErrorResult(message); - cmdController.display(new app.models.DisplayResult(input, error)); - } - - function invokeHandler (input, handler) { - var cmdResult = handler.handle(input); - if(cmdResult != null) { - var r = new app.models.DisplayResult(input, cmdResult); - cmdController.display(r); - } - } - - function createHandler (cmd, handler) { - if(is.plainObject(cmd)) { - return cmd; - } - - if(is.string(cmd)) { - return { canHandle: function (input) { return input === cmd; }, handle: handler }; - } - - return null; - } - - function findHandler (input) { - var i= 0; - for(i;i self.historyIndex) { // up - args.target.value = self.history[self.historyIndex++]; - - } - - args.preventDefault(); - return; - } - - if(args.keyCode == 40) { - - if(self.historyIndex > 0) { // up - args.target.value = self.history[--self.historyIndex]; - } - - args.preventDefault(); - } - }) - } - } - }); - - app.controller('cmdController', function() { - var html = app.get('html'); - - return { - clear: function () { - this.viewElement.innerHTML = ''; - }, - display: function ( model) { - var view = app.buildViewFor(model); - - var vw = this.viewElement; - if(vw.childNodes.length == 0) { - vw.appendChild(view); - } - else { - vw.insertBefore(view, vw.childNodes[0]); - } - } - }; - }); - - app.controller('configPanelCtrl', { - onViewAttached: function (){ - var self = this; - var cfg = app.get('cmdConfig'); - self.update(cfg); - - cfg.observe(function(){ - self.update(cfg); - }); - }, - update: function (cfg) { - var emIndicator = this.viewElement.querySelector('#emphasizeBytes'); - var reg = /\son/g; - - if(cfg.emphasizeBytes) { - emIndicator.classList.add("on"); - } else { - emIndicator.classList.remove("on"); - } - } - }); -}); - - diff --git a/app/modelViews.js b/app/modelViews.js deleted file mode 100644 index f32c44a..0000000 --- a/app/modelViews.js +++ /dev/null @@ -1,98 +0,0 @@ -// Expression View -app.compose(function () { - "use strict"; - - var formatter = app.get('formatter'); - var calc = app.get('calc'); - var html = app.get('html'); - var cmdConfig = app.get('cmdConfig'); - - app.modelView(app.models.BitwiseOperation, { - renderView: function(expr) { - var maxLen = getBinaryLength([expr.operand1, expr.operand2, expr.result]); - - expr.operand1Binary = formatter.toBinaryString(expr.operand1, maxLen); - expr.operand2Binary = formatter.toBinaryString(expr.operand2, maxLen); - expr.resultBinary = formatter.toBinaryString(expr.result, maxLen); - - var templateId = /<<|>>/.test(expr.sign) ? 'shiftExpressionView' : 'binaryExpressionView'; - var template = app.template(templateId) - - var el = template.render(expr); - colorizeBits(el); - return el; - } - }); - - app.modelView(app.models.BitwiseNumbers, { - renderView: function(model) { - var maxLen = getBinaryLength(model.numbers); - var table = html.element('
'); - - model.numbers.forEach(function(o){ - - var row = table.insertRow(); - var decCell = row.insertCell(); - - decCell.className = 'label'; - - var binCell = row.insertCell(); - binCell.className = 'bin'; - - decCell.textContent = o; - binCell.textContent = formatter.toBinaryString(o, maxLen); - }); - - colorizeBits(table); - return table; - } - }); - - app.modelView(app.models.ViewResult, { - renderView: function(model) { - var template = app.template(model.template); - return template.render(); - } - }); - - app.modelView(app.models.ErrorResult, { - renderView: function(model) { - return html.element('
{message}
', model); - } - }); - - app.modelView(app.models.DisplayResult, { - renderView: function(model) { - var resultView = app.template('resultView').render(model); - var contentView = app.buildViewFor(model.content); - resultView.querySelector('.content').appendChild(contentView); - return resultView; - } - }); - - function getBinaryLength(arr) { - var bits = calc.maxNumberOfBits(arr); - if(cmdConfig.emphasizeBytes && bits % 8 != 0) { - if(bits < 8) { - return 8; - } - - var n = bits - (bits % 8); - return n + 8; - } - return bits; - } - - function colorizeBits(container) { - var list = container.querySelectorAll('.bin'); - Array.prototype.forEach.call(list, function(el){ - var bin = el.textContent; - - el.innerHTML = bin - .replace(/(\d{8})/g, '$1') - .replace(/0/g, '0') - .replace(/1/g, '1'); - }); - } -}); - diff --git a/app/models.js b/app/models.js deleted file mode 100644 index 79d86e3..0000000 --- a/app/models.js +++ /dev/null @@ -1,34 +0,0 @@ -(function(app) { - "use strict"; - - function BitwiseOperation () { - } - - BitwiseOperation.prototype.calculate = function () { - return eval(this.string); - }; - - function BitwiseNumbers(numbers) { - this.numbers = numbers; - } - - function ErrorResult(message) { - this.message = message; - } - - function ViewResult (template) { - this.template = template; - } - - function DisplayResult (input, content) { - this.input = input; - this.content = content; - } - - app.models.BitwiseOperation = BitwiseOperation; - app.models.BitwiseNumbers = BitwiseNumbers; - app.models.ErrorResult = ErrorResult; - app.models.ViewResult = ViewResult; - app.models.DisplayResult = DisplayResult; - -})(window.app); diff --git a/app/services.js b/app/services.js deleted file mode 100644 index eaea2ce..0000000 --- a/app/services.js +++ /dev/null @@ -1,85 +0,0 @@ -(function(app, core){ - "use strict"; - - app.set('html', core.HtmlBuilder); - app.set('is', core.is); - app.set('should', core.should); - app.set('bindr', core.bindr); - - // Save config in local store - app.run(function() { - var cfg = app.get('cmdConfig'); - var storeKey = 'cmdConfig'; - - load(); - - cfg.observe(function(property, value){ - save(); - }); - - function save() { - localStorage.setItem(storeKey, JSON.stringify(cfg.store())); - } - - function load() { - var json = localStorage.getItem(storeKey), stored; - if(core.is.string(json)) { - stored = JSON.parse(json); - for(var key in stored) { - cfg[key] = stored[key]; - } - } - } - }); - - app.set('shell', function(){ - var rootView = app.get('rootView'); - - return { - setDarkTheme: function() { - rootView.classList.remove('light'); - rootView.classList.add('dark'); - }, - setLightTheme: function() { - rootView.classList.remove('dark'); - rootView.classList.add('light'); - } - } - }); -/* - var template = { - compile: function (template) { - var regex = /(?:{([^}]+)})/g; - - var sb = []; - - sb.push('(function() {') - sb.push('return function (model) { ') - sb.push('\tvar html = [];') - sb.push('\twith (model) { ') - var m, index = 0; - while ((m = regex.exec(template)) !== null) { - if(m.index > index) { - sb.push("\t\thtml.push('" + normalize(template.substr(index, m.index - index)) + "');"); - } - sb.push('\t\thtml.push(' + m[1] + ');'); - index = m.index + m[0].length; - } - - if(index < template.length - 1) { - sb.push("\t\thtml.push('" + normalize(template.substr(index, template.length - index)) + "');"); - } - sb.push('\t}'); - sb.push("\treturn html.join('');"); - sb.push('}'); - sb.push('})()') - console.log(sb.join('\r\n')); - return eval(sb.join('\r\n')); - } - }; - - function normalize(str) { - return str.replace(/(\r|\n)+/g, '').replace("'", "\\\'"); - } - */ -})(window.app, window.core); \ No newline at end of file diff --git a/components/commandsFeature.js b/components/commandsFeature.js deleted file mode 100644 index 7ce4c51..0000000 --- a/components/commandsFeature.js +++ /dev/null @@ -1,57 +0,0 @@ -(function(app, core){ - "use strict"; - - var should = core.should; - - function Command(name) { - this.name = name; - this.executionHandlers = []; - } - - Command.prototype.execute = function (cmdArgs) { - cmdArgs = cmdArgs || {}; - cmdArgs.commandHandled = false; - - for(var i=0; i 0) { - if(arr[i] === item) { - return true; - } - } - - return false; - } - - core.Container = Container; -})(window.core); diff --git a/core/htmlBuilder.js b/core/htmlBuilder.js deleted file mode 100644 index 31f1b36..0000000 --- a/core/htmlBuilder.js +++ /dev/null @@ -1,62 +0,0 @@ -(function(core){ - "use strict"; - - var HtmlBuilder = {}; - var should = core.should; - - HtmlBuilder.element = function(template, model) { - var el = document.createElement('div'); - el.innerHTML = HtmlBuilder.template(template, model); - return el.children[0]; - }; - - HtmlBuilder.template = function(template, model) { - should.beString(template, "template"); - var regex = /(?:{([^}]+)})/g, html; - - if(model == null){ - html = template; - } else { - html = template.replace(regex, function(m, g1) { - return HtmlBuilder.escapeHtml(model[g1]); - }); - } - - return html; - }; - - function getAttributesStr(attr) { - if(attr == null) { - return ''; - } - var str = []; - - for(var key in attr) { - if(key == 'html') - continue; - str.push(key + '="' + HtmlBuilder.escapeHtml(attr[key]) + '"'); - } - - return str.join(' '); - } - - HtmlBuilder.escapeHtml = function(obj) { - if(obj == null) { - return obj; - } - - if(typeof obj != 'string') { - obj = obj.toString(); - } - - return obj - .replace(/&/g, "&") - .replace(//g, ">") - .replace(/"/g, """) - .replace(/'/g, "'"); - }; - - core.HtmlBuilder = HtmlBuilder; - -})(window.core); \ No newline at end of file diff --git a/core/is.js b/core/is.js deleted file mode 100644 index b78c0bf..0000000 --- a/core/is.js +++ /dev/null @@ -1,33 +0,0 @@ -(function(){ - "use strict"; - - window.core.is = { - plainObject: function(obj) { - return typeof obj == "object" && obj instanceof Object; - }, - - aFunction: function (obj) { - return typeof obj == "function"; - }, - - string: function (obj) { - return typeof obj == "string"; - }, - - regex: function (obj) { - return typeof obj == "object" && this.constructedFrom(RegExp); - }, - - constructedFrom: function (obj, ctor) { - return obj instanceof ctor; - }, - - htmlElement: function(obj) { - return obj instanceof HtmlElement; - }, - - array: function(obj) { - return obj instanceof Array; - } - }; -})(); diff --git a/core/observable.js b/core/observable.js deleted file mode 100644 index 1bf1bec..0000000 --- a/core/observable.js +++ /dev/null @@ -1,80 +0,0 @@ -(function(core){ - "use strict"; - var is = core.is; - - function ObservableObject () { - this.$store = {}; - this.$executionHandlers = []; - } - - ObservableObject.create = function(definition){ - var obj = new ObservableObject(); - - for(var property in definition){ - if(!definition.hasOwnProperty(property)){ - continue; - } - - Object.defineProperty(obj, property, { - get:ObservableObject.createGetter(property), - set:ObservableObject.createSetter(property) - }); - - obj[property] = definition[property]; - } - - return Object.seal(obj); - }; - - ObservableObject.createGetter = function (propertyName, store){ - return function(){ - return this.$store[propertyName]; - } - }; - - ObservableObject.createSetter = function(propertyName, store){ - return function(value){ - this.$store[propertyName] = value; - this.notifyPropertyChanged(propertyName, value); - } - }; - - ObservableObject.prototype.observe = function (property, handler){ - var func; - if(is.aFunction(property)) { - func = property; - } - else if(is.string(property) && is.aFunction(handler)) { - func = function (p, v) { - if(p === property) { - handler(p, v) - } - } - } - else { - console.warn('Unsupported set of arguments: ', arguments); - return; - } - - var handlers = this.$executionHandlers; - var index = handlers.push(func); - return function () { handlers.splice(1, index); } - }; - - ObservableObject.prototype.notifyPropertyChanged = function(propertyName, value){ - this.$executionHandlers.forEach(function(h){ - h(propertyName, value); - }); - }; - - ObservableObject.prototype.store = function() { - return this.$store; - }; - - ObservableObject.prototype.keys = function() { - return Object.keys(this.$store); - }; - - core.ObservableObject = ObservableObject; - -})(window.core); \ No newline at end of file diff --git a/core/should.js b/core/should.js deleted file mode 100644 index bc328ca..0000000 --- a/core/should.js +++ /dev/null @@ -1,34 +0,0 @@ -(function(){ - "use strict"; - - window.core.should = { - beNumber: function (num, name) { - this.check(typeof num == "number" && !isNaN(num), num + " is not a number"); - this.check(isFinite(num), append(name, "is an infinite number")); - }, - - bePositiveInteger: function(num, name) { - this.beNumber(num); - this.check(num >= 0, append(name, "should be positive integer")); - }, - - notBeNull: function (obj, name) { - this.check(obj != null, append(name, "is null or undefined")); - }, - - beString: function(obj, name) { - this.check(typeof obj == "string", "should be a string"); - }, - check: function(assertion, message) { - if(assertion !== true) { - throw new Error (message); - } - } - }; - - function append(name, msg) { - return typeof name == "string" ? name + " " + msg : msg; - } -})(); - - diff --git a/css/styles.css b/css/styles.css index 5895526..85799d0 100644 --- a/css/styles.css +++ b/css/styles.css @@ -1,36 +1 @@ -body { font-family: Verdana; font-size: 0.8em; padding: 20px 100px 0px 100px; margin: 0 } -code { font-size: 1.2em; font-weight: bold; } - -.links { float: right; position: absolute; right: 10px; top: 10px; } -.mono { font-family: monospace; font-size: 1.3em } -.expressionInput { width: 500px; padding: 3px; border: solid 1px lightgray; } - -.result { margin: 10px 10px 30px; } -.result .input { margin-bottom: 10px; } -.result .content { padding-left: 10px} -.result .cur { color: lightgray; margin-right: 5px; } - -.expression .label { font-weight: bold; padding-right: 5px; text-align: right; } -.expression .bin { letter-spacing: 3px; } -.expression .byte { margin: 0 3px; } -.expression .zero { color: #848586 } -.expression .result td { border-top: dotted 1px gray; } -.expression { font-size: 1.5em; font-family: monospace } - -.help { padding: 10px; } -.help ul { list-style-type: none; margin: 0; padding: 0; } -.help p { margin-top: 0 } - -.configPnl .indicator { font-size: 0.7em; background: gray; color: white; padding: 2px 5px; } -.configPnl .on { background: darkblue; } - -.error { color: maroon; } - -#view { padding: 10px} - -/* Light */ -.light .one { color: black; } -/* Dark */ -.dark { background: black; color: white;} -.dark .expressionInput { background: black; color: white; } -.dark a, .dark a:visited { color: white; } \ No newline at end of file +body{font-family:Verdana;font-size:.8em;padding:20px 100px 0 100px;margin:0}.expression,.mono{font-family:monospace}code{font-size:1.2em;font-weight:700}.links{float:right;position:absolute;right:10px;top:10px}.mono{font-size:1.3em}.expressionInput{width:500px;padding:3px;border:solid 1px #d3d3d3}.result{margin:10px 10px 30px}.result .input{margin-bottom:10px}.result .content{padding-left:10px}.result .cur{color:#d3d3d3;margin-right:5px}.expression .label{font-weight:700;padding-right:5px;text-align:right}.expression .bin{letter-spacing:3px}.expression .byte{margin:0 3px}.expression .result td{border-top:dotted 1px gray}.expression{font-size:1.5em}.help{padding:10px}.help ul{list-style-type:none;margin:0;padding:0}.help p{margin-top:0}.configPnl .indicator{font-size:.7em;background:gray;color:#fff;padding:2px 5px}.configPnl .on{background:#00008b}.error{color:maroon}#view{padding:10px}.light{background:#fafafa}.light .one{color:#000}.light .zero{color:#696a6b}.dark,.dark a,.dark a:visited{color:#fff}.dark{background:#121212}.dark .expressionInput{background:#000;color:#fff}.dark .zero{color:#848586} \ No newline at end of file diff --git a/index.html b/index.html index 19818bd..c1d2280 100644 --- a/index.html +++ b/index.html @@ -7,43 +7,11 @@ BitwiseCmd - - - - - - - + - - - - - - - - - - - - - - - - - + - - diff --git a/js/analytics.js b/js/analytics.js new file mode 100644 index 0000000..20f59af --- /dev/null +++ b/js/analytics.js @@ -0,0 +1,7 @@ +(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ + (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), + m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) +})(window,document,'script','//www.google-analytics.com/analytics.js','ga'); + +ga('create', 'UA-61569164-1', 'auto'); +ga('send', 'pageview'); diff --git a/js/bitwisecmd.js b/js/bitwisecmd.js new file mode 100644 index 0000000..07d94a2 --- /dev/null +++ b/js/bitwisecmd.js @@ -0,0 +1,2 @@ +/*! BitwiseCmd 2015-04-09 */ +window.core={},function(){"use strict";window.core.is={plainObject:function(a){return"object"==typeof a&&a instanceof Object},aFunction:function(a){return"function"==typeof a},string:function(a){return"string"==typeof a},regex:function(a){return"object"==typeof a&&this.constructedFrom(RegExp)},constructedFrom:function(a,b){return a instanceof b},htmlElement:function(a){return a instanceof HtmlElement},array:function(a){return a instanceof Array}}}(),function(){"use strict";function a(a,b){return"string"==typeof a?a+" "+b:b}window.core.should={beNumber:function(b,c){this.check("number"==typeof b&&!isNaN(b),b+" is not a number"),this.check(isFinite(b),a(c,"is an infinite number"))},bePositiveInteger:function(b,c){this.beNumber(b),this.check(b>=0,a(c,"should be positive integer"))},notBeNull:function(b,c){this.check(null!=b,a(c,"is null or undefined"))},beString:function(a,b){this.check("string"==typeof a,"should be a string")},check:function(a,b){if(a!==!0)throw new Error(b)}}}(),function(a){"use strict";function b(a){this.store={},this.resolutionStack=[]}function c(a){if(e(this.resolutionStack,a))throw new Error("Failed to resolve service: "+a+". Circular reference: "+this.resolutionStack.join(" < "));this.resolutionStack.unshift(a);var b=this.store[a];if(null==b)throw new Error(a+" component is not registered");return null==b.resolved&&b.createInstance(),this.resolutionStack.shift(),b.resolved}function d(a){this.def=a,this.resolved=null}function e(a,b){for(var c=a.length;c-->0;)if(a[c]===b)return!0;return!1}var f=a.is;b.prototype.register=function(a,b){var c=this.store[a];return null==c&&(c=b instanceof d?b:new d(b),c.name=a,this.store[a]=c),c},b.prototype.resolve=function(a){return c.call(this,a)},d.prototype.createInstance=function(){var a=this.def;this.resolved="function"==typeof a?a():a,f.aFunction(this.onFirstTimeResolve)&&this.onFirstTimeResolve(this.resolved)},b.Registration=d,a.Container=b}(window.core),function(){"use strict";function a(a){this.models={},this.di=a,this.runList=[],this.compositionList=[]}function b(a){a.forEach(function(a){a()})}a.prototype.get=function(a){return this.di.resolve(a)},a.prototype.set=function(a,b){this.di.register(a,b)},a.prototype.run=function(a){this.runList.push(a)},a.prototype.compose=function(a){this.compositionList.push(a)},a.prototype.initialize=function(){b(this.compositionList),b(this.runList)},window.core.AppShell=a}(),function(a){"use strict";var b={},c=a.should;b.element=function(a,c){var d=document.createElement("div");return d.innerHTML=b.template(a,c),d.children[0]},b.template=function(a,d){c.beString(a,"template");var e,f=/(?:{([^}]+)})/g;return e=null==d?a:a.replace(f,function(a,c){return b.escapeHtml(d[c])})},b.escapeHtml=function(a){return null==a?a:("string"!=typeof a&&(a=a.toString()),a.replace(/&/g,"&").replace(//g,">").replace(/"/g,""").replace(/'/g,"'"))},a.HtmlBuilder=b}(window.core),function(a){"use strict";function b(){this.$store={},this.$executionHandlers=[]}var c=a.is;b.create=function(a){var c=new b;for(var d in a)a.hasOwnProperty(d)&&(Object.defineProperty(c,d,{get:b.createGetter(d),set:b.createSetter(d)}),c[d]=a[d]);return Object.seal(c)},b.createGetter=function(a,b){return function(){return this.$store[a]}},b.createSetter=function(a,b){return function(b){this.$store[a]=b,this.notifyPropertyChanged(a,b)}},b.prototype.observe=function(a,b){var d;if(c.aFunction(a))d=a;else{if(!c.string(a)||!c.aFunction(b))return void console.warn("Unsupported set of arguments: ",arguments);d=function(c,d){c===a&&b(c,d)}}var e=this.$executionHandlers,f=e.push(d);return function(){e.splice(1,f)}},b.prototype.notifyPropertyChanged=function(a,b){this.$executionHandlers.forEach(function(c){c(a,b)})},b.prototype.store=function(){return this.$store},b.prototype.keys=function(){return Object.keys(this.$store)},a.ObservableObject=b}(window.core),function(a){"use strict";var b=new a.Container,c=new a.AppShell(b);c.set("cmdConfig",a.ObservableObject.create({emphasizeBytes:!0})),c.debugMode=!1,c.bootstrap=function(a){this.rootViewElement=a,this.set("rootView",a),this.initialize()},window.app=c}(window.core),function(a,b){"use strict";function c(a){a.attachView=function(b){this.viewElement=b,"function"==typeof a.onViewAttached&&a.onViewAttached(b)},a.detachView=function(){this.viewElement=null,"function"==typeof a.onViewDetached&&a.onViewDetached(viewElement)}}function d(b){for(var c,d,e,f=b.querySelectorAll("[data-controller]"),g=0,h=f.length;h>g;g++)e=f[g],c=e.getAttribute("data-controller"),d=a.controller(c),null!=d?(d.attachView(e),"function"==typeof d.detachView&&e.addEventListener("DOMNodeRemoved",function(a){e===a.target&&d.detachView()})):console.warn(c+" controller wasn't found")}var e=b.should;a.controller=function(a,d){if(e.beString(a,"name"),null==d)return this.get(a);var f=new b.Container.Registration(d);f.onFirstTimeResolve=function(a){c(a)},this.set(a,f)},a.run(function(){d(a.get("rootView"),a.di)})}(window.app,window.core),function(a){"use strict";function b(a){this.html=a}function c(c){var d=c.querySelectorAll("[data-template]"),e=a.templates;Array.prototype.forEach.call(d,function(a){var c=a.getAttribute("data-template");return e[c]instanceof b?void console.warn(c+" templates already registered"):void(e[c]=new b(a.innerHTML))})}b.prototype.render=function(b){return a.get("html").element(this.html,b)},a.templates=[],a.template=function(a){var b=this.templates[a];if(null==b)throw new Error(a+" template is not found");return b},a.run(function(){c(a.get("rootView"))})}(window.app),function(a,b){"use strict";function c(a){return d(a)+"ViewBuilder"}function d(a){var b=a.toString();return b.substr(8,b.indexOf("(")-8).trim()}a.modelView=function(b,d){var e=c(b);a.di.register(e,d)},a.buildViewFor=function(a){var b=c(a.constructor),d=this.di.resolve(b);return d.renderView(a)}}(window.app,window.is),app.compose(function(){function a(){try{b(e),console.info("View tracked successfully")}catch(a){console.error("Failed to start tracking:",a)}}function b(a){!function(a,b,c,d,e,f,g){a.GoogleAnalyticsObject=e,a[e]=a[e]||function(){(a[e].q=a[e].q||[]).push(arguments)},a[e].l=1*new Date,f=b.createElement(c),g=b.getElementsByTagName(c)[0],f.async=1,f.src=d,g.parentNode.insertBefore(f,g)}(window,document,"script","//www.google-analytics.com/analytics.js","ga");var b=window.ga;b("create",a,"auto"),b("send","pageview")}var c={"bitwisecmd.com":"UA-61569164-1","borislevitskiy.github.io":"UA-61569164-1"},d=window.location.host.toLowerCase();if(c.hasOwnProperty(d)){var e=c[d];setTimeout(a,300)}}),app.compose(function(){"use strict";var a=app.get("should");app.set("calc",{numberOfBits:function(b){return a.bePositiveInteger(b),Math.floor(Math.log(b)/Math.log(2))+1},maxNumberOfBits:function(a){for(var b,c=[],d=0;d0&&b.push(parseInt(a))}),new app.models.BitwiseNumbers(b)}var twoOperandsRegex=/^(\d+)\s*(<<|>>|\||\&|\^)\s*(\d+)$/,numbersList=/^((\d*)+\s?)+$/;app.set("expression",{canParse:function(a){return twoOperandsRegex.test(a)||numbersList.test(a)},parse:function(a){var b=a.replace(/^\s+|\s+$/,""),c=twoOperandsRegex.exec(b);return null!=c?createCalculableExpression(c):(c=numbersList.exec(a),null!=c?createListOfNumbersExpression(a):void 0)}})}),app.compose(function(){"use strict";var a=app.get("should");app.set("formatter",{toBinaryString:function(b,c){var d,e=b.toString(2),f=[];for(null!=c&&a.bePositiveInteger(c),d=0;df.length;)f.unshift("0");return f.join("")}})}),app.compose(function(){"use strict";app.set("cmd",function(){function a(a,b){var c=new app.models.ErrorResult(b);g.display(new app.models.DisplayResult(a,c))}function b(a,b){var c=b.handle(a);if(null!=c){var d=new app.models.DisplayResult(a,c);g.display(d)}}function c(a,b){return f.plainObject(a)?a:f.string(a)?{canHandle:function(b){return b===a},handle:b}:null}function d(a){var b=0;for(b;bb.historyIndex&&(a.target.value=b.history[b.historyIndex++]),void a.preventDefault()):void(40==a.keyCode&&(b.historyIndex>0&&(a.target.value=b.history[--b.historyIndex]),a.preventDefault()))})}}}),app.controller("cmdController",function(){app.get("html");return{clear:function(){this.viewElement.innerHTML=""},display:function(a){var b=app.buildViewFor(a),c=this.viewElement;0==c.childNodes.length?c.appendChild(b):c.insertBefore(b,c.childNodes[0])}}}),app.controller("configPanelCtrl",{onViewAttached:function(){var a=this,b=app.get("cmdConfig");a.update(b),b.observe(function(){a.update(b)})},update:function(a){var b=this.viewElement.querySelector("#emphasizeBytes");a.emphasizeBytes?b.classList.add("on"):b.classList.remove("on")}})}),app.compose(function(){"use strict";function a(a){var b=d.maxNumberOfBits(a);if(f.emphasizeBytes&&b%8!=0){if(8>b)return 8;var c=b-b%8;return c+8}return b}function b(a){var b=a.querySelectorAll(".bin");Array.prototype.forEach.call(b,function(a){var b=a.textContent;a.innerHTML=b.replace(/(\d{8})/g,'$1').replace(/0/g,'0').replace(/1/g,'1')})}var c=app.get("formatter"),d=app.get("calc"),e=app.get("html"),f=app.get("cmdConfig");app.modelView(app.models.BitwiseOperation,{renderView:function(d){var e=a([d.operand1,d.operand2,d.result]);d.operand1Binary=c.toBinaryString(d.operand1,e),d.operand2Binary=c.toBinaryString(d.operand2,e),d.resultBinary=c.toBinaryString(d.result,e);var f=/<<|>>/.test(d.sign)?"shiftExpressionView":"binaryExpressionView",g=app.template(f),h=g.render(d);return b(h),h}}),app.modelView(app.models.BitwiseNumbers,{renderView:function(d){var f=a(d.numbers),g=e.element('
');return d.numbers.forEach(function(a){var b=g.insertRow(),d=b.insertCell();d.className="label";var e=b.insertCell();e.className="bin",d.textContent=a,e.textContent=c.toBinaryString(a,f)}),b(g),g}}),app.modelView(app.models.ViewResult,{renderView:function(a){var b=app.template(a.template);return b.render()}}),app.modelView(app.models.ErrorResult,{renderView:function(a){return e.element('
{message}
',a)}}),app.modelView(app.models.DisplayResult,{renderView:function(a){var b=app.template("resultView").render(a),c=app.buildViewFor(a.content);return b.querySelector(".content").appendChild(c),b}})}),function(app){"use strict";function BitwiseOperation(){}function BitwiseNumbers(a){this.numbers=a}function ErrorResult(a){this.message=a}function ViewResult(a){this.template=a}function DisplayResult(a,b){this.input=a,this.content=b}BitwiseOperation.prototype.calculate=function(){return eval(this.string)},app.models.BitwiseOperation=BitwiseOperation,app.models.BitwiseNumbers=BitwiseNumbers,app.models.ErrorResult=ErrorResult,app.models.ViewResult=ViewResult,app.models.DisplayResult=DisplayResult}(window.app),function(a,b){"use strict";a.set("html",b.HtmlBuilder),a.set("is",b.is),a.set("should",b.should),a.set("bindr",b.bindr),a.run(function(){function c(){localStorage.setItem(f,JSON.stringify(e.store()))}function d(){var a,c=localStorage.getItem(f);if(b.is.string(c)){a=JSON.parse(c);for(var d in a)e[d]=a[d]}}var e=a.get("cmdConfig"),f="cmdConfig";d(),e.observe(function(a,b){c()})}),a.set("shell",function(){var b=a.get("rootView");return{setDarkTheme:function(){b.classList.remove("light"),b.classList.add("dark")},setLightTheme:function(){b.classList.remove("dark"),b.classList.add("light")}}})}(window.app,window.core); \ No newline at end of file diff --git a/publish.bat b/publish.bat deleted file mode 100644 index 9012a53..0000000 --- a/publish.bat +++ /dev/null @@ -1,4 +0,0 @@ -git checkout gh-pages -git pull origin master -git push -git checkout master \ No newline at end of file