Fun Stuff · Games · Programming

Two-Way Box released on the Google PlayStore

Two-Way Box IconTwo-Way Box released on the Google PlayStore: 

Pro Edition: https://play.google.com/store/apps/details?id=com.federrot.twowaybox

Free Edition: https://play.google.com/store/apps/details?id=com.federrot.twowayboxfree

 


Two-Way Box is a two-player inverse-space line-clearing black-white box-game that allows two players to play in the same game field on the same device.

Player 1 plays from the bottom to the top with white boxes in a black game field, while at the same time player 2 plays from the top to the bottom with black boxes in a white game field.

Features:
* 2 Player mode: The player with most wins in 4 matches wins. Both players play on the same device.
* 1 Player modes: Play alone as the white or black player.

Source Code:
The source code of the game has been published for learning purposes on github: https://github.com/tivtag/twowaybox

Advertisements
Fun Stuff · Mathematics · Programming · Project Management

Tech Book List

Almost everyone has an official list of favourite technical books. This now includes me: Here is mine! I hope that you will find something that you also want to read.
.


Kanban
Successful Evolutionary Change for Your Technology Business

Are you overladen and often have to switch between projects and tasks? Do you want to visualize and limit work-in-progress? Or work in a Kaizen culture of continuous and incremental improvement?
.
This book is a good introduction to Kanban. It’s a fun and enjoyable read, but most examples are for larger organizations.

.


.

Seven Databases in Seven Weeks
A Guide to Modern Databases and the NoSQL Movement

This book represents a unique fast-moving deep dive into modern databases of all kinds, from relational to document and graph.
.
PostgreSQL, Riak, HBase, MongoDB, CouchDB, Neo4J, Redis and The CAP Theorem

.


.

The Deadline
A Novel About Project Management

A super entertaining story about a project management experiment. Yes, you will learn something, while having a ton of fun!

.


.

Conceptual Mathematics
A First Introduction to Categories

If you like Functional Programming Languages (like Haskell) and you want to understand their foundations in mathematics, then at some point you’ll want to study Category Theory.
.
This book starts as a very easy read and continuously gets more challenging as you uncover the magical world of categories and conceptual mathematics. Greatly recommended. Also see: my blogpost.

.


.

Programming Ruby 1.9
The Pragmatic Programmers’ Guide

Programming Ruby by Dave Thomas

The goal of Ruby is to make programmers happy. Do you want to be happy while coding? Then you should learn Ruby.
.
This book will give you a great starting point that explores the basic but also some deeper concepts of Ruby. You will be enlightened. Also see: my blogpost.

.


.

Thinking about Android Epistemology
(No, not those smart phones; but maybe.. some day?)

A series of enjoyable and not-too-much-technical essays. You will be confronted with questions of epistemology (the study of knowledge) and philosophy of minds so very different from ours (and yet so equal) – artificial machines.

.


.

GUI Bloopers 2.0
Common User Interface Design Don’ts and Dos

Did you ever build a piece of software with a graphical interface? Was it perfect? Are you sure? Please read this book now. It’s also very fun.

.


.

Learn You a Haskell for Great Good!
A Beginner’s Guide

This hilarious book (just look at what the sun has to say at the website!) teaches you functional programming fundamentals from the ground up to mastering functors, applicative functions, monoids, and even the dreaded monads. Those won’t scare you any more, but will be your best friends afterwards.
.
The e-book is free. Also see: my blogpost.

.


.

Haskell Road to Logic, Maths and Programming
(Warning: complex – hard work required!)

This book is an in-depth introduction into the mathematics that lie behind functional programming languages and computer science.
.
Don’t be fooled – this won’t teach you Haskell. It is best to learn the tool – Haskell – first, before starting this complex but beginner-friendly book.

.


.

Clean Code
A Handbook of Agile Software Craftsmanship


