This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Array.prototype.unique = (function () { | |
var TYPE_MAP = { | |
'object' : 1, | |
'function' : 1 | |
} | |
return function () { | |
var map = {}, | |
objects = [], | |
unique = []; | |
for (var i = 0, len = this.length; i < len; i++) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function.prototype.bind = function (thisVal) { | |
var target = this, | |
args = [].slice.call(arguments, 1); | |
function f () { | |
return target.apply( | |
this instanceof f ? this : thisVal, | |
args.concat([].slice.call(arguments)) | |
); | |
}; | |
f.prototype = this.prototype; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Applying regex on substring | |
* http://qfox.nl/weblog/237 | |
*/ | |
RegExp.prototype.match = function (str, start) { | |
if (start > 0) { | |
return this.exec(str.slice(start)); | |
} | |
return this.exec(str); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// In ECMA-262 5th edition all methods of Array.prototype are intentionally generic. It means if you pass different | |
// native object than array for the this value, the particular method will work in same way as for array instances. | |
// ECMA-262 does not define how those methods will work if you pass a host object for the this value. That behavior // is implementation dependent. | |
// For example: | |
var arr = []; | |
Array.prototype.push.call(arr, 1, 2); | |
arr[0]; //1 | |
arr[1]; //2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#Name: Radio player | |
#Author: Asen Bozhilov | |
#Version: 1.0.0 | |
#License: MIT | |
#Available radio streams | |
RADIO_NAMES=( | |
"Дарик Радио" | |
"Радио 1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// creates a script load listener | |
function create_script_load_listener(elem, registry_item, flag,onload) { | |
/** | |
* If the garbage collector use reference count for the host objects | |
* code below will eventually leak if `onload' or `onreadystatechange' hasn't triggered. | |
* `onload' and `onreadystatechange' create circular reference trought the internal [[Scope]] | |
* elem -> onload -> [[Scope]] -> Variable Object -> elem | |
*/ | |
elem.onload = elem.onreadystatechange = function() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function func(a, f) { | |
return function (args) { | |
args.__proto__ = a; | |
f.call(this, args); | |
}; | |
}; | |
var f = func({foo : 10, bar : 20}, function (args) { | |
print(args.foo, args.bar); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var def = (function () { | |
var PROTO_SUPPORT = !{__proto__ : null}.toString, | |
hasOwnP = {}.hasOwnProperty; | |
var def; | |
if (PROTO_SUPPORT) { | |
def = function (params, func) { | |
return function (args) { | |
args.__proto__ = params; | |
func.call(this, args); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function setPrototypeOf(obj, proto) { | |
var p = proto; | |
do { | |
if (obj === p) { | |
throw Error('Circular prototype chain'); | |
} | |
} while (p = Object.getPrototypeOf(p)); | |
obj.__proto__ = proto; | |
return obj; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var IMG_EXT = { | |
'.jpg' : 1, | |
'.png' : 1, | |
'.gif': 1, | |
'.jpeg' : 1 | |
}; | |
var ext; | |
if (IMG_EXT[(ext = path.slice(-5))] || IMG_EXT[ext.slice(1)]) { | |
//do something |
OlderNewer