Skip to content

Instantly share code, notes, and snippets.

Avatar

Valentin Starck vstarck

  • Argentina
View GitHub Profile
@vstarck
vstarck / decorate.js
Last active Dec 21, 2015
decorator.js
View decorate.js
pkg = {};
pkg.foo = function(a, b, c) {
alert(a + ' ' + b + ' ' + c);
}
pkg.bar = function(a, b) {
alert(a + ' ' + b + ' ');
}
View broken.inheritance.js
function Parent() {
this.array = [1, 2, 3];
}
function Child() {
}
Child.prototype = new Parent;
@vstarck
vstarck / ForwardingList.js
Last active Dec 14, 2015
Implementing High Order Messaging using ES6 proxies.
View ForwardingList.js
var ForwardingList = (function () {
var proto = {
constructor:ForwardingList,
size:function () {
return this._array.length;
},
toString:function () {
return 'ForwardingList[' + this._array.toString() + ']';
}
};
@vstarck
vstarck / BigInt.js
Last active Dec 14, 2015
BigIntSum.php
View BigInt.js
function LargeInt(asString) {
this.asString = asString.replace(/^0+/, '');
}
LargeInt.LARGER = 'LARGER';
LargeInt.EQUAL = 'EQUAL';
LargeInt.SMALLER = 'SMALLER';
LargeInt._compare = function(one, another) {
var digitsOne = one.split(''),
@vstarck
vstarck / array.proxy.js
Last active Dec 12, 2015
Inheriting from native Array using Proxies
View array.proxy.js
var List = function() {
return new Proxy({
constructor: List,
_array: [].slice.call(arguments),
size: function() {
return this._array.length;
},
toString: function() {
return 'List[' + this._array.toString() + ']';
}
View __noSuchProperty__.js
var myObject = {
__noSuchProperty__: function(name) {
return name;
}
};
var myProxyObject = new Proxy(myObject, {
get: function(target, name) {
return name in target?
target[name]:
@vstarck
vstarck / private_properties.js
Last active Dec 12, 2015
Emulating private properties using ES6 proxies
View private_properties.js
var myObject = {
__meta__: {
public: ['publicMethod']
},
privateMethod: function() { return 'private'},
publicMethod: function() {return 'public' }
};
var myProxyObject = new Proxy(myObject, {
get: function(target, name) {
View fizzpuzz.php
<?php
function fizzBuzz($from, $to) {
$fizzActions = array('Fizz', '', '');
$buzzActions = array('Buzz', '', '', '', '');
$text = $fizzActions[$from % 3] . $buzzActions[$from % 5];
$renderAction = array();
$renderAction[$text] = $text;
View fizzbuzz.2.js
function fizzBuzz(from, to) {
var text =
'Fizz,,'.split(',')[from%3] +
'Buzz,,,,'.split(',')[from%5]
var _ = {}
_[text] = ''
_[''] = from
@vstarck
vstarck / fizzbuzz.js
Last active Dec 11, 2015
FizzBuzz without conditional / boolean operators / trycatch / etc
View fizzbuzz.js
function fizzBuzz(from, to) {
function print() {
var text =
'Fizz,,'.split(',')[from%3] +
'Buzz,,,,'.split(',')[from%5]
var _ = {}
_[text] = ''
_[''] = from