‘Programmers who satisfy themselves with merely working code are behaving unprofessionally. .. Bad code rots and ferments, becoming an inexorable weight that drags the team down.’

Mandatory reading for aspiring professional developers. Be warned that this is a very opinionated book and it exclusively uses Java – but with the right set of scepticism you will be able to pick many life-long lessons.
.
Please-please don’t be one of those that don’t care about the quality of their code. Please! I beg you.

.


.

Domain Driven Design
Tackling Complexity in the Heart of Software

This book will teach you how to design robust and maintainable application for complex problem domains.
.
Heureka! You will add many useful items to your object-oriented-design tool belt.

.


.

Gödel, Escher, Bach
An Eternal Golden Braid

‘Hofstadter’s Law: It always takes longer than you expect, even when you take into account Hofstadter’s Law.’

A magnificent journey about K. Gödel‘s Incompleteness Theorem, M. C. Escher‘s self-referential worlds, J. S. Bach‘s mathematical music, formal systems, the self, the meaning of meaning, cognition, ant colonies, and indeed very strange loops.

.


.

Learn You Some Erlang for Great Good!
A Beginner’s Guide

Similar to Learn You a Haskell for Great Good! but for Erlang.
.
Erlang and the Open Telecom Platform are different, useful and a fun learning experience. Hey, Prolog-style syntax. But as always: Don’t drink too much Kool-Aid! Also take a look at Elixir.

.
:edit: Added Learn You Some Erlang for Great Good!

Graphics · Programming

OpenGL experiments

Recently I have been learning basic realtime 3D graphics using OpenGL ES 2.0GLSL and C++. This is my first time coding anything more serious in 3D and also OpenGL! In theory this could run on any platform that supports OpenGL ES 2.0; ranging from PCs to Smart Phones. All of the content was used purely for learning purposes.

Cross-Platform window management using PowerVR VRShell.
Initialization of projection and view matrices with the help of GLM (OpengGL Mathematics).
Rendering 3x colored cubes using a single Vertex Buffer Object. Simple interpolating-color fragment shader.

3x Textured CubeLoading of image data using FreeImage. Rendering of three rotating and textured cubes.

Used Libraries: OpenGL ES 2.0, GLM, FreeImage, OOIS, Boost

Programming · Source Code

C# <3 Ruby

IronRuby allows you to get some of the freedom and expressiveness of Ruby in the .NET biz. world. Recently I’ve been using it as a simple game scripting language.

Warning: This post is a beginner tutorial on how to get started with hosting IronRuby inside your C# application.
.
.
C# loves Ruby
.
Step 1
Download the IronRuby binaries from Codeplex: http://ironruby.codeplex.com/ Warning: As of writing this the IronRuby 1.1.3 installer won’t install the binaries.

Step 2
Add references to IronRuby.dll, Microsoft.Csharp.dll and Microsoft.Scripting.dll to your project.
.
Step 3
ScriptEngine and ScriptScope are the key classes of the Dynamic Language Runtime that allow us to run Ruby code: (Download Tutorial Source Code – Rename to Zip)

// Tutorial 1:

// Initiate the main object that drives IronRuby:
var engine = IronRuby.Ruby.CreateEngine();

// And here goes the magic:
engine.Execute( "puts 'Meow, from Ruby!'" );
// Tutorial 2:
var engine = IronRuby.Ruby.CreateEngine();

// ScriptScopes allow you to capture variables and methods
// within a specific non-global scope.
ScriptScope scope = engine.CreateScope();

// The ScriptScope API allows us to easily set variables
// from .NET:
scope.SetVariable( "score", 10 );

// You can also use Ruby to set variables:
engine.Execute( "max_score = 10", scope );

// Let us access the variables now. Note the usage of "%Q/ /"
// as a replacement of " " in our Ruby code.
engine.Execute( "puts %Q/Your score is #{score} of #{max_score}!/", scope );

