Skip to content

Instantly share code, notes, and snippets.

@jcward
jcward / process.sh
Created January 4, 2017 21:32
Shell script to take errant ImageMagick 6.7 alpha extract into account
# Create alpha mask
convert /tmp/image.png -alpha extract /tmp/alpha.png
# In ImageMagick version 6.7, there was an error with how this alpha channel output. But we
# actually tuned it with that error taken into account. So if you're using a later version
# then we actually want to make the alpha channel darker to look like 6.7 again.
im_version=`convert -version`
if [[ "$im_version" == *"ImageMagick 6.7"* ]]
then
@jcward
jcward / snippet.hx
Created December 20, 2016 16:38
Examining fields up the inheritance chain in a Haxe build macro
// Do we need to mark the new function as override? Check up the inheritance chain
var super_fields:Array<String> = [];
var cls = Context.getLocalClass().get();
while (cls!=null) {
//trace(cls.name);
for (field in cls.fields.get()) super_fields.push(field.name);
var sup = cls.superClass;
cls = (sup==null) ? null : cls.superClass.t.get();
}
//trace(super_fields);
@jcward
jcward / index.html
Created October 11, 2016 22:11
Quick test of EaselJS's Graphics.js (standalone, without the whole lib)
<!DOCTYPE html>
<html>
<body>
<canvas></canvas>
</body>
<script>
var createjs = {
createCanvas:function() {
// Point to the canvas on the DOM
@jcward
jcward / 0 - Main.hx
Created August 1, 2016 21:32
Haxe custom DOM element class
// Compile with: haxe -js foo.js -main Main.hx
import js.Browser.document;
class Main {
static function main() {
trace("Haxe is great!");
var s = SpecialDiv.factory();
trace(s);
s.my_value = 12;
@jcward
jcward / Main.hx
Last active June 6, 2017 07:41
Haxe String.split() is 100x slower in macro context than runtime?!
class Main
{
public static var text:String;
public static function main()
{
var text = "";
in_macro();
@jcward
jcward / Global.hx
Last active June 19, 2022 03:09
Haxe global (like) functions and variables via import
package;
class Global
{
public static function parseInt(s:String):Int { return Std.parseInt(s); }
public static function int(f:Float):Int { return Std.int(f); }
public static function is(v:Dynamic, t:Dynamic):Bool { return Std.is(v, t); }
public static function typeof(o:Dynamic):Type.ValueType { return Type.typeof(o); }
public static var DEBUG_LEVEL:Int = 3;
@jcward
jcward / Test.hx
Last active May 5, 2016 20:56
An idea for Dynamic MovieClips
// Note 1: you'll have to comment out DisplayObject's implements Dynamic and DisplayObjectContainer's resolve function
// Note 2: this depends on abstract resolve: https://github.com/HaxeFoundation/haxe/issues/3753
//
// I tested Haxe 3.3 which is supposed to have @:resolve for abstract, but it still didn't work
// I must have done something wrong. :P
package;
import openfl.display.*;
import openfl.Assets;
@jcward
jcward / Main.hx
Last active September 12, 2020 10:58
Haxe typed compile time constants example macro (parsing or evaluating)
// In a build system, I like to pass typed compile-time constants to my code
// via compiler defines. For example, a host String and a port Int. The
// following macros provide functionality to either parse or eval a compiler
// define as Haxe code. Since they operate at compile time and inject the
// resulting expressions into your code, this retains all type features --
// from type inference to type checking.
//
// Note that $type prints the type at compile time, while trace prints
// the value at runtime. Neko is called simply to demonstrate the latter.
import haxe.macro.Context;
@jcward
jcward / instructions.md
Created December 31, 2015 01:40
Setup haxe repo, add pleclech remote, install ocaml, build, set symlink

This will pull the git repo for haxe, add pleclech as a remote, and build it (on Ubuntu, likely similar commands on Mac. And Windows? Err, sorry.)

Go to your dev folder, checkout HaxeFoundation/haxe repo, and init submodules

git clone https://github.com/HaxeFoundation/haxe.git
cd haxe
git submodule update --init --recursive
@jcward
jcward / FindWideElems.js
Last active August 29, 2015 14:22
JavaScript test to identify all elements with a width or min-width style that break the window width (e.g. cause horizontal scroll bar).
// http://stackoverflow.com/a/22638396/1026023 - added try/catch
function css(a) {
var sheets = document.styleSheets, o = [];
a.matches = a.matches || a.webkitMatchesSelector || a.mozMatchesSelector || a.msMatchesSelector || a.oMatchesSelector;
for (var i in sheets) {
var rules = sheets[i].rules || sheets[i].cssRules;
for (var r in rules) {
var m = 0;
try {
m = a.matches(rules[r].selectorText);