Skip to content

Instantly share code, notes, and snippets.

@fponticelli
fponticelli / stream.js
Created April 21, 2014 15:50
simple stream
import Timer from 'ui/timer';
let _listeners = Symbol();
class Source {
constructor(callback) {
this[_listeners] = [];
let sink = (value) => {
Timer.immediate(() => {
this[_listeners].map(ƒ => ƒ(value));
@fponticelli
fponticelli / CommentBox.hx
Created June 1, 2014 22:21
react.hx first attempt
import react.React;
class CommentBox extends React {
static function main() {
React.renderComponent(
@dom '<CommentBox url="comments.json" pollInterval={2000} />',
js.Browser.document.getElementById('content')
);
}
@fponticelli
fponticelli / Sample.axe
Last active August 29, 2015 14:02
new haxe?
class Sample<T>(value : T) {
trace(value)
def toString = value
}
import sui.Sui;
class DemoObject {
public static function main() {
var o = new DemoObject(),
sui = new Sui();
sui.bind(o.name);
sui.bind(o.enabled);
sui.bind(o.startedOn);
sui.bind(o.traceMe);
package thx.core;
import haxe.Constraints.IMap;
@:multiType(K)
abstract MapList<K, V>(MapListImpl<K, V>) {
public function new();
public inline function set(key:K, value:V) this.set(key, value);
public inline function insert(index : Int, k : K, v : V) : Void this.insert(index, k, v);
@:arrayAccess public inline function get(key:K) return this.get(key);
@fponticelli
fponticelli / Main.hx
Created February 15, 2015 16:21
Minimalistic Webserver with NodeJS + Express + Haxe (with Macros) and an experimental library called restx
import restx.App;
class Main implements restx.IRoute {
@:path("/")
function index()
response.send("Hello World!");
public static function main() {
var app = new App(9998);
app.router.register(new Main());
@fponticelli
fponticelli / Auth.hx
Created February 24, 2015 17:53
sample Auth with abe
@:use(mw.BodyParser.json())
class Auth implements abe.IRoute {
@:post("/auth")
@:args(body)
function login(user : String, password : String) {
response.send('$user:$password');
}
}
@fponticelli
fponticelli / Router.hx
Last active August 29, 2015 14:16
extern issue
import express.Request;
import express.Response;
import express.Next;
import express.Middleware;
import express.Express;
import abe.Router;
class Main {
public static function main() {
var router = new abe.Router(null);
@fponticelli
fponticelli / Main.hx
Created March 11, 2015 14:46
small js.Promise test
import js.Promise;
class Main {
static function main() {
var p1 = new Promise(function(resolve, reject) {
resolve("YES");
});
p1.then(function(v) trace(v), function(e) trace('NOOO!! $e'));
var p2 = new Promise(function(resolve, reject) {
@fponticelli
fponticelli / Lazy.hx
Created September 16, 2015 17:19
Lazy evaluation of remote files
import js.node.vm.Script;
using thx.promise.Promise;
class Lazy {
static var map : Map<String, Script> = new Map();
public static function load(path : String) : Promise<{} -> String> {
var script = map.get(path);
if(null != script) {
return Promise.value(loadScript(script));
}