.
Step 4 – Domain Specific Languages
We can ‘teach’ our scripts a set of specialized methods that make it easy to interact with the problem domain. With the help of Ruby’s expressiveness our scripts will look more like a custom language that is focused on the target domain. See Teta on github for a text adventure that is build around a Ruby DSL.

# Here's a silly example from my Zelda fangame:
on_time_changed do |time|
  if time == 'DayBegan' then
    if roll_1_in 100 then
      spawn_item 'Ruby1'

      after_seconds 2 do
         fairy_says "Oh, what's that? Lucky!"
      end
    end
  end
end
// Tutorial 3 - how to get started with a Ruby DSL from C#:
var engine = IronRuby.Ruby.CreateEngine();
var scope = engine.CreateScope();

string domain =
    @"
        class Universe
            attr_accessor :underlying_theory
            attr_accessor :groups

            def initialize()
                @groups = []
            end

            def to_s
                %Q/Universe based on #{underlying_theory} is filled with: #{groups}./
            end
        end

        class Group
            attr_accessor :name
            attr_accessor :galaxies

            def initialize()
                @galaxies = []
            end
        end

        class Galaxy
            attr_accessor :name
        end
    ";

// Now teach it about our domain. You could use normal C# classes too.
// But those might be at times be more awkward to access from within Ruby.
engine.Execute( domain, scope );

string dsl =
    @"
        # DSL:
        def universe(hash)
            u = @@current_u = Universe.new()
            u.underlying_theory = hash[:based_on]

            yield if block_given?
            u
        end

        def group(named)
            g = @@currrent_g = Group.new()
            g.name = named

            yield if block_given?
            @@current_u.groups << g
        end

        def galaxy(named)
            g = Galaxy.new()
            g.name = named

            @@currrent_g.galaxies << g
        end
    ";

// 'Enable' our tiny DSL:
engine.Execute( dsl, scope );

// And lets use it to create some universes:
string ruby =
    @"
        mt = universe based_on: 'M-Theory' do
            group 'Local group' do
                galaxy 'Milky Way'
                galaxy 'Andromeda Galaxy'
                galaxy 'Triangulum Galaxy'
            end

            group 'Virgo Cluster'
            group 'Centaurus Supercluster'
        end

        hlt = universe based_on: 'HL-Theory' do
            group 'Black Mesa' do
                galaxy 'On a Rail '
                galaxy 'Questionable Ethics'
                galaxy 'Lambda Core'
                galaxy 'Nihilanth'
            end
        end

        et = universe based_on: 'Empty-World Theory'
        [mt, hlt, et]
    ";

// ScriptEngine.Execute returns our list of universes as the result of the ruby code:
dynamic universes = engine.Execute( ruby, scope );

foreach( dynamic universe in universes )
{
    Console.WriteLine();
    Console.WriteLine( universe );
}

.
Step 5 – Miscellaneous Notes
I encourage you to use a Test/Specification Driven Development style when working with your Ruby scripts (It is imho a must with dynamic languages). Personally I can’t yet rate how easy/hard it is to get something like RSpec running with IronRuby and loose scripts.

The outside image of IronRuby looks a bit shady at the moment. The official website doesn’t link to the newest version, and all in all the project is fragmentted over too many different domains. It doesn’t help that the installer and Visual Studio integration (v 1.1.3) is somewhat bugged. From the inside we’ve got a very solid product that can get you some of the Ruby love inside the .NET world. Thanks to the open source community on continuing work on IronRuby and IronPython! <3

.
::Edit Step 6 – Tip: Compile from Source ::Edit (30.06.2012)
To get the best experience, until the IronRuby team decides to release a new version, you should compile IronRuby from source for your target framework. This has shown to give me a great performance increase. Great work!

.
Step 7 – Additional Resources
IronRuby Tutorial Source Code – Rename to Zip

IronRuby on Codeplex
IronRuby Mailing List
IronRuby Source Code
IronRuby Issue Tracker

Games · Programming · Source Code

