Skip to content

Instantly share code, notes, and snippets.

View YellowAfterlife's full-sized avatar

Vadym Diachenko YellowAfterlife

View GitHub Profile
@YellowAfterlife
YellowAfterlife / Ext.hx
Created June 25, 2015 20:30
Quite another C-style for-loop macros for Haxe.
class Ext {
/// C-style for-loop. Uses @pleclech's idea but on macros level.
public static macro function cf(init, cond, post, expr) {
#if !display
var func = null;
func = function(expr:haxe.macro.Expr) {
return switch (expr) {
case macro continue: macro { $post; $expr; }
default: haxe.macro.ExprTools.map(expr, func);
}
@YellowAfterlife
YellowAfterlife / ImageReloader.html
Created March 31, 2015 05:57
Reloads an image from path at every given interval and provides pan/zoom controls.
<script type="text/javascript">
var imagePath = "test.png"; // file to reload.
var reloadInterval = 0.5; // how often to reload, in seconds.
</script>
<img id="image" />
<canvas id="canvas"></canvas>
<style type="text/css">
#image {
visibility: hidden;
}
/// buffer_hex(buffer, ?length) : Returns buffer contents as a hexadecimal string.
var o = argument[0], q = buffer_tell(o), d, v, n;
if (argument_count > 1) {
n = argument[1]
} else n = buffer_get_size(o) - q
var sb = buffer_create(n * 3 + 1, buffer_fixed, 1);
repeat (n) {
v = buffer_read(o, buffer_u8)
d = v >> 4
if (d < 10) {
if (wasAlive && life <= 0 && isRealLevel() && type != "") {
if (type == "Bat") global.enemyDeaths[0] += 1;
else if (type == "Snake") global.enemyDeaths[1] += 1;
else if (type == "Spider") global.enemyDeaths[2] += 1;
else if (type == "Giant Spider") global.enemyDeaths[3] += 1;
else if (type == "Caveman") global.enemyDeaths[4] += 1;
else if (type == "Skeleton") global.enemyDeaths[5] += 1;
else if (type == "Zombie") global.enemyDeaths[6] += 1;
else if (type == "Vampire") global.enemyDeaths[7] += 1;
else if (type == "Frog") global.enemyDeaths[8] += 1;
var HxOverrides = function() { };
HxOverrides.cca = function(s,index) {
var x = s.charCodeAt(index);
if(x != x) return undefined;
return x;
};
var Main = function() { };
Main.utf2ints = function(v,r) {
if(r == null) r = []; else r.splice(0,r.length);
var i = -1;
/// ds_list_string(id)
var l = argument0;
var r = "list#" + string(l);
var n = ds_list_size(l);
r += "[" + string(n) + "]{ ";
for (var i = 0; i < n; i++) {
if (i > 0) r += ", "
r += string(l[|i])
}
r += " }"
@YellowAfterlife
YellowAfterlife / resync.bat
Created January 7, 2015 04:05
ResHack script for quickly repackaging icons for GameMaker:Studio. "GM8_.dll" is a copy of original icon DLL file.
:: replace {} with paths appropriate
@{RESHACK}\ResHacker.exe -script {ICONSPATH}\syncIcons.txt
var times, grid, array;
times = 1000 * 1000
grid = ds_grid_create(100, 100)
for (var i = 0; i < 100; i++) array[i, 99] = 0
//
time = get_timer()
repeat (times) val = ds_grid_get(grid, 42, 42)
show_debug_message("ds_grid_get: " + string(get_timer() - time))
//
time = get_timer()
// macros:
macro public static function forc(init, condition, post, block) {
return macro {
$init;
while ($condition) {
var __forc = 0;
do {
$block;
} while (++__forc == 0);
$post;
@YellowAfterlife
YellowAfterlife / haxe-js-for.hx
Created December 27, 2014 15:44
C-style for-loop for Haxe-JS. The real one this time! Requires a git version of Haxe.
class Main {
macro public static function forc(init, condition, post, block) {
return macro untyped __js__("for ({0}; {1}; {2}) {3}", $init, $condition, $post, $block);
}
static function main() {
forc(var i = 0, i < 5, i++, {
trace(i);
trace("..!!");
});
}