Skip to content

Instantly share code, notes, and snippets.

View haxiomic's full-sized avatar
:octocat:
Everything is happening

George Corney haxiomic

:octocat:
Everything is happening
View GitHub Profile
@haxiomic
haxiomic / Scope-Preserving-Split.hx
Created April 18, 2019 21:05
Split by character, but not inside scopes
function scopePreservingSplit(str: String, by: String) {
var scopePairs = ['()', '[]', '{}', '<>'];
var scopeState = [0, 0, 0, 0];
var parts = new Array<String>();
var buffer = '';
inline function handleScope(c) {
for (i in 0...scopePairs.length) {
var open = scopePairs[i].charAt(0);
var close = scopePairs[i].charAt(1);
# Global State
[select object]
- activeTexture(unit:TextureUnit)
- bindBuffer(target:BufferTarget, buffer:GLBuffer)
- bindFramebuffer(target:FramebufferTarget, framebuffer:GLFramebuffer)
- bindRenderbuffer(target:RenderbufferTarget, renderbuffer:GLRenderbuffer)
- bindTexture(target:TextureTarget, texture:GLTexture)
- useProgram(program:GLProgram)
[primtive draw state]
@haxiomic
haxiomic / Haxe Makefile
Last active April 1, 2019 08:22
Haxe makefile with file watching. Requires fswatch (`brew install fswatch`)
HXML ?= $(shell find . -name "*.hxml" -print -quit)
SOURCES ?= $(shell find . -name "*.hx")
# Determine output file or directory from target arguments in HXML
OUTPUT ?= $(shell echo ' \
class M { static function main() { \
var r = ~/^\s*-?-(js|lua|swf|as3|neko|php|cpp|cppia|cs|java|python|hl)\s+([^\\n]+)/im; \
if (r.match(sys.io.File.getContent(Sys.args()[0]))) \
Sys.print(r.matched(2)); \
} } \
@haxiomic
haxiomic / MediaElement.hx
Created July 28, 2018 20:00
js/html/MediaElement.hx
/*
* Copyright (C)2005-2018 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
@haxiomic
haxiomic / WebGL2RenderingContext.hx
Created July 28, 2018 18:45
Auto-generated WebGL2RenderingContext externs
/*
* Copyright (C)2005-2018 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
@haxiomic
haxiomic / getType.js
Created July 10, 2018 21:58
Convert JS object to TS type
function getType(x) {
let type = typeof x;
if (type === 'object') {
if (Array.isArray(x)) {
return `Array<${getType(x[0])}>`;
} else {
let fields = [];
for (let key of Object.keys(x)) {
fields.push(`${key}: ${getType(x[key])}`);
}
@haxiomic
haxiomic / GFF3LineParser.ts
Last active June 13, 2018 14:22
Parses genomic feature files in the gff3 format – purely a line-parser in that it does not build up objects but instead calls callbacks for each line-type
/**
* # GFF3 File format
* https://github.com/The-Sequence-Ontology/Specifications/blob/master/gff3.md
*/
export type LineCallbacks = {
// directives
onVersion: (versionString: string) => void,
onSequenceRegion: (seqId: string | null, start: number | null, end: number | null) => void,
onFeatureOntology: (uri: string) => void,
@haxiomic
haxiomic / Spring.ts
Last active April 15, 2018 12:44
Analytic spring integration
// analyitc spring integration
// useful when you want a robust single-spring simulation
stepSpring(
dt_s: number,
state: {
x: number,
v: number,
pe: number, // potential energy
}, parameters: {
tension: number,
/*
Incomplete parser for closure compiler externs
Converts closure externs to haxe classes and modules
Tested using https://github.com/nodebox/opentype.js/tree/master/externs
https://github.com/google/closure-compiler/wiki
*/
class ClosureExternConverter {
package;
import haxe.io.Bytes;
import haxe.io.Input;
@:enum abstract DDSD(UInt) to UInt{
var CAPS = 0x1;
var HEIGHT = 0x2;
var WIDTH = 0x4;
var PITCH = 0x8;