Introducing a ruby adventure in text or how I learn(ed) Ruby

I am currently studying the Ruby programming language. You know; as a software developer you should learn at-least one new language per year! Ruby is a dynamic multi-paradigm programming language that is really fun to use!

This time around I’ve decided to focus on learning a testing framework for Ruby very early. My choice was the very elegant rspec specification framework. RSpec, as most great Ruby libraries, uses an (internal) Domain Specific Language to describe its application domain; which in RSpecs case is describing the expected behaviour of your application.

At the very beginning of my journey I’ve used the Interactive Ruby (irb) REPL (Read-Eval-Print Loop) to explore the language. REPLs are a great way to explore your language of choice! Soon after I’ve started to write tests (or rather specifications) for features of the Ruby language. Personally this didn’t keep me going for very long; it was quite useful.. but.. I needed an actual project to work on!

Of all the goodies Ruby comes with, its Meta Programming features are the most thrilling for me. I wanted to write my own Domain Specific Language (DSL) inside Ruby. And thus was born Teta, a ruby text adventure!

Take a look at this link for an example of the DSL. (You can find all of the source code of Teta on github.)

When I am working on Teta I use three Terminal sessions (in TABs). The 1st TAB has got VIM loaded to edit the source code (Derek Wyatt has got tons of great tutorial videos about VIM):

VIM text editor

.
The 2nd TAB is used to issue various commands; including executing all rspec specifications or pushing changes to the git repository. I also use it to access the great ruby documentation (using the ri command):

Teta Rspec Specifications

.
And finally the 3rd TAB has got an interactive ruby session loaded for exploration and experimentation:

Interactive Ruby

.
But back to learning new languages using Test Driven Learning. It was initially a blog post by @pragmatrix that pushed me into the direction of using a testing framework when first learning Ruby. To say the least; it was really worth it!

In case you are like me and don’t feel like writing tests for language features; then there are some great people who already did this for you. The Ruby Koans walk you along the path to enlightenment:

.
If you also want to get started with Ruby then I suggest that you get the following equipment:

1. Ubuntu (Wubi)
2. VIM
3. Ruby Version Manager to install..
4. Ruby
5. RSpec gem as the testing/specification framework
6. Git to get data to and from github
.
Till then, enjoy the journey \o/

Design Patterns & Best Practices · Programming

Code: Abstract Unit of Work

Today I’ve been tinkering about how to best implement the
Unit of Work/Repository patterns at the client (service)-side.

Warning! This blog post contains experimental source code!

What I want:
1. Simple to use. Usage is easy to explain.
2. Doesn’t leak the underlying data access framework.
3. Supports transactions.
4. Supports multiple parallel units of work when required.
5. Manages the session/context scope for me.
Not quite sure whether I need nested UoWs.

Here is what I have come up so far. I’ll update this post once I figure out something new about all of this.


// Scoped unit of work:
// 1. Quite simple
// 2. Repositories use the currently active UoW
// 3. Doesn't support multiple UoWs to be active
// 4. Using block scopes the current session/object context
// 5. Repositories are injected using the constructor
using( UnitOfWork.Start() )
{
   var user = this.userRepository.GetUserByName( "Paul" );
   var skill = this.skillRepository.GetSkillByName( "Ruby" );
   user.Award( skill );
}

// Scoped UoW, that also starts a new transaction:
// When the UoW is disposed it will be rolled-back
// unless it has been committed.
using( var uow = UnitOfWork.Start( transaction: true ) )
{
   var user = this.userRepository.GetUserByName( "Paul" );
   var skill = this.skillRepository.GetSkillByName( "Ruby" );
   user.Award( skill );
   uow.Commit();
}

Update:
If the current Unit of Work is marked to be unique for each thread (ThreadStaticAttribute) it can safely handle multiple ‘requests’ at the same time. No need for any >special case< handling.

Thanks to @pragmatrix for pointing this out on Twitter. :)