Skip to content

Instantly share code, notes, and snippets.

View SimonRichardson's full-sized avatar
👻
Bug hunting 🎯

Simon Richardson SimonRichardson

👻
Bug hunting 🎯
View GitHub Profile
@SimonRichardson
SimonRichardson / gist:4713952
Created February 5, 2013 11:42
HistoryController
// HistoryController.hx
package controller;
import funk.actors.types.mvc.Controller;
import funk.actors.types.mvc.Model;
import funk.ioc.Inject;
import funk.types.Tuple2;
import model.HistoryModel;
import generic.event.Events;
// FUCK HEADS https://github.com/caolan/nodeunit#tests-run-in-series
// No ->
var _readFile = fs.readFile;
fs.readFile = function(path, callback){
// its a stub!
};
// test function that uses fs.readFile
// we're done
fs.readFile = _readFile;
@SimonRichardson
SimonRichardson / JQuery Exception
Created February 20, 2013 15:55
This annoys the crap out of me when I'm Pausing on all exceptions in chrome as I have to press Play (F8) to bypass it every god damn time.
try {
// This should fail with an exception
// Gecko does not error, returns false instead
matches.call( document.documentElement, "[test!='']:sizzle" );
} catch( pseudoError ) {
pseudoWorks = true;
}
package ;
typedef Function2Type<T1, T2, R> = T1 -> T2 -> R;
abstract Function2<T1, T2, R>(Function2Type<T1, T2, R>) from Function2Type<T1, T2, R> to Function2Type<T1, T2, R> {
inline function new(func : Function2Type<T1, T2, R>) {
this = func;
}
}
@SimonRichardson
SimonRichardson / Graphics API.hx
Last active December 14, 2015 16:48
Shallow graphics api.
interface IDrawable {}
class DisplayObject {
public function new(drawable: IDrawable){}
}
// Different drawable items
class Bitmap implements IDrawable {}
class Graphics implements IDrawable {}
class Movie implements IDrawable {}
@SimonRichardson
SimonRichardson / MVC Actors
Created April 3, 2013 07:51
Model View Controller using actors
class Model extends Actor {
private state: Int = 0
private listeners: List[Actor] = Nil
def act =loop {
react {
case AddListener(who) => listeners = who :: listeners
case RemoveListener(who) => listeners = listeners.remove(who.eq)
case SetState(st: Int) => state = st; listeners.foreach(_ ! TheState(this, state))
case GetState => reply(TheState(this, state))
}
@SimonRichardson
SimonRichardson / d8-arguments
Last active December 15, 2015 18:09
D8 Arguments to see what's inlined or not.
d8 --use_strict --trace_inlining --trace_opt --trace_deopt --trace_dead_code_elimination --trace-gc Example.js
@SimonRichardson
SimonRichardson / instanceof.js
Created April 8, 2013 15:41
Haxe javascript instanceof improvement.
js.Boot.__instanceof = function(o,cl) {
if (o === null || cl === null) return false;
if (typeof cl === 'function') {
if(o instanceof cl) {
if(cl == Array) return o.__enum__ == null;
return true;
}
if(js.Boot.__interfLoop(o.__class__,cl)) return true;
}
switch(cl) {
@SimonRichardson
SimonRichardson / Curries.hx
Created April 9, 2013 10:26
Got this working now so you can pass wildcards to the carries function.
var a = function(value1, value2, value3) {
return value1 + value2 + value3;
}.carries(1, _, _)(2)(3); // Traces 6
@SimonRichardson
SimonRichardson / jsc.hx
Last active December 16, 2015 00:49
The idea is similar to how .swc works for AVM, but for js. Highly dangerous, but highly effective for packaging lots of js files and assets in one payload.
import haxe.io.Bytes;
import haxe.io.BytesInput;
import haxe.io.BytesOutput;
import format.tools.CRC32;
import format.zip.Data;
import format.zip.Reader;
import format.zip.Tools;
import format.zip.Writer;
class Test {