Skip to content

Instantly share code, notes, and snippets.

@haxiomic
haxiomic / Partial.hx
Last active February 26, 2023 11:44
Haxe macro to make all fields of a type optional (similar to Typescript's Partial<T>)
import haxe.macro.Context;
import haxe.macro.Expr;
import haxe.macro.TypeTools;
#if !macro
@:genericBuild(PartialMacro.build())
#end
class Partial<T> {}
class PartialMacro {
@mcheshkov
mcheshkov / ShortLambdaMacroTest.hx
Last active August 29, 2015 14:22
Short lambda macro #1
class ShortLambdaMacroTest {
static function other(i:Int){
trace('ok, so $i');
}
static function using(){
Lambda.iter([1,2,3], function(i){trace(i);});
Lambda.iter([1,2,3], f(i => trace(i)));
Lambda.iter([1,2,3], f(i => {trace(i + 1); other(i);}));
}
@nijikokun
nijikokun / m.validator.js
Last active May 18, 2016 15:11
Mithril validation utility
m.validator = function (model, validations) {
this.errors = {}
this.validations = validations
this.model = model
}
m.validator.prototype.hasErrors = function () {
return Object.keys(this.errors).length
}

HTML5 Markup Template - Basic

A very basic starter template with fundamental HTML5 markup -- only the basics.

Based on HTML5 Bones | http://html5bones.com

@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.
*/
@samuelcole
samuelcole / ultimate_url_re.js
Created April 14, 2011 19:44
Ultimate Url Regex!
/*
Based off of Gruber's awesome url regex: http://daringfireball.net/2010/07/improved_regex_for_matching_urls
In addition:
- Should match 'example.com', 'google.net', 'google.org'. (only com, net, and org are whitelisted).
- Should not match 'sam@samuelcole.name'.
*/
var URL_RE = /(?:(?=[\s`!()\[\]{};:'".,<>?«»“”‘’])|\b)((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/|[a-z0-9.\-]+[.](?:com|org|net))(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))*(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]|\b))/gi