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 / timelord.js
Last active January 5, 2021 15:39
TimeLord.js: hack javascript's sense of time
window.TimeLord = (function(){
/*
# Time accounted for
Date.now()
window.performance.now()
window.setInterval(...)
window.setTimeout(...)
window.requestAnimationFrame(...)
# Not accounted for
@haxiomic
haxiomic / url.js
Created July 25, 2016 13:29
JavaScript URL parsing with regex - fallback for when window.URL isn't available
(function(URL, parent){
var initialConstructor = parent.URL;
var urlPattern = new RegExp(
"^" +
//protocol
"(?:((?:\\w+):)?/?/?)" +
//user:pass
"(?:(?:([^:]*)(?::([^@]*))?)?@)?" +
@haxiomic
haxiomic / Partial.hx
Last active February 26, 2023 11:44
Haxe macro to make all fields of a type optional (similar to Typescript's Partial<T>)
import haxe.macro.Context;
import haxe.macro.Expr;
import haxe.macro.TypeTools;
#if !macro
@:genericBuild(PartialMacro.build())
#end
class Partial<T> {}
class PartialMacro {
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;
/*
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 {
@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,
@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 / 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 / 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 / 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:
*