Skip to content

Instantly share code, notes, and snippets.

class Container<Action, State> {
var state:tink.state.State<State>;
var reducer:State->Action->State;
public function new(initial, reducer) {
this.state = new State(initial);
this.reducer = reducer;
}
class User {
var id:String;
public function new(id)
this.id = id;
@:get('/profile/')
public function profile()
return 'profile of $id';
@:get('/whatever/$otherId/etc')
@back2dos
back2dos / Entity.hx
Created March 27, 2016 18:41
Macro based entity.
package;
import haxe.macro.Expr;
#if macro
using haxe.macro.Context;
using haxe.macro.Tools;
#end
class Entity {
class Build {
macro static public function getEnv(s:String)
return macro $v{Sys.getEnv(s)};
macro static public function exec(cmd:String, ?args:Array<String>) {
var p = new sys.io.Process(cmd, args),
pos = haxe.macro.Context.currentPos();
return
switch p.exitCode() {
case 0:
@back2dos
back2dos / TreeWalker.hx
Created January 27, 2016 16:03
Walk trees.
import js.html.Element;
interface TreeWalker<T, Cls> {
function attr(target:T, name:String):String;
function hasClass(target:T, cls:Cls):Bool;
function parent(target:T):Null<T>;
function prev(target:T):Null<T>;
function next(target:T):Null<T>;
function firstChild(target:T):Null<T>;
}
@back2dos
back2dos / Forever.hx
Created January 4, 2016 16:24
Run stuff forever.
package;
class Forever {
static function main() {
var args = Sys.args();
while (true) {
Sys.command(args[0], args.slice(1));
Sys.sleep(.25);
}
}
@back2dos
back2dos / Main.h
Last active August 29, 2015 14:28
Out args for hxcpp.
#ifndef INCLUDED_Main
#define INCLUDED_Main
#ifndef HXCPP_H
#include <hxcpp.h>
#endif
HX_DECLARE_CLASS0(Main)
@back2dos
back2dos / AnonEnum.hx
Created June 17, 2015 15:49
Anonymous enums \o/
#if macro
import haxe.macro.Expr;
import haxe.macro.Type;
import haxe.macro.Context.*;
#else
@:genericBuild(AnonEnum.build())
#end
class AnonEnum<Const> {
macro static function build():Type {
@back2dos
back2dos / Main.hx
Created June 1, 2015 07:57
Macro context vs. output context
//Original source code:
class Main {
#if !macro
static function main() {
test();
}
#end
macro static function test() {
@back2dos
back2dos / results.txt
Created January 22, 2015 09:34
Top 100 Haxelibs by download
+-----------+----------------------+
| downloads | name |
+-----------+----------------------+
| 78260 | openfl |
| 57649 | lime |
| 50236 | openfl-samples |
| 49287 | hxcpp |
| 43047 | lime-tools |
| 41134 | openfl-native |
| 40236 | actuate |