Skip to content

Instantly share code, notes, and snippets.

class PrintCwd {
static function main()
Sys.println('cwd: ' + Sys.getCwd() + ' args: ' + Sys.args());
}
@back2dos
back2dos / Main.hx
Created April 4, 2018 08:01
Example usage for tink_xml.
// items.xml to be found at https://raw.githubusercontent.com/dougmencken/HeadOverHeels/master/gamedata/items.xml
// Run per `haxe -lib tink_xml --run Main`
using sys.io.File;
class Main {
static function main() {
var s = new tink.xml.Structure<Array<Entry>>();
switch s.read('items.xml'.getContent()) {
case Success(entries):
var doors = [],
@back2dos
back2dos / Scrolling.hx
Created December 12, 2017 13:23
Infinite coconut scroller.
package ;
import js.Browser.*;
import vdom.VDom.*;
import coconut.Ui.hxx;
import coconut.ui.*;
import coconut.data.*;
using Scrolling;
class Scrolling {
@back2dos
back2dos / CachingClient.hx
Created December 6, 2017 14:33
Caching client for tink_web.
import tink.http.Client;
import tink.http.Request;
import tink.http.Response;
using tink.CoreApi;
typedef CachePolicy = OutgoingRequest->IncomingResponse->Future<Noise>;
class CachingClient implements tink.http.Client.ClientObject {
var actual:Client;
var policy:CachePolicy;
@back2dos
back2dos / Include.hx
Created October 23, 2017 09:24
Handwritten include all.
package ;
import haxe.macro.Context;
using sys.FileSystem;
using StringTools;
@:forward
abstract Entry(haxe.io.Path) {
public inline function new(s)
this = new haxe.io.Path(s);
@back2dos
back2dos / ArrayRead.hx
Last active September 29, 2017 01:02 — forked from nadako/ArrayRead.hx
Recursive read-only type generator for JSON structures (based on @:genericBuild)
@:forward(map, filter, copy, slice)
abstract ArrayRead<T>(Array<T>) from Array<T> to Iterable<T> {
@:arrayAccess inline function get(i:Int):T return this[i];
public var length(get,never):Int;
inline function get_length() return this.length;
}
@back2dos
back2dos / NpmInstall.hx
Created September 26, 2017 10:24
NPM based installation for haxeshim.
import Sys.*;
using sys.FileSystem;
using sys.io.File;
class NpmInstall {
static function die(reason:String, ?code = 500) {
println(reason);
exit(code);
}
@back2dos
back2dos / Self.hx
Last active July 28, 2017 09:02
Reference local class as `Self`.
package ;
#if macro
import haxe.macro.Context.*;
class Self {
static public function buildSelf()
return getType(
switch getTypedExpr(typeExpr(macro (function (?pos:haxe.PosInfos) {})())).expr {
case ECall(_, [macro { fileName: $_, lineNumber: $_, className: ${{ expr: EConst(CString(name)) }}, methodName: $_ }]): name;
default: throw 'assert';
@back2dos
back2dos / index.html
Last active May 31, 2017 08:58
TodoMVCoconut
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>TodoMVCoconut</title>
<meta name="description" content="TodoMVC implementation based on MVCoconut" />
<link rel="stylesheet" type="text/css" href="styles.css">
<link rel="icon" href="https://avatars1.githubusercontent.com/u/25455337?v=3&amp;s=200" type="image/png" />
</head>
@back2dos
back2dos / Swapper.hx
Created April 30, 2017 11:21
Coconut swapper.
import tink.state.*;
import coconut.ui.*;
using tink.CoreApi;
class Swapper<T> extends BaseView {
public function new(options:Observable<{
className:String,
data: Promised<T>,
renderData:T->RenderResult,