Skip to content

Instantly share code, notes, and snippets.

View shannah's full-sized avatar

Steve Hannah shannah

View GitHub Profile
@shannah
shannah / not_working.m
Created October 6, 2012 21:02
JNI method that crashes
JNIEXPORT jstring JNICALL Java_ca_weblite_mactools_Sandbox_saveDialog
(JNIEnv *env, jobject jthis, jstring title, jstring extension){
JNF_COCOA_ENTER(env);
jstring path;
//@autoreleasepool {
NSString *cocoaExtension = JNFJavaToNSString(env, extension);
NSSavePanel *panel = [NSSavePanel savePanel];
NSArray *types = [NSArray arrayWithObjects: cocoaExtension,nil];
@shannah
shannah / TowersOfHanoi.java
Created December 6, 2012 22:22
Towers Of Hanoi class used for benchmarking CodenameOne
package com.mycompany.myapp;
public class TowersOfHanoi {
public static void move(int n, int startPole, int endPole) {
if (n == 0) {
return;
}
int intermediatePole = 6 - startPole - endPole;
@shannah
shannah / StateMachine.java
Created December 6, 2012 22:25
Excerpt from Statemachine that responds to button press to perform benchmark.
protected void onMain_BtnTowerOfHanoiAction(Component c, ActionEvent event) {
final Label towerOfHanoiLabel = this.findLblTowerOfHanoi();
towerOfHanoiLabel.setText("Calculating.... Please wait");
if ( isCalculatingHanoi ){
return;
}
isCalculatingHanoi = true;
Thread t = new Thread(new Runnable(){
@shannah
shannah / com_mycompany_myapp_NativeTowersOfHanoiImpl.m
Created December 6, 2012 22:28
Native method with towers of Hanoi benchmark.
#import "com_mycompany_myapp_NativeTowersOfHanoiImpl.h"
void com_mycompany_myapp_NativeTowersOfHanoiImpl_move(int n, int startPole, int endPole) {
if (n == 0) {
return;
}
int intermediatePole = 6 - startPole - endPole;
com_mycompany_myapp_NativeTowersOfHanoiImpl_move(n - 1, startPole, intermediatePole);
com_mycompany_myapp_NativeTowersOfHanoiImpl_move(n - 1, intermediatePole, endPole);
}
@implementation com_mycompany_myapp_NativeTowersOfHanoiImpl
@shannah
shannah / StateMachine.java
Created December 6, 2012 22:29
Controller method to run the native towers of hanoi benchmark
protected void onMain_BtnNativeTowerOfHanoiAction(Component c, ActionEvent event) {
final Label towerOfHanoiLabel = this.findLblTowerOfHanoi();
towerOfHanoiLabel.setText("Calculating.... Please wait");
if ( isCalculatingHanoi ){
return;
}
isCalculatingHanoi = true;
Thread t = new Thread(new Runnable(){
@shannah
shannah / com_mycompany_myapp_NativeTowersOfHanoiImpl.m
Created December 6, 2012 22:31
Revised Towers of Hanoi Benchmark with static variable that is incremented.
#import "com_mycompany_myapp_NativeTowersOfHanoiImpl.h"
static counter = 0;
void com_mycompany_myapp_NativeTowersOfHanoiImpl_move(int n, int startPole, int endPole) {
if (n == 0) {
return;
}
int intermediatePole = 6 - startPole - endPole;
com_mycompany_myapp_NativeTowersOfHanoiImpl_move(n - 1, startPole, intermediatePole);
//NSLog(@"Move %i from %i to %i", n, startPole, endPole);
com_mycompany_myapp_NativeTowersOfHanoiImpl_move(n - 1, intermediatePole, endPole);
@shannah
shannah / TowersOfHanoi.java
Created December 6, 2012 22:33
Towers Of Hanoi class used for benchmarking CodenameOne revised with static variable incrementing.
package com.mycompany.myapp;
public class TowersOfHanoi {
public static int counter = 0;
public static void move(int n, int startPole, int endPole) {
if (n == 0) {
return;
}
int intermediatePole = 6 - startPole - endPole;
@shannah
shannah / TowersOfHanoi.java
Created December 7, 2012 01:13
Towers of Hanoi changed to use object methods instead of static methods.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.mycompany.myapp;
/**
*
* @author shannah
*/
@shannah
shannah / StateMachine.java
Created December 7, 2012 01:14
Benchmark after changing to object methods.
protected void onMain_BtnTowerOfHanoiAction(Component c, ActionEvent event) {
final Label towerOfHanoiLabel = this.findLblTowerOfHanoi();
towerOfHanoiLabel.setText("Calculating.... Please wait");
if ( isCalculatingHanoi ){
return;
}
isCalculatingHanoi = true;
Thread t = new Thread(new Runnable(){
@shannah
shannah / com_mycompany_myapp_NativeTowersOfHanoiImpl.m
Created December 7, 2012 01:27
Towers of Hanoi using objective-c messages.
#import "com_mycompany_myapp_NativeTowersOfHanoiImpl.h"
@implementation com_mycompany_myapp_NativeTowersOfHanoiImpl
-(void)move:(int)n startPole:(int)startPole endPole:(int)endPole
{
if (n == 0) {
return;
}
int intermediatePole = 6 - startPole - endPole;