Skip to content

Instantly share code, notes, and snippets.

@ciscoheat
ciscoheat / Routes.hx
Last active August 26, 2016 19:51
Typesafe web routes with Haxe in less than 100 lines
// Code for this article:
// https://github.com/ciscoheat/mithril-hx/wiki/Typesafe-web-routes-with-Haxe-in-less-than-100-lines
#if macro
import haxe.Serializer;
import haxe.Unserializer;
import haxe.macro.Context;
import haxe.macro.Expr;
import sys.io.File;
@ciscoheat
ciscoheat / UUID.hx
Created April 3, 2016 05:20
Quick UUID generator in Haxe
class UUID {
public static function uuid() {
// Based on https://gist.github.com/LeverOne/1308368
var uid = new StringBuf(), a = 8;
uid.add(StringTools.hex(Std.int(Date.now().getTime()), 8));
while((a++) < 36) {
uid.add(a*51 & 52 != 0
? StringTools.hex(a^15 != 0 ? 8^Std.int(Math.random() * (a^20 != 0 ? 16 : 4)) : 4)
: "-"
);
@ciscoheat
ciscoheat / domready.js
Created February 10, 2016 20:36 — forked from ded/domready.js
Smallest x-browser DOM Ready, ever [WORKING]
function r(f){/(un|ing)/.test(document.readyState)?setTimeout(r,9,f):f()}
@ciscoheat
ciscoheat / animation.xaml
Last active December 4, 2015 23:52
Silverlight animation declaration...
<Canvas xmlns="..." xmlns:x="..." ...>
<Canvas.Resources>
<Storyboard
x:Name="mouseEnterAnimation">
<ColorAnimation
Duration="00:00:0.2"
To="Purple"
Storyboard.TargetProperty=
"(Shape.Fill).(GradientBrush.
GradientStops)[1].
import js.Browser;
import mithril.M;
class App implements Mithril {
public static function main() {
M.mount(Browser.document.body, new App());
}
var tests = [];
@ciscoheat
ciscoheat / Main.hx
Last active August 29, 2015 14:21
Minimal working DCI example for Haxe
/*
How to run:
1. Download and install Haxe: http://haxe.org/download/
2. Save this code to Main.hx and open a command prompt in the same directory
3. Execute "haxelib install haxedci"
4. Execute "haxe -main Main -lib haxedci --interp"
For javascript output:
haxe -main Main -lib haxedci -js moneytransfer.js
*/
@ciscoheat
ciscoheat / Example.hx
Last active August 29, 2015 14:14 — forked from cambiata/Example.hx
Using a View instead of a Module
class User implements Model {
@prop public var name : String;
public function new(name) {
this.name = M.prop(name);
}
}
class TestModule implements View {
var user:User;
@ciscoheat
ciscoheat / Attraction.hx
Created January 12, 2015 05:55
Problem with creating a Mongoose model
package;
import js.npm.mongoose.macro.Manager;
import js.npm.mongoose.macro.Model;
typedef AttractionSchema = {
name: String,
description: String,
location: { lat: Float, lng: Float },
history: {
@ciscoheat
ciscoheat / Example.js
Last active August 29, 2015 14:13
Brainstorming a simple API description format, generic but with Haxe externs in mind
// The format is JSON, but using js for comments.
{
// Type (Starts with Uppercase to differentiate from the primitive types)
"IncomingForm": {
"" : "Empty key leaves room for a description.",
// A function ends with (). Array value signifies overloading
"parse()": [{
"" : "Parse a form",
// Parameter: Type
"req": "js.npm.express.Request",
@ciscoheat
ciscoheat / Vagrantfile
Last active December 21, 2015 14:10
Vagrant setup for Haxe
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# All Vagrant configuration is done here. The most common configuration
# options are documented and commented below. For a complete reference,
# please see the online documentation at vagrantup.com.