Skip to content

Instantly share code, notes, and snippets.

View robertpenner's full-sized avatar

Robert Penner robertpenner

View GitHub Profile
@robertpenner
robertpenner / SaveFlowRobert.as
Created October 31, 2011 14:15
Command Flow DSL Comparison
const saveFlow:Flow = new Flow(
{
saveSeq : new Sequence(
[
new Attempt(ValidateChanges).guard(NotQuitting).fail(ShowError),
new Attempt(ConfirmWithUser),
new Execute(BlockQuitting),
new Attempt(SaveData).fail(saveDataErrorSeq),
new Execute(StoreSavedData),
new Execute(UnblockQuitting)
@robertpenner
robertpenner / Rectangle.as
Created February 15, 2012 02:13
flash.geom.Rectangle decompiled from playerglobal.swc (11.1)
package flash.geom{
[native(cls="RectangleClass", gc="exact", instance="RectangleObject", methods="auto")]
public class Rectangle {
public var x:Number;
public var y:Number;
public var width:Number;
public var height:Number;
public function Rectangle(x:Number=0, y:Number=0, width:Number=0, height:Number=0){
@robertpenner
robertpenner / describeType.as
Created February 15, 2012 02:49
describeType() decompiled from playerglobal.swc (11.1)
//Created by Action Script Viewer - http://www.buraks.com/asv
package avmplus{
public function describeType(value, flags:uint):XML{
var e:XML;
var o:Object = describeTypeJSON(value, flags);
var x:XML = typeXml.copy();
x.@name = o.name;
if (o.traits.bases.length){
x.@base = o.traits.bases[0];
};
@robertpenner
robertpenner / basicreduce.js
Created October 21, 2013 11:00
Functional JavaScript Workshop Solutions
function countWords(inputWords) {
return inputWords.reduce(function(counts, word) {
counts[word] = (counts[word] || 0) + 1;
return counts;
}, {})
}
module.exports = countWords
@robertpenner
robertpenner / gist:a9bf52740308544e2973
Created November 1, 2014 09:03
Frozen's top 4 songs: behold the lyrical craftsmanship!
1. I never see you anymore / Come out the door
2. We don't have to feel it anymore! / Love is an open door!
3. The window is open, so's that door / I didn't know they did that anymore
4. Let it go, let it go! / Can't hold it back anymore.
Let it go, let it go! / Turn away and slam the door.
@robertpenner
robertpenner / gear.md
Last active August 29, 2015 14:15 — forked from joelhooks/gear.md
//MIT License
//Author: Max Irwin, 2011
//Floodfill functions
function floodfill(x,y,fillcolor,ctx,width,height,tolerance) {
var img = ctx.getImageData(0,0,width,height);
var data = img.data;
var length = data.length;
var Q = [];
var i = (x+y*width)*4;
// really more a struct/interface
class DataStore {
store: (object: any, key: string) => string;
get: (key: string) => any;
}
class JsonDataStore extends DataStore {
getRawJson: () => string;
static create(fileWriter: FileWriter): JsonDataStore {
@robertpenner
robertpenner / node.es6imports.d.ts
Last active August 29, 2015 14:21
node.d.ts with ES6 imports so TypeScript can --target ES6 without Error TS1202: Import assignment cannot be used when targeting ECMAScript 6 or higher. Used regex search: import[ ]+(\w+)[ ]+=[ ]+require\(\"(\w+)\"\) replace: import * as $1 from "$2"
// Type definitions for Node.js v0.12.0
// Project: http://nodejs.org/
// Definitions by: Microsoft TypeScript <http://typescriptlang.org>, DefinitelyTyped <https://github.com/borisyankov/DefinitelyTyped>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/************************************************
* *
* Node.js v0.12.0 API *
* *
************************************************/
@robertpenner
robertpenner / 3D TypeScript cubes, wireframe and shading.markdown
Created May 23, 2015 04:35
3D TypeScript cubes, wireframe and shading

3D TypeScript cubes, wireframe and shading ('-' * 42) 3D cubes with wireframe and shading in TypeScript.

I wanted to see how well this preprocessor works. The editor doesn't cope with it that well quite yet. The indentation doesn't quite work, nor does the syntax highlighting.

Also, when an error occurs, it always points to line 1. No matter what the error is.

It also is rather difficult to access external symbols from secondary script files, for example, new Stats() isn't possible, but that's just a TypeScript annoyance.