Skip to content

Instantly share code, notes, and snippets.

View bendmorris's full-sized avatar

Ben Morris bendmorris

View GitHub Profile
@bendmorris
bendmorris / potrace
Last active January 6, 2023 06:48
Potrace script designed for making FontForge pixel fonts
#!/bin/bash
# To use, move the potrace binary to potrace-bin, then place this script
# somewhere on the path so that it'll be found by fontforge.
# After autotracing, you'll need to apply the following transformation:
# scale uniform 10%, using glyph origin as the origin
# get the last parameter passed by fontforge - the name of the temp img file
for last; do true; done
# get all of the other parameters
length=$(($#-1))
@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 / float_test.py
Created January 26, 2014 16:52
Testing whether Python's json module correctly outputs floating point numbers without loss of precision
import random
import json
digits = '0123456789'
for i in range(10000):
ndigits = 10
number = '0.' + ''.join([random.choice(digits) for j in range(ndigits)])
number = number.rstrip('0')
if number.endswith('.'): number += '0'
json_number = json.dumps(float(number))
@bendmorris
bendmorris / gist:7534559
Created November 18, 2013 20:15
PhyloCommons web API use
import urllib2
my_query_url = 'http://phylocommons.org/query/prune=True&format=newick&taxa=Homo+sapiens%2CGorilla+gorilla%2CPan+paniscus%2CPan+troglodytes&tree=bininda-emonds_mammals'
result = urllib2.urlopen(my_query_url)
tree = result.read()
print tree
# ((('Pan paniscus':3.90000,'Pan troglodytes':3.90000)Pan:5.80000,'Homo sapiens':9.70000):3.00000,'Gorilla gorilla':12.70000)Homininae:7.00000;