Skip to content

Instantly share code, notes, and snippets.

View mbolt35's full-sized avatar
:octocat:
Code, code, code...

Matt Bolt mbolt35

:octocat:
Code, code, code...
View GitHub Profile
@mbolt35
mbolt35 / ArrayClass.cpp
Created April 24, 2012 01:48
Vector Dynamic Memory Allocation
// Allocation for Array
ArrayObject* ArrayClass::newarray(Atom* argv, int argc)
{
ArrayObject *inst = newArray(argc);
for (uint32 i=0; i<uint32(argc); i++) {
inst->setUintProperty(i, argv[i]);
}
@mbolt35
mbolt35 / Foo.coffee
Created May 1, 2012 14:53
CoffeeScript Global Class
# Defining a class globally can be done like this:
class Foo
constructor: (@name) ->
this.Foo = Foo;
# Or like this...
this.Foo = class Foo
constructor: (@name) ->
var vec:Vector. = new <int>[ 1, 2, 3 ];
var arr:Array = function(v:Vector.<int>):Array {
var result:Array = [];
for (var i:int = 0; i < v.length; ++i) {
result[i] = v[i];
}
return result;
}(vec);
// This constant is set to the fully qualified class name for Vector
private static const VECTOR_CLASS:String = "__AS3__.vec::Vector";
// Use flash.utils.describeType() on the input, and verify type
// of the object is a Vector class. This is probably fairly
// expensive, a valid point to my argument.
public static function isVector(vector:*):Boolean {
var type:String = flash.utils.describeType(vector).@name;
return type.indexOf(VECTOR_CLASS) != -1;
}
var arr:Array = [ 1, 2, 3 ];
var arr2:Array = [ 3, 2, 1 ];
var result:Array = arr.concat(arr2);
trace(result);
// Outputs: 1,2,3,3,2,1
var arr:Array = [ 1, 2, 3 ];
var result:Array = arr.concat(3, 2, 1);
trace(result);
// Outputs: 1,2,3,3,2,1
// We return -1 if val1 is first, 1 if val2 is first, and 0
// if we don't care - just return a random value between
// -1 and 1
function shuffle(val1:int, val2:int):int {
var random:int = Math.floor(Math.random() * 3) - 1;
return random;
}
var toSort:Array = [ 1, 2, 3, 4, 5 ];
toSort.sort(shuffle);
var vec:Vector.<int> = new <int>[ 1, 2, 3 ];
var vec2:Vector.<int> = new <int>[ 3, 2, 1 ];
var result:Vector.<int> = vec.concat(vec2);
trace(result);
// Outputs: 1,2,3,3,2,1
var vec3:Vector.<int> = new <int>[ 9, 8, 7 ];
result = vec.concat(vec2, vec3);
trace(result);
// Outputs: 1,2,3,3,2,1,9,8,7
// These produce the same Array *structure*, they are not
// strictly equivalent (===)
var oneWay:Array = new Array(1, 2, 3);
var anotherWay:Array = [ 1, 2, 3 ];
// Each of these result with the same Vector.<int>
// *structure*, however they are not strictly
// equivalent (===).
var v1:Vector.<int> = new Vector.<int>(3);
v1[0] = 1; v1[1] = 2; v1[2] = 3;