Skip to content

Instantly share code, notes, and snippets.

View Stray's full-sized avatar

Stray Stray

  • Innerleithen, Scotland
View GitHub Profile
@Stray
Stray / TogglePanelPositionConditional.as
Created January 19, 2011 13:03
Toggle the position of a panel by conditional (for comparison with other approaches)
private var _isGoingUp:Boolean = false;
private function togglePanelPosition(e:MouseEvent):void
{
var yPos:Number = ON_STAGE_Y;
if(_isGoingUp)
{
yPos = OFF_STAGE_Y;
}
@Stray
Stray / CombinationGameIdeas.as
Created January 14, 2011 11:24
how I started out sketching the combination game
new CombinationGameBuilder()
.requireOneOf ( someItems )
.requireNoneOf ( someOtherItems )
// more rules as required
.build();
package com.client.app.feature.restricted.model {
public class AdminDataLoadingURLVarsFactorySupport extends AdminDataLoadingURLVarsFactory {
public function AdminDataLoadingURLVarsFactorySupport(keyIsGood:Boolean = true) {
if(keyIsGood){
fingerprintKey = new AdminKeyGoodSupport();
}
@Stray
Stray / fileMetrics.rb
Created January 8, 2011 18:38
Counts files, lines, words in a folder (by file extension) and then gives you a pure typing time analysis
require 'find'
if ARGV.length != 2
raise ArgumentError.new('Two arguments are required: path, extension')
end
path = ARGV[0]
extension = ARGV[1]
numFiles = 0
@Stray
Stray / EndToEndTestWishes.as
Created December 4, 2010 16:46
How should I go about this in asunit 4?
package strategy.xendtoendtests {
// imports removed for brevity
public class PyramidGameEndToEndTest extends TestCase {
private var robotEyes:RobotEyes;
private var config:IGameConfig;
private var endToEndTests:Vector.<Class>;
private var runningEndToEndTests:Boolean;
private var dummyDispatcher:EventDispatcher = new EventDispatcher();
@Stray
Stray / LoggingContext.as
Created November 27, 2010 18:57
Easy logging in robotlegs through events
// code required in your context startup - this uses Config::Variables to set the logger at compile time,
// but you could just swap it in/out as required and do away with the if/else etc
commandMap.mapEvent(LoggingEvent.LOG_EVENT, UpdateLogCommand, LoggingEvent);
if(CONFIG::HiddenLogging)
{
injector.mapSingletonOf(ILoggingService, TraceLoggingService);
}
else if(CONFIG::EmailLogging)
@Stray
Stray / GetTheFunctionOwner.as
Created November 21, 2010 20:07
Is this possible?
////////// code in a robotlegs mediator
private function someHandler(e:Event):void
{
// whatever
}
// this mediator adds the handler to the relaxedEventMap
override public function onRegister():void
@Stray
Stray / NosyMediator.as
Created November 16, 2010 11:06
Nosy mediators (or mediator-mini-controllers) open the view's mail
// Good mediator behaviour:
function handleDataEvent(e:DataEvent):void
{
var userVO:UserVO = e.userVO;
view.showUsername(userVO.firstname, userVO.surname);
view.showAge(userVO.age);
view.setStatus(userVO.isSaved);
}
@Stray
Stray / ExampleUITest.as
Created November 8, 2010 16:59
Example roboteyes actual UI Test
package com.client.project.xendtoendtests {
import asunit.framework.TestCase;
import AcademyShell;
import shell.AcademyShellSkin;
import com.newloop.roboteyes.inViewOf;
import com.newloop.roboteyes.core.RobotEyes;
@Stray
Stray / usingCompoundCommandMap.as
Created November 6, 2010 09:44
Map multiple events to trigger a command only when all events are received (in order if required)
// params: command, isOneShot, requireInOrder
compoundCommandMap.mapToEvents(SomeAwesomeCommand, true, true)
.addRequiredEvent(SomeEvent.SOMETHING_HAPPENED, SomeEvent);
.addRequiredEvent(SomeOtherEvent.SOMETHING_ELSE_HAPPENED, SomeOtherEvent, 'somethingElseHappened');
.addRequiredEvent(SomeOtherEvent.STUFF_HAPPENED, SomeOtherEvent, 'stuffHappened');
// in the command itself
[Inject]
public var someEvent:SomeEvent;