This file contains hidden or 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
// result will vary browser wise | |
alert(Object.getOwnPropertyNames(Function.prototype)); |
This file contains hidden or 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
//create a new array method that removes a member | |
Array.prototype.remove = function(member) { | |
var index = this.indexOf(member); | |
if (index > -1) { | |
this.splice(index, 1); | |
} | |
return this; | |
} | |
['poppy', 'sesame', 'plain'].remove('poppy'); //["sesame", "plain"] |
This file contains hidden or 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
// We know typeof has problms, here is a better solution | |
Object.toType = function(obj) { | |
return ({}).toString.call(obj).match(/\s([a-z|A-Z]+)/)[1].toLowerCase(); | |
} | |
// Examples: | |
Object.toType(window); //"global" (all browsers) | |
Object.toType([1,2,3]); //"array" (all browsers) |
This file contains hidden or 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 concatenate(){ | |
// return arguments.join(''); // won't work. arguments is not a real array. | |
// return [].splice.call(arguments,0).join(''); // old 'n busted | |
return Array.prototype.join.call(arguments,''); // new hotness | |
} | |
concatenate('good',2,'go'); | |
// ==> 'good2go' |
This file contains hidden or 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($){ | |
// store original reference to the method | |
var _old = $.fn.method; | |
$.fn.method = function(arg1,arg2){ | |
if ( ... condition ... ) { | |
return .... | |
} else { // do the default |
This file contains hidden or 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
console.log( 104.249834 | 0 ); //104 | |
console.log( 9.999999 | 0 ); // 9 | |
// bitwise operators operators call ToInt32 on each expression to be evaluated |
This file contains hidden or 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 foo = [1, 2, 3, 4, 5, 6]; | |
foo.length = 3; | |
foo; // [1, 2, 3] |
This file contains hidden or 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
<?php | |
/** | |
* | |
* @flatten multi-dimensional array | |
* | |
* @param array $array | |
* | |
* @return array | |
* | |
*/ |
This file contains hidden or 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.extends = function(parent) { | |
var sConstructor = parent.toString(); | |
var aMatch = sConstructor.match( /\s*function (.*)\(/ ); | |
if ( aMatch != null ) { this.prototype[aMatch[1]] = parent; } | |
for (var m in parent.prototype) { | |
this.prototype[m] = parent.prototype[m]; | |
} | |
}; | |
// Note not Dog = Dog.extends(Animal) | |
Dog.extends(Animal); |
This file contains hidden or 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
<?php | |
backup_tables('localhost','root','','lores_new'); | |
/* backup the db OR just a table */ | |
function backup_tables($host,$user,$pass,$name,$tables = '*') | |
{ | |
$link = mysql_connect($host,$user,$pass); |