Whole numbers divided to get pi

Friday, April 22nd, 2016 | Maths, Rust | Comments Off on Whole numbers divided to get pi

I read someones notes on pi where it states 355 / 113 is a good approximation so I decided to write a rust program to test it out.

It gets to 6 decimal places which the page said fits into 16 bits.

Other ones that are close to pi are 22/7 for 2 decimal places and 31369698 / 9985285 for 13 places

15 places is used for JPL’s highest accuracy calculations, which are for interplanetary navigation, 3.141592653589793



fn main() {
    let start: i32 = 1;
    let pi: f64 = f64::consts::PI;
    println!("{}", pi);

    for n in start..200 {
        let x: f64 = n as f64 * pi;
        let z: f64 = x.round();
        let result: f64 = z / n as f64;
        let samefrac: i32 = count_same(pi, result) - 2; // not counting the 3 and decimal point
        if samefrac > 2 {
            println!("{} / {} - {} - {}", z, n, result, samefrac);

fn count_same(n1: f64, n2: f64) -> i32 {
    let s1: String = n1.to_string();
    let s2: String = n2.to_string();

    let mut count: i32 = 0;
    let mut iter = s1.chars().zip(s2.chars());

    loop {
        match iter.next() {
            Some((a, b)) => { if a == b { count = count + 1 } else { break; } }
            None => { break; }

    return count;

HaxeHybrid – Building For Android using Eclipse

Friday, June 6th, 2014 | Haxe, Mobile | Comments Off on HaxeHybrid – Building For Android using Eclipse

Using openfl it is a fairly simple process to build an apk for Android or build for other platforms. Doing it this way on mobiles will create a full screen app. What if you wanted to include the openfl view as only part of the screen and include it as part of an existing android-sdk project, as an embedded view? It turns out that way the openfl project is setup makes this fairly easy.

The following steps will outline how I created an Eclipse project to build for Android in Windows (the steps should be similar on other OS):

Go through the normal process to compile an openfl project to the android target and run it on a device to make sure there are no errors.

Open Eclipse and Create a new Android Application Project.

Go to  ‘%YourProject%/bin/android’ this will be referred to from now on as %OpenflBin%

Open ‘%OpenflBin%/AndroidManifest.xml’. Copy the parts into your AndroidManifest: ‘uses-sdk’, ‘uses-feature’, ‘uses-permission’ and possibly ‘<category android:name=”tv.ouya.intent.category.GAME” />’

In Eclipse, Import -> Existing Android Code into Workspace -> Press Next -> Browse to folder ‘%OpenflBin%/deps/extension-api’ -> Make sure the project and copy project into workspace is selected.

The project should build then copy the extension-api.jar file to the libs folder in the main project. This library is needed for the GameActivity java class.

The other required libraries are object files, including the ApplicationMain which is your game code. Copy ‘%OpenflBin%/libs/armeabi’ to your libs folder. Each time you make changes to your openfl code, compile and copy ‘ApplicationMain.o’.

OpenFl uses some Java code to create the window using the android-sdk and renders to a GLSurfaceView which specifies the egl renderer from the native code. Go to ‘%OpenflBin%/src/’. There should be ‘MainActivity.java’ under the namespace you used for the openfl project. Copy this to your project overriding the existing version and fix up any package differences. Also copy the other src files which has the namespace ‘org.haxe.lime’.

Copy anything in ‘%OpenflBin%/res/’ to the Ecplise project res folder.

You might need to clean the project to have all the right stuff generated. You should be able to run the project on your device now.

If you want to see a non full screen version of it go to the GameActivity and change the inherited class to ActionBarActivity. In onCreate comment out ‘requestWindowFeature (Window.FEATURE_NO_TITLE);’ and the fullscreen flag below it.

Simple openfl view. The Sprites respond to input.

Simple openfl view. The Sprites respond to input.

Debug Logging for Huawei Ideos X5

Thursday, June 5th, 2014 | Mobile, Tools | Comments Off on Debug Logging for Huawei Ideos X5

I flashed my Ideos X5 to Android 2.3 and enabled debugging but when looking at logcat it showed:

Unable to open log device '/dev/log/main': No such file or directory

A quick search showed the answer on stackoverflow by Berat Onur Ersen:

On call screen type *#*#2846579#*#*
opens system management menu
Project menu -> background settings -> Log setting
Log level setting -> VERBOSE Log switch -> LOG on
Dump and Log -> Checked all the boxes
Restart device.

Waxe with GLCanvas

Saturday, February 8th, 2014 | Uncategorized | Comments Off on Waxe with GLCanvas

I’ve managed to get the Waxe GLCanvas working with lime. I’m not sure if wxWidgets has proper support for OpenGL3 because it only works when the lime window is setup first so it must be something in whatever windowing library is used or maybe when waxe creates the glCanvas different options need to be used. Lime seems to use one of SDL, SDL2 or glfw. I might look into it more later but for now I’ve just done a bit of a hack where a borderless 1×1 lime window is created then immediately shutdown. The waxe window then loads. I could use the lime window as a splash window, showing some info or loading resources before the main window shows.

Waxe Simple Screenshot

The webgl code is copied from Lesson 1: A Triangle and a Square

The project files are at  waxe-Simple . Compile using ‘lime test windows’ . The neko target doesn’t compile for Lime 0.9.2 and other operating systems are untested.

LimeTools Project Filenames

Sunday, January 26th, 2014 | Haxe | Comments Off on LimeTools Project Filenames

I’ve been reading through “haxe\lib\lime-tools\1,2,6\src\CommandLineTools.hx” and found “private function findProjectFile (path:String):String”

It first searches for: “project.hxp”, “project.lime”, “project.nmml” and “project.xml”. It then does a search for all files with the extensions: hxp, lime, nmml and xml. If it finds one that isn’t include.[ext] it gets added to a Map <String, Array > with the key being the extension and the value being the list of files. At the end it looks through each extension and returns the first item in the array if it exists. The extensions are looked at in this order: hxp, lime, nmml, xml.


Getting started with Waxe and OpenFL

Friday, January 24th, 2014 | Haxe | Comments Off on Getting started with Waxe and OpenFL

I’m no expert on either of Waxe orOpenFL but I did get the waxe simple example working with a little massaging as you’ll soon find out.

The below information was needed in addition to the tutorial at http://cambiatablog.wordpress.com/2012/05/19/desktop-applications-with-haxe-and-waxe-part-1/

Once you have installed Haxe 3 and OpenFL/Lime get Waxe from https://code.google.com/p/waxe/ . It doesn’t have a released package for Haxe3 but if you look in the change logs it has “Get Building with haxe3/wxWidgets 3” comment. You will need to install the files manually. Go to where you installed Haxe (“HaxeToolkit\haxe\lib”) and create a waxe folder. Copy one of the .current files from the or create it with an editor since Windows explorer doesn’t allow it. Open the file and put any version number in. Create a folder in the same directory that matches the version with ‘.’ replaced with ‘,’. Put the waxe files in there. It should have the following folders: ndll, samples, src, wx. To test you have installed it properly run on cmd “haxelib list” and you should see waxe with the version you gave.

The next part is getting the project file right. I copied the OpenFL PiratePig example’s project file and used the information from the waxe Simple example to get something like this:

<?xml version=”1.0″ encoding=”utf-8″?>

<meta title=”Simple01″ package=”org.haxe.waxe.Simple01″ version=”1.0.0″ company=”waxe” />
<app path=”Export” file=”Simple01″ main=”Simple” />

<window width=”800″ height=”600″ if=”desktop” />

<source path=”Source” />

<haxelib name=”openfl” />
<haxelib name=”waxe” />

I moved the source into the Source folder and removed the other files. Leaving a structure like this:


With the project setup I tried to run the code with “lime test windows -neko” and got an error about nme.display.ManagedStage not being found in waxe/wx/NMEStage.hx. My first thought was to try changing nme to openfl. This also wasn’t found so I tried removing any references to ManagedStage. This managed to run. I thought maybe something won’t run properly without the ManagedStage code so I had a look for where it is actually located. I found it in openfl-native. I’m not experienced enough to know why it didn’t load so I experimented some more.

Instead of using openfl I replaced it with lime in the project file. This got past the ManagedStage not being found but then I got errors about the Simple class constructor being private. I think lime and openfl do the application entry differently when it creates Simple/Export/windows/neko/haxe/ApplicationMain.hx. I made another class and put what was in main function into the constructor of that new class and in the project file change the main to match the new class. It runs the same as in the first case.

When the waxe window is closed a second window appears. I think this is the openfl window but I will need to do more investigation.



I’ve had more a look at the second window opening issue. It seems it might be possible to not include lime/openfl if you don’t want to use it according to this post but I’d like to use lime for the opengl api so what I did is copy the templates folder lime/templates/haxe to the project templates folder and add this line ( <templatePath name=”templates” /> ) to the end of the project.xml file to override the lime template and commented out the part where lime is initialized. No extra window now and I will hopefully be able to use the opengl api with wxGLCanvas. 🙂


Tags: ,

OpenGLES Multiple Contexts

Thursday, November 21st, 2013 | Mobile, Programming, Work | Comments Off on OpenGLES Multiple Contexts

Don’t forget to set the current context before attempting to use any GL calls otherwise only one glview will render properly.

For ObjectiveC:

[EAGLContext setCurrentContext:context];

MVC Performance Tip

Saturday, August 31st, 2013 | Web Application | Comments Off on MVC Performance Tip

This is really just here so I don’t forget it. From http://geekswithblogs.net/Aligned/archive/2013/05/31/mvc-performance-tip.aspx

This makes sure the web forms view engine isn't being checked when only razor view engine is being used.
protected void Application_Start()
    // since we aren't using web forms .aspx, remove from the view engines
    ViewEngines.Engines.Add(new RazorViewEngine());


Python logging

Thursday, July 26th, 2012 | Python | Comments Off on Python logging

If you get a message like:

No handlers could be found for logger “sleekxmpp.xmlstream.xmlstream”


import logging



Ejabberd External Auth and BOSH

Tuesday, July 3rd, 2012 | Web Application, Work | Comments Off on Ejabberd External Auth and BOSH

A lot of things can go wrong when trying to use an external auth script with Ejabberd. Here are some troubleshooting tips.

E(<0.1026.0>:ejabberd_http_bind:1239) : You are trying to use BOSH (HTTP Bind), but the module mod_http_bind is not started.

  • Check the user’s domain is correct.
  • Check the host is specified in hosts.
  • Make sure mod_http_bind is in the modules section.


=ERROR REPORT==== 2007-10-02 01:09:21 ===
** State machine terminating
** Last event in was {xmlstreamelement,

** Reason for termination =
** {badarg,[{extauth,call_port,2},

  • Make sure the script is executable (ie chmod the file) and is accessible.
  • In the config might need to use eg “python /path/to/file args” instead of just “/path/to/file”.
  • Make sure the script doesn’t have errors. Try this barebones script which is known to work: https://git.process-one.net/ejabberd/mainline/blobs/raw/2.1.x/doc/dev.html#htoc8
  • To reduce errors change the barebones script as little as possible. Put custom code into a module and test independantly of ejabberd.
  • Check the paths of any loaded files in the script. Execution path may be different. Use absolute paths or os.path.dirname(__file__) but make sure to replace empty path with “.” if using the latter.

Tags: ,