Skip to content

Instantly share code, notes, and snippets.

View dpeek's full-sized avatar

David Peek dpeek

View GitHub Profile
@dpeek
dpeek / gist:7762713
Created December 3, 2013 02:08
Programming is a Slippery Slope
  1. Want to code a thing
  2. Choose a runtime
  3. Choose a language
  4. Choose some libraries
  5. Start coding
  6. Library doesn't meet your requirements
  7. Start writing your own library
  8. Language gets in way of perfect library
  9. Start writing your own language
  10. Runtime is holding back language
import haxe.macro.Expr;
class FTW
{
public static function build()
{
return haxe.macro.Context.getBuildFields().map(transformField);
}
static function transformField(field:Field)
import haxe.macro.Expr;
class Func
{
public static function each<T>(it:Iterable<T>, cb:T -> Void)
{
for (i in it) cb(i);
}
public static function every<T>(it:Iterable<T>, cb:T -> Bool):Bool
@dpeek
dpeek / ProcessHelper.hx
Last active March 29, 2016 21:44
Non blocking process in Neko
import neko.vm.Thread;
import sys.io.Process;
class ProcessHelper
{
static function main()
{
var process = run('haxe', ['--help'],
function (line) Sys.println('stdout: $line'),
function (line) Sys.println('stderr: $line'),
@dpeek
dpeek / gist:6666697
Last active December 23, 2015 17:09
Fluent compilation times
class Test
{
static function main()
{
new Test().a().a().a().a().a().a().a().a().a().a().a().a().a().a().a().a().a().a().a().a().a()
.a() // 0.460s
.a() // 0.910s
.a() // 1.860s
.a() // 3.630s
.a() // 7.350s
class Main
{
static function main()
{
var context = new MyContext(new View());
}
}
class MyContext extends mmvc.impl.Context
{
@dpeek
dpeek / VerEx.hx
Last active May 3, 2019 19:38
VerbalExpressions for Haxe
class VerEx
{
public static function main()
{
var test = new VerEx()
.startOfLine()
.then("http")
.maybe("s")
.then("://")
.maybe("www.")
class GameScene extends Scene {
// ...
public override function update() {
// Keep camera.x centered on the player
HXP.camera.x = player.x - HXP.halfWidth + 64;
// Keep camera.y centered on the player,
// unless it would show below the map.
// In that case, keep to the bottom fo the map.
@dpeek
dpeek / gist:6043433
Created July 20, 2013 01:23
Haxe, Neko and OpenFL on Raspberry Pi
mkdir ~/source
# dependencies
sudo apt-get update
sudo apt-get install libgc-dev bzip2 git-core make gcc g++ gnuplot glade imagemagick libusb-dev python-usb python-lxml python-wxgtk2.8 speech-dispatcher libgnomecanvas2-dev m4 libsdl1.2-dev
# neko
git clone https://github.com/HaxeFoundation/neko.git ~/source/neko
cd ~/source/neko
make
@dpeek
dpeek / gist:5810652
Last active December 18, 2015 16:19
class Test
{
public static var instance(default, null):Test = new Test();
public static var lazy(get, null):Test;
static function get_lazy() return lazy == null ? lazy = new Test() : lazy;
static function main()
{
trace(instance);