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 Class() { | |
} | |
Class.prototype = new function() { | |
var value = 100; | |
function getValue() { | |
return value++; | |
} | |
this.getValue = getValue; |
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 toConstantCase() { | |
var a = arguments; | |
if( a.length == 1 ) { | |
return a[0].replace( toConstantCase.REGEX, toConstantCase ).toUpperCase(); | |
} | |
return a[0][0] + "_" + a[0][1] + ( a[0][2] ? a[0][2] : "" ); | |
} | |
toConstantCase.REGEX = /[a-z][A-Z]|[A-Z]{2}[a-z]/g; | |
// |
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 window:Object = {}; | |
new function():void { | |
var shared:Number = 100; | |
/** | |
*/ | |
function Foo():void { | |
this.getNumber = function():Number { |
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
// | |
// Works in Chrome, Firefox, MSIE, Opera and Safari. | |
// | |
function onDOMContentLoaded( event ) { | |
if( event ) { | |
document.removeEventListener( event.type, onDOMContentLoaded, false ); | |
} | |
document.onreadystatechange = null; | |
// do something here... | |
} |
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
new function() { | |
var TRIM = /^\s*(.+?)\s*$/; | |
String.prototype.trim = function() { | |
return this.replace( TRIM, '$1' ); | |
} | |
} |
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
class JSONObject extends stdClass { | |
// Accepts an array, object, or JSON encoded string. | |
public function __construct( $o=null ) { | |
if( $o === null ) { | |
return; | |
} | |
if( is_string( $o ) ) { | |
$o = json_decode( $o ); | |
} |
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
const CHR:Array = [ | |
"A","B","C","D","E","F","G","H","I","J","K","L","M", | |
"N","O","P","Q","R","S","T","U","V","W","X","Y","Z" | |
]; | |
const CHRLEN:Number = CHR.length; | |
function getRandom():String { | |
return CHR[ CHRLEN * Math.random() >> 0 ]; | |
} |
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
const DEGRAD:Number = Math.PI / 180; | |
var iso:Matrix = new Matrix(); | |
iso.rotate( -45 * DEGRAD ); // rotate anti-clockwise by 45 degrees | |
iso.scale( 1.0, 0.5 ); // scale vertically by 50% | |
iso.translate( 100, 100 ); // set position if needed | |
displayObject.transform.matrix = iso; |
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 replace( str:String, search:String, replacement:String ):String { | |
var a:int = search.length; | |
var b:int = replacement.length; | |
var o:int = 0; | |
var i:int; | |
while( ( i = str.indexOf( search, o ) ) != -1 ) { | |
str = str.substr( 0, i ) + replacement + str.substr( i + a ); | |
o = i + b; | |
} | |
return str; |
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
// Counts the number of bytes in a string. | |
function count_bytes( &$str ) { | |
if( ini_get( 'mbstring.func_overload' ) ) { | |
return mb_strlen( $str, '8bit' ); | |
} | |
// Ideally we want strlen() to be used, because it's fast. | |
return strlen( $str ); | |
} |