Rhino Mocks with Managed C++

Rhino Mocks with Managed C++

August 16, 2011  |  Coding  |  Comments Off

Having just had the unfortunate need to use rhino mocks from managed C++ I thought I would document the “how”

Let’s say you want to mock/stub IFoo. Which has two methods:

  • IQux Bar()
  • int Baz(int)

Create a MockRepository:

IFoo^ foo_stub = MockRepository::GenerateStub<IFoo^>();

Stub out Bar() -> Note it doesn’t take a parameter:

Rhino::Mocks::Function<IFoo^, IQux^>^ foo_bar =
    gcnew Rhino::Mocks::Function<IFoo^, IQux^>(&IFoo::Bar);

RhinoMocksExtensions::Stub(foo_stub, foo_bar)->Return(
    /* Another mock/stub or a real IQux */
);

Stub out Baz() -> Note it takes a parameter:

Note, the static method, this will configure the stub for a specific argument, in this example when Baz(1) is called we return 2.

Rhino::Mocks::Function<IFoo^, int>^ foo_baz =
    gcnew Rhino::Mocks::Function<IFoo^, int>(&Test::FooStubBaz);

RhinoMocksExtensions::Stub(foo_stub, foo_baz)->Return(2);

// IFoo will actually be a rhino mock/stub
int Test::FooStubBaz(IFoo^ foo) {
    return foo->Baz(1);
}

Now foo_stub->Baz(1) will return 2

I imagine you could remove the need for a static method but this was enough for my needs and my head!

NeuroSky Mindset gem ... Is nearing completion

NeuroSky Mindset gem … Is nearing completion

July 3, 2011  |  Coding  |  Comments Off

I have recently been playing with the NeuroSky mindset – I have always found this subject fascinating…

Unfortunately the device didn’t come with any Linux software so I decided to write some using ruby. Had a good run at coding this weekend and I’m now finalising the gem – Hope to have it up on git hub and ruby forge this week. I can then move onto coding some fun software on top. Doubt it will have a huge demand but at least it will make using the device a little easier on Linux (and Windows), I needed it so at least one person will benefit!

Update: I have placed an almost finished (just some documentation tidying left) version on GitHub

 

CodeFoo: Agile Feedback Loops Via The Commit

CodeFoo: Agile Feedback Loops Via The Commit

July 3, 2011  |  Coding, Thoughts  |  Comments Off

I’ve been thinking about agile/LEAN feedback loops lately, primarily how I could introduce fun ways to kick start them and hopefully keep them maintained. With this in mind my thoughts turned to the “commit” process. It’s something all developers do (hopefully else your coding without revision control) and provides a nice point in time to inject some automated feedback.

The idea is to have each commit analysed for some simple “agile” metrics, nothing too complex or tricky, examples:

  • Did the commit touch unit tests
  • Was the commit “small”

I imagine you could also run a few simple code quality algorithms also (ones that are regarded as being sensible) and maybe a copy and paste checker. Overall the main aim is to find around three or four simple metrics that the team can agree on that signify good practice.

Then the fun starts, you normalise the values and plug them into a simple fighting game, where they impact the fighters abilities (and looks?), clearly weighted towards the better the metrics, the better the fighter. This new fighter then battles the current one (winner of the last commit war) to see who remains king of the hill.

The whole fight can be e-mailed back as a small movie, statistics can also be kept – If you commit small, unit tested code often you have a high chance of ranking highly.

Think I will code this up. Also wondered about wiring the commit to net hack or an adventure game, I.e. your commit log would contain a string for your next move, on commit you are e-mailed a response. E.g.

# open door

<commit>

"You see a wolf"

Fun, possibly, but not where I was heading.

Ruby Port of TinyMud (WIP!)

Ruby Port of TinyMud (WIP!)

December 14, 2010  |  Coding  |  Comments Off

It started with a conversation in a pub (don’t most things?) related to porting “old” code to newer languages. With my interest in TinyMud I decided to take on the challenge of porting the original c-code to Ruby.

This is now becoming an intense labour of love! I’m wrapping the old TinyMud code as Ruby extensions and writing as many test cases as I can. I’m over half way through now. The idea being to get good test coverage of the c-code (in Ruby) then switch to Ruby equivalent code – Then re-factor to a more Ruby’esque style.

I have to say I’m impressed by the original source code (although I’m finding some edge case defects). I wonder if the Ruby code will be any more compact? Intending to put the result on GitHub at some point – For now it’s a one man mission!

Once complete I will run this on a server and prove wikipedia (sort of) wrong, I quote “No active games currently run on a TinyMUD server”. I could host the original (and I’m in a position to), but I think running a modernised equivalent would be more interesting.

Synchronizing ruby threads with a shared queue

November 5, 2010  |  Coding  |  Comments Off

Whilst working on improving Poodle’s crawler I ran into a nasty problem. I had multiple threads all producing and consuming content from a shared “queue”.

Read More

Poodle is now on github

October 19, 2010  |  Coding  |  Comments Off

It’s taken me more than my highly underestimated “few days” to complete, but  I now have a version of my ruby based search tool up on github, it’s called “Poodle”.  Feel free to use/contribute to, more information here.

It still requires some more work (hence the “0.9″ revision number), hopefully someone else will find it of use and help out.

Fun with Solr and Ruby on Rails

Fun with Solr and Ruby on Rails

September 10, 2010  |  Coding  |  Comments Off

I have been researching search tools for our Intranet/enterprise, after looking at Nutch, MS search server 2010 (express) and plenty of others I decided to write my own, why? A fair question, basically they all had something not quite right about them, varying from rubbish web-front ends to an inability to authenticate with NTLM or go through proxies. Lastly, I thought it would be fun!

The result – I’m almost done, 3 hours of coding! I didn’t start from scratch though, I wrote a simple ruby crawler, wired it to Apache Solr and wrote a rails application to call out to Solr and display the results (no rails database involved – Which differs from the normal RoR and Solr configuration). The RoR application even supports open-search.

The result is excellent! Just fine tuning now and tidying, I will put the code up in a day or two – It will be instructive if nothing else…

[The code is now on Github: https://github.com/mangled/Poodle]

 

Creating a single movie/video from a mix of static images and movies

Creating a single movie/video from a mix of static images and movies

June 3, 2010  |  Coding  |  Comments Off

Recently I needed to create a script to make a single movie from static images and existing movie files. I hacked this together with ruby, ffmpeg and ImageMagick. Note, it will function under windows with little code change.

Putting it up in case someone finds it of use!

Read More

Downloading YouTube videos with Ruby

Downloading YouTube videos with Ruby

May 30, 2010  |  Coding  |  Comments Off

A random script I hacked together (through searching and experimentation) for pulling down videos from YouTube with ruby, its only guaranteed to last along as the current YouTube html formatting lasts.

Read More

Idea: Wiki based IDE’s

March 17, 2010  |  Coding  |  5 Comments

Idea for the day, why not use a wiki as an integrated development environment (IDE)?

I.e. write code in the wiki, configure the build similarly, i.e. which pages will be compiled. Modern wiki’s have configuration management built in, so bye bye svn, git etc. (ok, wiki’s don’t handle this well enough, but again this is an idea not a real product).

The environment by itself supports cross linking, so it self documents and people find it easy to document! The compiler and automated tests can update a build/test result page! With a little thought I think a wiki could manage code better than current IDE’s and integrate the social side. I guess execution of code might be an issue, but one which some more thought would overcome. Possibly this could be integrated into Google Wave?

It’s worth some discussion and further thought – Somewhere, off to bed!