Skip to content

Instantly share code, notes, and snippets.

@jcward
jcward / StreamVideo.as
Created October 25, 2013 19:04
A simple example of playing a video stream in Flash (and vlc commands for serving the stream)
/**
* Streaming Video Test
*
* References:
* -----------
* http://serverfault.com/questions/288137/how-to-stream-live-video-from-a-linux-server
* https://wiki.videolan.org/Stream_VLC_to_Website_with_asf_and_Flash#Method_2_H264_and_Flash_.flv
* http://blog.morscad.com/code-snippets/creating-a-video-player-in-as3-using-netstream/
*
* Sample videos:
@jcward
jcward / Rand32.hx
Last active August 29, 2015 13:56
Haxe cross-platform rand() function that provides a full 32-bit random Ints
// Author: Jeff Ward
// License: MIT
//
// Haxe Std.random() can only generate 31 bits of random data. This seems to
// be a Neko limitation that is foisted on the other platforms. Well, no
// longer! cpp, flash, and js are liberated below.
package;
class Rand32 {
@jcward
jcward / primes.c
Last active August 29, 2015 14:01
Quick'n'dirty prime number calculation
#include <iostream>
#include <vector>
#include <math.h>
int main()
{
std::vector<long> primes;
primes.push_back(2);
for(long i=3; i < 2^63; i++)
{
@jcward
jcward / print_amf.rb
Last active June 28, 2017 04:32
RocketAMF can de/serialize AMF serialized byte streams, but it throws (at least, the 0.2.1 version from gem install throws) when it encounters an IExternalizable type in the byte steam. This patch allows it to parsed custom IExternalizable classes properly.
#!/usr/bin/env ruby
require 'rocketamf'
require 'stringio'
# Monkey patch for RocketAMF (0.2.1 gem) that handles IExrternalizable types
# in the input, storing their type as "__as3_type" parameter:
module RocketAMF
module Values #:nodoc:
class TypedHash
@jcward
jcward / float_fix.rb
Created October 7, 2014 14:38
Script to inject Std.int on Float should be Int
#!/usr/bin/ruby
#
# Usage: haxe Test.hx -main Test -cpp test 2>&1 | float_fix.rb
#
# Modifies files which appear on error lines as:
#
# Test.hx:15: characters 12-18 : Float should be Int
#
# Changes Test.hx line 15 from: needInt( 4.5 - 3 ) ;
# to: needInt( Std.int(4.5 - 3) ) ;
@jcward
jcward / Rand.hx
Last active August 29, 2015 14:09
Testing Int, Std.random in Haxe 3.1.3, Neko 2.0
// Testing with Haxe 3.1.3 and Neko 2.0
class Rand {
static function intArg(ii:Int) {
trace(" - got intArg: "+ii);
}
static function main() {
var i1:Int = 0xffffffff;
trace("0xFFFFFFF = "+i1);
var i2:Int = 0x7fffffff;
@jcward
jcward / PopulateHierarchicalStruct
Created January 22, 2015 07:27
Traversing (and populating where nodes don't exist) a hierarchical structure in a std::map
// Traversing (and populating where nodes don't exist) a hierarchical structure:
struct AllocStackIdMapEntry
{
std::map<int, AllocStackIdMapEntry*> children;
};
{
std::vector<int> callstack;
@jcward
jcward / hxScout testing instructions
Last active August 29, 2015 14:15
Setup testing of hxcpp / hxScout
Instructions for testing hxScout with hxcpp.
FYI, I've tested this using Haxe 3.1.3, OpenFL 2.1.7 (the legacy version, aka _v2, aka not next) in Windows 7. Your mileage may vary. All this is under heavy development, so it may cease working at some point.
1) Git checkout (or download) jcward's hxcpp (integration branch), hxtelemetry, and hxScout:
https://github.com/jcward/hxScout/archive/master.zip
https://github.com/jcward/hxtelemetry/archive/master.zip
https://github.com/jcward/hxcpp/archive/integration.zip
@jcward
jcward / Main.hx
Last active October 20, 2017 17:19
Print compiler defines from a macro in Haxe
// Note: Context.getDefines() requires Haxe 3.2 or later
class Main { // example main class
// - - - - - - - - - - - - - - - - - - - - - - - - - -
// Just paste this code into one of your classes:
// - - - - - - - - - - - - - - - - - - - - - - - - - -
macro public static function get_defines():haxe.macro.Expr {
var rtn = "Defines ("+
(haxe.macro.Context.defined("macro")?"macro":"standard")+" pass):\n";
@jcward
jcward / Main.hx
Created May 12, 2015 23:50
Haxe fast C++ Float to Int conversion
import haxe.Timer.stamp;
// Testing float to integer conversion faster than Std.int() for C++ based on:
// http://stackoverflow.com/questions/429632/how-to-speed-up-floating-point-to-integer-number-conversion
class Main {
#if cpp
@:functionCode("
union Cast
{