Skip to content

Instantly share code, notes, and snippets.

View shamansir's full-sized avatar
πŸ’­
Noodling

Ulric Wilfred shamansir

πŸ’­
Noodling
View GitHub Profile
@shamansir
shamansir / iterator.js
Created August 30, 2012 14:29
Quick JS Iterator
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++];
@shamansir
shamansir / Evolution of a Python programmer.py
Created September 2, 2012 12:13
Evolution of a Python programmer
#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;
@shamansir
shamansir / arithmetics._.pegjs
Last active December 27, 2015 01:59
An example of generated parser for PEGjs-fn (http://github.com/shamansir/pegjs-fn)
/*
* 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;
This file has been truncated, but you can view the full file.
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 β”‚
@shamansir
shamansir / arithmethics.pegjs
Last active December 27, 2015 15:29
Comparison between parser generated with Peg-js and parser generated with Peg-js-fn
/*
* 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; }
@shamansir
shamansir / CS_GUIDE.md
Last active August 29, 2015 14:02
JS Player Code Style Guide
@shamansir
shamansir / arithmetics-parser.pegjs-0-6-2.js
Created September 6, 2014 22:39
Comparison between parser generated with `pegjs` and parser generated with `pegjs-fn` – 2
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.
*/