Skip to content

Instantly share code, notes, and snippets.

View jonasmalacofilho's full-sized avatar

Jonas Malaco jonasmalacofilho

View GitHub Profile
@Simn
Simn / Main.hx
Created November 3, 2012 16:59
Function-based specialization wizardry in haxe3
class Main {
static function main() {
trace(process(12)); // 24
trace(process("Hello world")); // HELLO WORLD
}
@:generic static function process<T>(t:T):T {
return throw "unknown type: " + t;
}
@jasononeil
jasononeil / DispatchTest.hx
Last active December 17, 2015 20:19
A sample to test some more complex routing options of haxe.web.Dispatch. Run with `haxe -x DispatchTest.hx` This is the sample code for this tutorial / blog post: http://jasononeil.com.au/2013/05/29/creating-complex-url-routing-schemes-with-haxe-web-dispatch/
import haxe.ds.StringMap;
import haxe.web.Dispatch;
import haxe.web.Dispatch.DispatchError;
#if sys
import Sys.println;
import Sys.print;
#else
import haxe.Log.trace in println;
import haxe.Log.trace in print;
@nadako
nadako / DynamicMap.hx
Last active January 2, 2016 22:29
Abstract wrapper for Dynamic objects.
/**
* Simple wrapper for anonymous structures that are meant to be used as a
* keyed collection of objects of the same type (i.e. json object).
*
* Wraps Reflect calls with nice syntax and static typing without any
* runtime overhead.
*/
abstract DynamicMap<V>(Dynamic<V>) from Dynamic<V>
{
/**
@jasononeil
jasononeil / Metric.hx
Last active November 10, 2016 11:16
Demonstration of using Haxe abstracts to take care of explicit conversions between different units of measurement, with no performance overhead.
class Metric {
static function main() {
var coinRadius:Millimeters = 12;
var myHeight:Centimeters = 180;
var raceLength:Meters = 200;
var commuteDistance:Kilometers = 23;
diff( coinRadius, myHeight ); // 1.788 meters
diff( raceLength, commuteDistance ); // 22800 meters
sum( commuteDistance, coinRadius ); // 23000.012 meters
@nadako
nadako / 1 Main.hx
Created February 18, 2014 22:19
Using haxe macros as syntax-tolerant, position-aware json parser
import haxe.macro.Context;
import haxe.macro.Expr;
using haxe.macro.ExprTools;
class Main
{
inline static var QUOTED_FIELD_PREFIX = "@$__hx__";
static function main()
@jasononeil
jasononeil / ClassicSwitch.hx
Last active March 22, 2018 21:17
ClassicSwitch.hx - a macro which takes a switch statement and turns it into an if/elseif/else chain. This is useful if you want traditional ecmascript "switch" behaviour, not the kick-ass haxe pattern matching. See the README, the implementation, and some tests below.
import haxe.macro.Expr;
import haxe.macro.Context;
class ClassicSwitch
{
macro static public function from(inExpr:Expr):Expr
{
var retExpr:Expr = null;
switch (inExpr.expr)
import haxe.macro.Expr;
class FTW
{
public static function build()
{
return haxe.macro.Context.getBuildFields().map(transformField);
}
static function transformField(field:Field)
@gagern
gagern / gist:8256742
Created January 4, 2014 15:55
Dump GPG packet data, public key in particular
import sys
import subprocess
import io
class PacketReader(object):
packetTagNames = {
0: 'Reserved - a packet tag MUST NOT have this value',
1: 'Public-Key Encrypted Session Key Packet',
2: 'Signature Packet',
@TheUbuntuGuy
TheUbuntuGuy / fuckuanova.py
Created April 23, 2017 20:17
Decode Anova Precision Cooker WiFi Packets
#!/usr/bin/python3
import math
f = open("rawdump.txt", "r")
for l in f.readlines():
p = 0
chars = []
chksum = 0
@pedrocamargo
pedrocamargo / TSP with AequilibraE.ipynb
Created March 30, 2020 08:04
Using AequilibraE and Google OR-Tools to compute the TSP
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.