Skip to content

Instantly share code, notes, and snippets.

View jasononeil's full-sized avatar

Jason O'Neil jasononeil

View GitHub Profile
@jasononeil
jasononeil / HaxeScript.hx
Created April 22, 2013 06:18
haxex, a short shell script that can be used so you have Haxe shell scripting
#!/usr/bin/haxex
// Run with "./HaxeScript.hx some args here"
class HaxeScript
{
public static function main()
{
trace('Hi, the following ${Sys.args().length} arguments were passed in:');
for (a in Sys.args())
@jasononeil
jasononeil / angularInjectionMiddleware.js
Last active October 5, 2021 00:02
Using angular dependency injection with react, redux, and redux-thunk
var thunkDispatcherRef = {
dispatch: function () {}
}
/**
* The angular injection middleware allows our redux actions to return functions.
*
* The function will be executed with regular angular dependency injection, allowing
* you to use angular services in Redux actions.
*
@jasononeil
jasononeil / Console.hx
Created March 6, 2012 03:00
A really simple proof of concept for a haxe interactive shell
/**
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 / ClassicSwitch.hx
Last active March 22, 2018 21:17
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.
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)
@jasononeil
jasononeil / metrics.txt
Created November 14, 2016 01:18
List of all Sitespeed 4.0 metrics. I couldn't find this list anywhere, and it took me a while to figure out how to generate the file using grunt-sitespeedio (for future reference: set `sitespeedio.default.options.metrics.list=true`). I figure pasting this here will help some other poor souls thanks to the SEO goodness.
browsertime.pageSummary.browserScripts.0.pageinfo.documentHeight
browsertime.pageSummary.browserScripts.0.pageinfo.documentWidth
browsertime.pageSummary.browserScripts.0.pageinfo.responsive
browsertime.pageSummary.browserScripts.0.timings.firstPaint
browsertime.pageSummary.browserScripts.0.timings.fullyLoaded
browsertime.pageSummary.browserScripts.0.timings.navigationTiming.connectEnd
browsertime.pageSummary.browserScripts.0.timings.navigationTiming.connectStart
browsertime.pageSummary.browserScripts.0.timings.navigationTiming.domComplete
browsertime.pageSummary.browserScripts.0.timings.navigationTiming.domContentLoadedEventEnd
browsertime.pageSummary.browserScripts.0.timings.navigationTiming.domContentLoadedEventStart
@jasononeil
jasononeil / zendesk-wysiwyg-styles.css
Created August 18, 2017 05:41
Styles needed for Zendesk wysiwyg content
.wysiwyg-color-black {
color: #000; }
.wysiwyg-color-black70 {
color: #4d4d4d; }
.wysiwyg-color-black60 {
color: #666666; }
.wysiwyg-color-black50 {
color: gray; }
.wysiwyg-color-black40 {
color: #999999; }
@jasononeil
jasononeil / WebpackLoaderUtil.hx
Last active June 5, 2017 23:33
A webpack loader that compiles (and watches) a hxml file, including the resulting JS in the webpack bundle.
import haxe.macro.Context;
import haxe.macro.Type;
import haxe.macro.Expr;
import sys.io.File;
class WebpackLoaderUtil {
public static function outputJson(outputFile:String) {
Context.onGenerate(function (types:Array<Type>) {
var allFilesUsed = [];
for (type in types) {
@jasononeil
jasononeil / Metric.hx
Last active November 10, 2016 11:16
Demonstration of using Haxe abstracts to take care of explicit conversions between different units of measurement, with no performance overhead.
class Metric {
static function main() {
var coinRadius:Millimeters = 12;
var myHeight:Centimeters = 180;
var raceLength:Meters = 200;
var commuteDistance:Kilometers = 23;
diff( coinRadius, myHeight ); // 1.788 meters
diff( raceLength, commuteDistance ); // 22800 meters
sum( commuteDistance, coinRadius ); // 23000.012 meters
@jasononeil
jasononeil / ReflectionCost.hx
Created June 12, 2016 12:24
Demonstrate how much extra code reflection (Reflect.* and Type.*) generate in Haxe code
class ReflectionCost {
public static function main() {
var obj = new ReflectionCost();
#if reflect
Reflect.setField( obj, "name", "Jason" );
Reflect.callMethod( obj, Reflect.field(obj, "printName"), [] );
Type.getInstanceFields( Type.getClass(obj) );
#else
obj.name = "Jason";
obj.printName();
@jasononeil
jasononeil / Test.hx
Last active January 2, 2016 16:18
`AcceptEither`, a way to accept either one type or another, without resorting to "Dynamic", and still have the compiler type-check everything and make sure you correctly handle every situation.
class Test {
static function main(){
stringOrInt( "hello" );
stringOrInt( 10 );
}
static function stringOrInt( either:AcceptEither<String,Int> ) {
switch either.type {
case Left(str): trace("string: "+str);
case Right(int): trace("int: "+int);