Skip to content

Instantly share code, notes, and snippets.

@davespanton
davespanton / gist:1276483
Created October 10, 2011 20:48
Wrapping array indexes
public function getWrappedIndex( index:int, length:int ):int
{
return ((index % length) + length) % length;
}
@davespanton
davespanton / gist:1276608
Created October 10, 2011 21:31
Native process example
public var process:NativeProcess;
[Bindable]
public var output:String = "waiting...";
private function onAppComplete():void
{
if( NativeProcess.isSupported )
setupAndLaunch();
else
@davespanton
davespanton / gist:1276619
Created October 10, 2011 21:34
Native process example pt 2.
#include "stdafx.h"
#include <iostream>
#include <sstream>
#include <windows.h>
int _tmain(int argc, _TCHAR* argv[])
{
POINT pt;
int i = 1;
@davespanton
davespanton / gist:1276698
Created October 10, 2011 22:01
Actionscript only Swiz config
var swizConfig:SwizConfig = new SwizConfig();
swizConfig.eventPackages = [ "com.as3offcuts.as3Swiz.events" ];
swizConfig.viewPackages = [ "com.as3offcuts.as3Swiz.view" ];
var swiz:Swiz = new Swiz( this, swizConfig, null, [ Beans ] );
swiz.init();
@davespanton
davespanton / gist:1276708
Created October 10, 2011 22:05
Actionscript only Swiz bean class
package
{
import com.as3offcuts.as3Swiz.controller.SomeController;
import com.as3offcuts.as3Swiz.model.SomeModel;
import org.swizframework.core.BeanProvider;
public class Beans extends BeanProvider
{
public function Beans(beans:Array=null)
@davespanton
davespanton / gist:1488051
Created December 16, 2011 21:23
Stub Titanium.Network
var originalTiNet = Titanium.Network;
var StubNetwork = function() {};
StubNetwork.createHTTPClient = function() { return originalTiNet.createHTTPClient() };
Titanium.Network = StubNetwork;
@davespanton
davespanton / gist:1488122
Created December 16, 2011 21:40
Return a stub from Titanium.Network.createHTTPClient
var stubClient = function() {};
stubClient.send = function() {};
stubClient.open = function(type, url) {};
spyOn(Titanium.Network, "createHTTPClient").andReturn(stubClient);
spyOn(stubClient, "send");
spyOn(stubClient, "open");
@davespanton
davespanton / gist:2047448
Created March 15, 2012 22:48
New prepareTest method
@Override
public void prepareTest(Object test) {
NutbarTestModule module = new NutbarTestModule();
RoboGuice.setBaseApplicationInjector(Robolectric.application, RoboGuice.DEFAULT_STAGE, Modules.override(RoboGuice.newDefaultRoboModule(Robolectric.application)).with(module));
Injector injector = RoboGuice.getInjector(Robolectric.application.getApplicationContext());
injector.injectMembers(test);
}
@davespanton
davespanton / gist:2589240
Created May 3, 2012 20:47
Assisted Injection
// the factory interface
public interface SMSSendingAlarmFactory {
public SMSSendingAlarm create(Context context);
}
// in the module class
protected void configure() {
@davespanton
davespanton / gist:2589335
Created May 3, 2012 20:53
Assisted Injection dependancy
<dependency>
<groupId>com.google.inject.extensions</groupId>
<artifactId>guice-assistedinject</artifactId>
<version>3.0</version>
<exclusions>
<exclusion>
<artifactId>guice</artifactId>
<groupId>com.google.inject</groupId>
</exclusion>
</exclusions>