Skip to content

Instantly share code, notes, and snippets.

View shamansir's full-sized avatar

Ulric Wilfred shamansir

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.
*/