Skip to content

Instantly share code, notes, and snippets.

@back2dos
back2dos / Main.hx
Last active December 10, 2015 22:28
Hello world with tinx_node
package ;
class Main implements tink.lang.Cls {
static function main()
@with(tinx.node.Http.server(2000))
@on(request)
request.respond().end('hello world')
}
@tong
tong / nacl-toolchain.xml
Created February 2, 2013 12:30
NativeClient toolchain file for HXCPP
<!-- NativeClient hxcpp toolchain -->
<xml>
<include name="gcc-toolchain.xml"/>
<path name="${NACL_SDK_ROOT}/toolchain/linux_x86_newlib/bin"/>
<set name="M" value="32" unless="HXCPP_M64" />
@darobin
darobin / index.html
Last active December 12, 2015 07:48
Who needs srcset? Who needs <picture>? Not the AppCache people we don't!
<!DOCTYPE html>
<!--
- controllerpath should default to /*, it's just the typical thing
- controllersync ensures the controller is always there
-->
<html controller="respimg.js" controllerpath="/*" controllersync>
<!-- ... -->
<img src='my-shiny-donkey.png#resp-me'>
</html>
@andyli
andyli / AbstractClass.hx
Last active June 24, 2021 13:40
Java abstract class implemented in Haxe macros. Related: https://groups.google.com/forum/?fromgroups=#!topic/haxelang/WzeI-N1XbIg
import haxe.macro.Context;
import haxe.macro.Expr;
import haxe.macro.Type;
using Lambda;
/**
Old school abstract class.
Classes that implements it, and their sub-classes, will be able to declare abstract methods (methods that without body).
There will be a check in compile-time such that no public constructor is allowed without all abstract methods implemented.
*/
@tong
tong / NekoBoot.hx
Last active January 27, 2020 11:49
Haxe port of nekoboot.neko for creating executables from bytecode. Original: http://code.google.com/p/nekovm/source/browse/trunk/src/tools/nekoboot.neko Usage : nekoboot <file.n>
import sys.FileSystem;
import sys.io.File;
/**
Haxe port of nekoboot.neko for creating executables from neko bytecode.
Original version: https://github.com/HaxeFoundation/neko/blob/master/src/tools/nekoboot.neko
Usage : nekoboot <file.n>
*/
package ;
abstract JsonMap<T>({ }) from {} {
public function new() this = {};
public function exists(key:String) return Reflect.hasField(this, key);
@:arrayAccess public function get(key:String) return Reflect.field(this, key);
@:arrayAccess public function set(key:String, value:T):T {
Reflect.setField(this, key, value);
return value;
}
@clemos
clemos / HybridSwitch.hx
Last active December 16, 2015 13:39
Make haxe switch to accept both patterns and identifiers
import haxe.macro.Context;
import haxe.macro.Expr;
class HybridSwitch {
/*
this macro attempts to make switch / case work both
with the new pattern matching feature and with
simple switch variables
@martinwells
martinwells / gist:5980517
Created July 12, 2013 00:43
Simple Haxe logging with colors
/**
Simple, colorful logging!
Setup
=====
Somewhere really early in your code do a:
Log.init();
This will setup the logger methods and coloring stuff.
Logging
@Integralist
Integralist / Description.md
Last active April 25, 2020 16:20
This is how BBC News currently implements it's Image Enhancer for responsive images. Note: this is a completely rebuilt version of the code so the BBC's original source code doesn't actually look anything like the below example.

The BBC has a server-side image service which provides developers with multiple sized versions of any image they request. It works in a similar fashion to http://placehold.it/ but it also handles the image ratios returned (where as placehold.it doesn't).

The original BBC News process (and my re-working of the script) follows roughly these steps...

  • Create new instance of ImageEnhancer
  • Change any divs within the page (which have a class of delayed-image-load) into a transparent GIF using a Base64 encoded string.
    • We set the width & height HTML attributes of the image to the required size
    • We know what size the image needs to be because each div has custom data-attr set server-side to the size of the image
    • We then set a class of image-replace onto each newly created transparent image
  • We use a 250ms setTimeout to unblock the UI thread and which calls a function resizeImages which enhances the image-replace images so their source is now set to a URL whe
import haxe.macro.Expr;
class FTW
{
public static function build()
{
return haxe.macro.Context.getBuildFields().map(transformField);
}
static function transformField(field:Field)