Open in StackEdit Viewer
Gist: https://gist.github.com/shamansir/faedd62ef62cc8c15582
<style type="text/css"> .positive { color: #006600; } .negative { color: #ff0000; } .neutral { color: #cccc00; }
function iter(a) { | |
if (a.__iter) { | |
a.__iter.reset(); | |
return a.__iter; | |
} | |
var pos = 0, | |
len = a.length; | |
return (a.__iter = { | |
next: function() { | |
if (pos < len) return a[pos++]; |
#Newbie programmer | |
def factorial(x): | |
if x == 0: | |
return 1 | |
else: | |
return x * factorial(x - 1) | |
print factorial(6) | |
#First year programmer, studied Pascal |
// simple observer (pubsub) implementation | |
define(["underscore", "base/classex", "util/logging"], function(_, Class, Logging) { | |
var PubSub = Class.extend({}); | |
PubSub._topics = function() { | |
if (!window.pubsub) { | |
window.pubsub = {}; | |
} | |
return window.pubsub; |
/* | |
* Classic example grammar, which recognizes simple arithmetic expressions like | |
* "2*(3+4)". The parser generated from this grammar then computes their value. | |
*/ | |
start | |
= additive | |
additive | |
= left:multiplicative "+" right:additive { return left + right; } |
module.exports = (function() { | |
/* | |
* Generated by PEG.js 0.7.0. | |
* | |
* http://pegjs.majda.cz/ | |
*/ | |
function peg$subclass(child, parent) { | |
function ctor() { this.constructor = child; } | |
ctor.prototype = parent.prototype; |
module.exports = (function(){ | |
/* | |
* Generated by PEG.js 0.7.0. | |
* | |
* http://pegjs.majda.cz/ | |
*/ | |
function quote(s) { | |
/* | |
* ECMA-262, 5th ed., 7.8.4: All characters may appear literally in a |
// x 10 runs | |
┌─────────────────────────────────────┬───────────┬────────────┬──────────────┐ | |
│ Test │ Inp. size │ Avg. time │ Avg. speed │ | |
├─────────────────────────────────────┴───────────┴────────────┴──────────────┤ | |
│ JSON │ | |
├─────────────────────────────────────┬───────────┬────────────┬──────────────┤ | |
│ Example 1 │ 0.69 kB │ 0.90 ms │ 766.06 kB/s │ | |
│ Example 2 │ 0.24 kB │ 0.30 ms │ 787.76 kB/s │ | |
│ Example 3 │ 0.59 kB │ 0.20 ms │ 2949.22 kB/s │ | |
│ Example 4 │ 3.39 kB │ 0.70 ms │ 4838.17 kB/s │ |
/* | |
* Classic example grammar, which recognizes simple arithmetic expressions like | |
* "2*(3+4)". The parser generated from this grammar then computes their value. | |
*/ | |
start | |
= additive | |
additive | |
= left:multiplicative "+" right:additive { return left + right; } |
Open in StackEdit Viewer
Gist: https://gist.github.com/shamansir/faedd62ef62cc8c15582
module.exports = (function(){ | |
/* Generated by PEG.js 0.6.2 (http://pegjs.majda.cz/). */ | |
var result = { | |
/* | |
* Parses the input with a generated parser. If the parsing is successfull, | |
* returns a value explicitly or implicitly specified by the grammar from | |
* which the parser was generated (see |PEG.buildParser|). If the parsing is | |
* unsuccessful, throws |PEG.parser.SyntaxError| describing the error. | |
*/ |