Skip to content

Instantly share code, notes, and snippets.

Jason O'Neil jasononeil

Block or report user

Report or block jasononeil

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@jasononeil
jasononeil / Console.hx
Created Mar 6, 2012
A really simple proof of concept for a haxe interactive shell
View Console.hx
/**
A super basic interactive console for haxe.
Done because someone on the mailing list asked and I got distracted :)
Consider this code Public Domain.
Jason O'Neil
Run using:
haxe -lib hscript -x Console.hx
(you will need hscript installed via haxelib)
@jasononeil
jasononeil / NekoScript.hx
Created May 23, 2012
NekoScript proof of concept - simple scripting language using hscript
View NekoScript.hx
/**
NekoScript
By Jason O'Neil, 2011. Licensed under the GPL.
*/
import hscript.Parser;
import neko.Sys;
import neko.FileSystem;
import neko.io.File;
import haxe.Http;
@jasononeil
jasononeil / Main.hx
Created Jun 18, 2012
Xirsys_std and erazor do not co-operate
View Main.hx
import erazor.Template;
class Main
{
public static function main()
{
var template = new Template("hello @file");
trace(template.execute({ "file": "world" }));
}
}
View Builder.hx
import haxe.macro.Context;
import haxe.macro.Expr;
class Builder {
// Build macros are called using @:build() or @:autoBuild() metadata
// They must return an array containing all of the fields of the new type
macro static function build():Array<Field> {
// Create expression representing the test() function
var funcExpr = macro function():String {
return "test";
@jasononeil
jasononeil / InitialisationChecker.hx
Last active Dec 14, 2015
Very simple proof of concept for a macro which checks that all member variables and static variables have been initialised. Currently it checks for every single type... so it finds a bunch of errors in the standard library too. Someone may want to fork it and make it a little bit more clever... UPDATE: modified it to only check Int, Float, Strin…
View InitialisationChecker.hx
// Only tested on Neko, Haxe3RC
// Compile and run with:
// haxe -x InitialisationChecker.hx
// Created by Jason O'Neil, 2013. Release public domain.
#if macro
import haxe.macro.Context;
using Lambda;
#end
@jasononeil
jasononeil / DOMReady.hx
Last active Dec 15, 2015
A lot of the time in JS we have to wait for the page to finish loading, or at least, for the DOM to be loaded, before we can begin our various operations. Detox makes this easy with the Detox.ready() function, which fires the given function as soon as the DOM is loaded.
View DOMReady.hx
using Detox;
public class DOMReady
{
static function main()
{
Detox.ready(function (e) {
Detox.document.title = "Page is ready";
});
}
@jasononeil
jasononeil / MacroDefine.hx
Created Mar 25, 2013
haxe.macro.Compiler.define() example
View MacroDefine.hx
/**
* Macro Compiler Define example
*
* Shows how to use a compiler configuration macro to set up more "defines" based
* on an existing define.
*
* Jason O'Neil 2013. Use as you please.
*
* haxe -D mydebug --macro "MacroDefine.setDefines()" -x MacroDefine.hx
* -- traces "A" and "B"
@jasononeil
jasononeil / WebSocketTest.hx
Created Apr 5, 2013
A haxe port of the WebSockets demo here: http://www.websocket.org/echo.html Works with Haxe3.
View WebSocketTest.hx
// Compile with: haxe -main WebSocketTest.hx -js WebSocketTest.js
// Doing your imports like this makes it much easier to port with existing Javascript code.
import js.Browser.window;
import js.Browser.document;
import js.html.*;
class WebSocketTest
{
static var wsUri = "ws://echo.websocket.org/";
@jasononeil
jasononeil / CustomSerialisation.hx
Created Apr 12, 2013
A test of custom serialisation in Haxe when using sys.db.Object objects. Results in file below * Using a custom serialiser for SPOD can reduce speeds by more than half. * String size is also reduced, which is good if you're sending over HTTP * Have a build macro append a static array containing the names of the fields to serialise.
View CustomSerialisation.hx
import sys.db.Types;
using Lambda;
/**
* What this class shows:
*
* Using a custom serialiser for SPOD can reduce speeds by more than half.
* Have a build macro append a static array containing the names of the fields to serialise.
*/
@jasononeil
jasononeil / ClassicSwitch.hx
Last active Mar 22, 2018
ClassicSwitch.hx - a macro which takes a switch statement and turns it into an if/elseif/else chain. This is useful if you want traditional ecmascript "switch" behaviour, not the kick-ass haxe pattern matching. See the README, the implementation, and some tests below.
View ClassicSwitch.hx
import haxe.macro.Expr;
import haxe.macro.Context;
class ClassicSwitch
{
macro static public function from(inExpr:Expr):Expr
{
var retExpr:Expr = null;
switch (inExpr.expr)
You can’t perform that action at this time.