Skip to content

Instantly share code, notes, and snippets.

View bendmorris's full-sized avatar

Ben Morris bendmorris

View GitHub Profile
@bendmorris
bendmorris / hellogc.kit
Created March 30, 2019 18:55
Kit GameCube example
// adapted from the original acube demo by tkcne.
// enjoy
include "stdlib.h";
include "string.h";
include "malloc.h";
include "math.h";
include "gccore.h";
include "stdio.h";
@bendmorris
bendmorris / test.kit
Created October 26, 2018 23:18
Kit: trait method forwarding
trait MyTrait {
public function doSomething(): Void;
}
abstract MyType: Int {
rules {
($this.doSomething) => $this.MyTrait.doSomething;
}
}
@bendmorris
bendmorris / test.kit
Last active October 26, 2018 18:36
Kit: additive blending
abstract Color: Uint32 {
rules {
(${a: Color} + ${b: Color}) =>
((($a & 0xff0000) + ($b & 0xff0000)) & 0xff0000) +
((($a & 0xff00) + ($b & 0xff00)) & 0xff00) +
((($a & 0xff) + ($b & 0xff)) & 0xff) as Color;
}
}
function main() {
@bendmorris
bendmorris / test.kit
Created October 19, 2018 21:50
Kit allocator example
import kit.mem;
struct MyStruct {
public var x: Int;
public var y: Int;
public static function new(allocator: Box[Allocator]): Ptr[MyStruct] {
var newValue: Ptr[MyStruct] = allocator.alloc(sizeof MyStruct);
newValue.x = 1;
newValue.y = 2;
@bendmorris
bendmorris / AssertTest.hx
Created March 2, 2018 17:47
Haxe assert macro
import haxe.macro.Context;
import haxe.macro.Expr;
import haxe.macro.ExprTools;
class AssertTest {
macro public static function assert(e:ExprOf<Bool>) {
#if debug
var assertion = ExprTools.toString(e);
return macro {
if (!$e) {
@bendmorris
bendmorris / Dockerfile
Last active February 23, 2018 17:22
try-haxe Dockerfile
FROM ubuntu:latest
RUN apt-get update
RUN apt-get install -y haxe php7.0 apache2 libapache2-mod-php7.0
RUN mkdir -p /var/www/try-haxe
RUN a2enmod php7.0
RUN a2enmod rewrite
COPY try-haxe.conf /etc/apache2/sites-enabled/000-default.conf
EXPOSE 80
@bendmorris
bendmorris / Flx9SliceSprite.hx
Created September 4, 2016 16:29
Flx9SliceSprite, which simply moves and scales 9 other FlxSprites
package flixel;
import flixel.FlxSprite;
import flixel.graphics.FlxGraphic;
import flixel.graphics.frames.FlxImageFrame;
import flixel.math.FlxPoint;
import flixel.math.FlxRect;
import flixel.system.FlxAssets;
import flixel.util.FlxColor;
@bendmorris
bendmorris / gist:5219affdd32efc08eedc
Created August 11, 2015 03:40
Replace member in Graphiclist (HaxePunk)
function replace(graphicList:Graphiclist, search:Graphic, replace:Graphic) {
var children = graphicList.children;
var index = children.indexOf(search);
if (index > -1) {
children[index] = replace;
}
}
@bendmorris
bendmorris / MapArray.hx
Last active August 29, 2015 14:19
MapArray - array with linked hashmap for fast existence/position lookups
class MapArray<T>
{
public static function main()
{
var x = new MapArray<Int>(new Map<Int, Int>());
for (i in 1 ... 100001)
x.push(i);
x.remove(5002);
@bendmorris
bendmorris / gist:2f3013c32fd2c6baccf4
Created December 27, 2014 20:49
Count # of files and total lines by file type, in all git repos starting from the current directory
#!/bin/bash
DIR=$(pwd)
REPOS=$(find . -type d -name .git)
echo "-- Directory: " $DIR
echo "-- Repos: " $REPOS
for i in hx py xml; do
echo $i