Skip to content

Instantly share code, notes, and snippets.

View SmilyOrg's full-sized avatar

Miha Lunar SmilyOrg

View GitHub Profile
@Sunjammer
Sunjammer / BitmapToAscii.hx
Last active March 22, 2021 03:34
Naive bitmap to ascii converter
package;
/**
* Mostly stolen from http://www.codeproject.com/Articles/20435/Using-C-To-Generate-ASCII-Art-From-An-Image
* @author Andreas Rønning
*/
private typedef BMD = {
function getPixel(x:Int, y:Int):Int;
var width(default, never):Int;
var height(default, never):Int;
@nadako
nadako / Main.hx
Last active August 29, 2015 14:02
CoffeeScript-like destructurize. This is now added to https://github.com/nadako/haxe-thingies repository.
using Unpack;
class Main {
static function main() {
f().unpackInto( [ v1, { a: { length: v2 } }, { a: [ v3, _, v4 ] } ] );
trace(v1); // { a: [ 1 ] }
trace(v2); // 2
trace(v3); // 4
trace(v4); // 5
import haxe.macro.Context;
import haxe.macro.Expr;
class EnumAbstractMacro
{
public static function build():Array<Field>
{
var fields = Context.getBuildFields();
var values = [];
@Simn
Simn / Main.hx
Created February 19, 2014 18:29
initLocals macro
class Main {
var arg1:Int;
var arg2:String;
var arg3:Bool;
function new(arg1 = 0, arg2 = "foo", arg3 = false) {
MyMacro.initLocals();
}
@jonvaldes
jonvaldes / Discrete Spiral
Last active May 2, 2016 01:29
Function that generates a discrete spiral from consecutive numbers.
Needed a function would spiral out to cover a tiled world, then remembered these posts by John Carmack:
* https://twitter.com/ID_AA_Carmack/status/308678512099852288
* https://twitter.com/ID_AA_Carmack/status/308676302079160320
Derived the solution with an initial implementation that uses several arrays to calculate positions,
then removed those array values for a more compact implementation. There's probably still room for
improvement, though.
It uses uniform initialisation from c++11, so you'll have to enable compiler support for it if you want
@Bokugene
Bokugene / CGFontToFontData.m
Created February 23, 2012 13:21
Read Table Data from a CGFont, then wrap them into a OTF/TTF font.
typedef struct FontHeader {
int32_t fVersion;
uint16_t fNumTables;
uint16_t fSearchRange;
uint16_t fEntrySelector;
uint16_t fRangeShift;
}FontHeader;
typedef struct TableEntry {
uint32_t fTag;