My BLOG on DIY, Hacking and notes

This includes mostly useful information for myself and my BLOG about various free time projects. Which are currently mostly hardware and electronics hacks .

Besides this I'm fully occupied with programming the final parts of MPL, extending my software generation tools such as the precompiler. And finishing my PhD thesis text which is about Creating the integrated programming environment Multi Precision Lab using source code generation tools.

First time visitors, people with comments or questions are welcome to sign my guestbook . Some of my projects in my blog hit the masses like www.hackaday.com featuring binary clock and makezine featuring my Wii-remote hack resulting in 10000 new visitors on the day they appeared in my blog. Cya and have a nice day .

Arkapong for android alpha 2

Written by Walter on 14/10/2013 17:35:29.

Ok added more sound effects and most notably some cool fireworks.
It's like the old version but better in the sense that top player fireworks rain on him when he breaks blocks and bottom paddle gets fireworks if he hits them. Anyway it fills the screen nicely and makes it look cool .

Here's a little preview showing the cpu-vs-cpu mode (or autoplay mainly used for testing):



Once released there is a 1 player. 2 player battle and network 2 player battle that can be chosen. Also loads of specials which will use the fysics engine to add gravity to the playing balls etc.


ArkaPong for android the legend has just begun

Written by Walter on 07/10/2013 20:10:09.

Allright yesterday got my first android game running.
It's going to be a rewrite of the arkapong game we made in the 90's targeted at android's first, then iphone's and ipads.

Now that I started this, I'm having so much fun doing it hope my next contract involves android development again. Android sdk is a breeze if you've got a long java background like me. It's also so similar to writing regular java apps or writing c++ qt apps that's it's a breeze. By using the canvas class this game should work on androids 2.3.x -> 4.x. OpenGL might give some more features and hardware accelleration but it would not work for all the older androids as most of the earlier models don't support the 2d accelerated features I need.



Together on the team is Jasper Nuyens from linux belgium who convinced me at Ohm 2013 to just go for it as he's capable of doing the PR work and also he just went ahead and ordered arkapong.com and found some sample pong demo with sources to start from (it was way buggy but it had a lot of features to give us a head start like playing sounds and whatnot).

Here is a small demo of the alpha version after 3 days of develoment:



So that's pretty smooth (actually the video is less smooth than the real thing here ). Next up will be more animations and specials.

As of yesterday one of the original authors and close friend Anthony Liekens, also my best man at my wedding last year, wants to join the project.

The smartphone market and stores are booming business, let's hope we can make this a winner!


Simple fragment cache and some javascript ninja code for the win!

Written by Walter on 10/09/2013 15:43:00.

Today I decided to optimize one of our most complex pages.
It was long overdue. The view rendering was now taking a whopping 9 seconds and the javascript which dynamically added tri-state selects another +7 seconds or more on a slow pc.



1. Solving the server side view render time :
Basically we have a dynamic permission checker that iterates all controllers and actions and shows an overview for each role. Turns out after some profiling, fetching the actions from routes are not expensive it's rendering +500 checkboxes that screeches our rails app to a halt. Easy 5 min. fix was using a clever fragment cache like so:



<h1>Manage permissions</h1>

<% app_controller_actions, app_controller_paths = Permission.routes_hashes %>
<% permission_cache_key = Digest::MD5.hexdigest( app_controller_actions.to_s+app_controller_paths.to_s ) %>

<%= cache "permissions_#{permission_cache_key}" do %>

... complex view code iterating all controllers and showing the action checkboxes for each login role...

<%end%>



What's nice about this is that it will auto invalidate the cache if the md5 of the set we use to iterate over changes. So if any new controller or action is defined we immediately create a new cached copy. Ow yes and view render time now dropped to 120ms vs the original +9000ms

2. Solving the client side (jquery javascript). We also iterated each row of checkboxes and wanted to minimize/collapse it all (this turns out to not be so slow) what did take time was determining to show a custom label in case some checkboxes we're checked. This was harder to make faster but we could solve it in another way. By (ab)using setInterval we can simulate an asynchronous process. In more modern browsers the issue will solve itself easily with javascript workers. But for now you can use the following ninja scripting:

CODE BEFORE:


$(".select_all").updateTriSelect(); //nice and short alas this hogs the browser and locks it untill all elements are processed


CODE AFTER:


unction batchUpdateTriSelect( inputList ){
var i=0, limit = inputList.size(), busy=false;
var processor = setInterval( function(){
if( !busy ){
busy = true;

//update a single tri-select
if( i < limit ){
element = $(inputList[i]);
updateSelectAll( element.data('controller'), element.data('role') ); //updateTriSelect of single element but unrolled to shave a few milli seconds off...
}

if( ++i == limit ){
clearInterval( processor ); //stop processing, our list is updated.
}
busy = false;
}

}, 1 );
}


The net effect is the browser is responsive straight after the pageload and is processing in the background without disturbing the user experience. woohooo!