Skip to content

Instantly share code, notes, and snippets.

View martinwells's full-sized avatar

Martin Wells martinwells

View GitHub Profile
function test()
{
var myBigObject = {};
setTimeout( function()
{
console.log('' + myBigObject);
}, 1000);
}
@martinwells
martinwells / gist:5980517
Created July 12, 2013 00:43
Simple Haxe logging with colors
/**
Simple, colorful logging!
Setup
=====
Somewhere really early in your code do a:
Log.init();
This will setup the logger methods and coloring stuff.
Logging
@martinwells
martinwells / gist:6084333
Created July 25, 2013 22:24
How to extend haxe map classes
// Since you can't do:
// class MyMap<String, String> extends Map<String, String>
// Try...
import haxe.ds.ObjectMap;
class ObjectMyMap extends ObjectMap<String, String>
{
@martinwells
martinwells / gist:6091295
Created July 26, 2013 18:49
PrioritizedQueue class
import haxe.ds.ObjectMap;
/*
Simple prioritized queue. Throw objects at it and you'll always get back things according
to a priority you set. Priorities are retained internally, so you don't need to modify your
objects.
Usage:
// create a queue:
@martinwells
martinwells / gist:6108911
Created July 29, 2013 23:46
structs in haxe
@:publicFields class Struct
{
public function new() {}
}
class MyStruct extends Struct
{
var field1:String;
var field2:String;
var field3:Bool;
@martinwells
martinwells / gist:8813653
Created February 4, 2014 22:29
Haxe generic type comparison
public function compareTypes(a:Dynamic, b:Dynamic)
{
return (Type.getClass(a) != null) ? (Type.getClass(a) == Type.getClass(b)) : (Type.typeof(a) == Type.typeof(b));
}
@martinwells
martinwells / gist:8815829
Created February 5, 2014 01:24
Bash: find size of all files (recursively) using a given name/extension
find . -name "*.png" -mtime -1 | du | awk '{total+=$1} END{print total}'
@martinwells
martinwells / gist:9243014
Created February 27, 2014 02:17
dump a sprite stack
public function dumpSpriteStack(sprite:Sprite)
{
trace(spriteToString(sprite));
var parent:Sprite = cast sprite.parent;
var c = 1;
while (parent != null)
{
var indent = '.';
for (i in 0...c)
@martinwells
martinwells / gist:9419622
Created March 7, 2014 20:41
Launch image for android
class Main extends Sprite
{
private var doneFrame:Bool;
public function new()
{
super();
doneFrame = false;
graphics.beginFill(0xff5555);
@martinwells
martinwells / gist:9539270
Created March 13, 2014 23:24
Cut up an image into chunks
var bitmapData = Assets.getBitmapData(bitmapPath);
_fullWidth = bitmapData.width;
_fullHeight = bitmapData.height;
_chunkSize = chunkSize;
_lastChunkRect = new Rectangle();
_currentChunkRect = new Rectangle();
// it's different! remove the old cached chunk data
FileUtils.rmdir(_cachePath);