Skip to content

Instantly share code, notes, and snippets.

View vstarck's full-sized avatar

Valentin Starck vstarck

  • Argentina
View GitHub Profile
@vstarck
vstarck / decorate.js
Last active December 21, 2015 21:49
decorator.js
pkg = {};
pkg.foo = function(a, b, c) {
alert(a + ' ' + b + ' ' + c);
}
pkg.bar = function(a, b) {
alert(a + ' ' + b + ' ');
}
function Parent() {
this.array = [1, 2, 3];
}
function Child() {
}
Child.prototype = new Parent;
@vstarck
vstarck / ForwardingList.js
Last active December 14, 2015 08:28
Implementing High Order Messaging using ES6 proxies.
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 December 14, 2015 07:28
BigIntSum.php
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 December 12, 2015 01:58
Inheriting from native Array using Proxies
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() + ']';
}
@vstarck
vstarck / __noSuchProperty__.js
Created February 1, 2013 21:39
__noSuchProperty__
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 December 12, 2015 01:29
Emulating private properties using ES6 proxies
var myObject = {
__meta__: {
public: ['publicMethod']
},
privateMethod: function() { return 'private'},
publicMethod: function() {return 'public' }
};
var myProxyObject = new Proxy(myObject, {
get: function(target, name) {
<?php
function fizzBuzz($from, $to) {
$fizzActions = array('Fizz', '', '');
$buzzActions = array('Buzz', '', '', '', '');
$text = $fizzActions[$from % 3] . $buzzActions[$from % 5];
$renderAction = array();
$renderAction[$text] = $text;
@vstarck
vstarck / fizzbuzz.2.js
Created January 24, 2013 17:42
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 December 11, 2015 14:18
FizzBuzz without conditional / boolean operators / trycatch / etc
function fizzBuzz(from, to) {
function print() {
var text =
'Fizz,,'.split(',')[from%3] +
'Buzz,,,,'.split(',')[from%5]
var _ = {}
_[text] = ''
_[''] = from