Daniel, technologiest at heart, a curious person and a sharp developer. He leaves in Israel and works as an independent consultent and architect working with local Hi-Tech companies to build solid and efficient software system. Daniel first love was javascript back in the day when html was practically domless, that was untill he came across C# and the .net framework. you can see some of his works at www.dnastudio.co.il and read his ramblings in hebrew at http://blogs.microsoft.co.il/blogs/danielisimo

Home page: http://www.codeinvain.com

Posts by daniel

rails console pry integration

this gist enables simple support for loading pry console within rails application ,

instead of typing

my-rails-project$ pry -r ./config/environment

just type

my-rails-project$ rails p

just replace script/rails with the content of rails/pry  gist

[gist id=1172869]

in this method you keep both ‘rails c’ to run rails with IRB and ‘rails p’ to run with pry.

if you want just want pry used instead of irb update config/environments/development.rb with the following

[gist id=1172923]

installing ruby mysql with native extensions on mac osx (64 bit)

getting an error `<main>’: undefined method `query’ for #<Mysql:0x00000100913e20> or sort (also for methods init, each etc’) are common for mysql ruby driver that is not installed correctly or without native extensions.

to fix this issue just run the following commands:

1. brew install mysql-connector-c

2. sudo gem install mysql — –with-mysql-lib=/usr/local/mysql/lib

(/usr/local/mysql/lib is my local mysql installation folder)


my stack is

rvm / ruby 1.9.2

gem 1.8.5

mysql  Ver 14.14 Distrib 5.5.12, for osx10.6 (i386) using readline 5.1 (64 bit dmg installation from mysql website)

mac 10.6.8

hope it helps .




Show the Current GIT Branch and Tag in Your Command Prompt

Following Eran’s post on showing current git branch, here is an improved version including branch or tag number (which is helpful in repositories like nodejs) .

in order to differentiate between branches and tags the script prints branches in braces () and tags in square braces [].
[gist id=988852]

Installing QT 4.7.x for VS2010

had some issues installing QT on windows with vs2010 so I thought I’ll share the solution that worked for me.

I’m using win7 64 bit , vs2010, qt 4.7.1

What do I need ?

qt add on for visual studio (qt-vs-addin-1.1.7.exe)
qt open source distribution (qt-everywhere-opensource-src-4.7.1.zip)

Installation Process

  1. download and install qt add on for visual studio
  2. download qt open source distribution
  3. create qt directory (i used C:\Qt\4.7.1×32\)
  4. extract the zip contents into previously created folder (extract files & folders not the root directory named qt-everywhere-opensource)
  5. open visual studio command prompt named Visual Studio Command Prompt (2010) use the command prompt with this explicit name, there are other command prompts for 64 bit using them eventually will fail the process.
  6. run the following commands
[gist id=711441]

Working With Large Arrays in Action Script

While working on partly connected system using flex technology I figured out quick enough that working with large data sets (thousands of records) is not applicable. Especially because i held a number of those sets which I needed to  cross reference in number of occasions.

My solution was to create an indexed collection which i can benefit both worlds of Dictionary and ArrayCollection , with that in mind I designed and implemented the IndexedArrayCollection.

The collection extends ArrayCollection and adds the capability of indexing a single member of an object in the collection (I assume that each element is an object).

IndexArrayCollection constructor receives two arguments first is a source array and second is the index field name (attribute name).

[gist id=479664]

Pong Applied Box2DFlex Physics Engine

I decided to learn by example and assigned myself the goal of building pong in box2d.

box2d is an overkill for pong , but what do you know, it’s damn easy.

[iframe src=http://www.codeinvain.com/blog/wp-content/uploads/2010/07/Box2DDemos/Pong2D.html width=840 height=440]

the gist of it is :

  • layout
  • world setup
  • event handling

Full source code hosted in github Pong in Box2DFlex.

The layout

a SkinnablePhysicsContainer holding two border containers (named p1 and p2) which are the player bars and corelating p1Goal and p2Goal which will act as hit area for the ball graphics element (Ellipse).

[gist id=485641]

Setting Up the World

when the application loads it maps all elements in the physics container to box2d bodies , in woldSetup method i specified different mapping types to components

The key thing you need to know is that you want  p1, p2 and the goals controls to be kinematic bodies so

  • they are not affected by collations and
  • they do not collide with each other
  • they affect dynamic bodies colliding into them

and an event handler onBodiesContact that triggers when two bodies collide .

[gist id=485646]

Event Hadnling

onBodiesContact is triggered each time two bodies collide indie it i do a simple test to see which to bodies collided and triggers the respective indicator.

world_mouseMoveHandler is handling the translation of mouse position and movement of p2

var p2b:b2Body = worldUIContainer.getComponentBody(p2);
p2b.SetPosition(new b2Vec2(p2b.GetPosition().x,worldUIContainer.worldDef.meter(nextPos)));

[gist id=485710]

Box2D Flex Complex Shapes Mapping

One of the drawbacks in box2d is that it’s not supporting concave polygon shapes .

for that box2d flex employs several algorithms and converts a complex shape to a set of polygons (I took the idea from 3d modeling)

at this point i would like to give credits to

both state that their algorithms are far from perfect but for a v0.2 it’s a good start.

in this case I’ll start from the demo and then go into the code so see how the doll bellow is segmented to several triangles.

[iframe src=http://www.codeinvain.com/blog/wp-content/uploads/2010/07/Box2DDemos/OutlineShape.html width=802 height=602]

first thing is to understand how what the doll constructs of , in our case it’s a graphics

[gist id=473475]

our object can be comprised of anything , graphic shapes , ui controls, images etc’ it has only one caveat - It’s edges must be transparent .

The next thing it to take a look at our physics container

[gist id=473480]

you can see that autoStartPhysicsEngine is set to false. By default SkinnablePhysicsContainer maps all it’s flex objects to box2d shapes on creation, this time we want to interfere before hand and give the engine a different directive to try and map the shape not by it’s boundingBox but by it’s actual edges.

This is done by actionscript code, in which we tell our physics container to parse complex shape and pass it with the shape id and a parsing object, afterwards we call the physics engine to start.

[gist id=473486]

you can see the the shape parser receives an argument specifying the quality of it’s mapping , this is done for performance  improvement but might impair edges fidelity.

Simple Box2D Flex Example

following my previous post announcing Box2D Flex framework i want to share some techniques via examples on how to use the library.

First thing we create add a SkinableContentContainer to and drop some contorls inside it

[gist id=473443]

This, still, does not do anything fancy it just initializes box2d and registers & measures all controls inside our physics container.

next step we add some bindable controls that will change our physics gravity and debug

[gist id=473454]

and the bindable properties to our physics container

[gist id=473449]

now we can play with the gravity sliders and see flex controls bounce around

[iframe src=http://www.codeinvain.com/blog/wp-content/uploads/2010/07/Box2DDemos/Box2DFlex.html width=853 height=540]

Announcing Box2D Flex framework


In a previous post demonstrating box2d integration with flex I made a promise (mainly to myself) to share the demo code. When I started to review with sharing in mind it looked cumbersome and overly verbose. So I started cranking on it fixing and straightening the code & architecture and step by step I realized that I’m creating a small Integration layer rather then a POC.

Announcing Box2DFlex

Box2DFlex framework allows you easely integrate box2d into flex framework using mxml. The framewok helps easy integration with flex and exposes box2d world for advanced manipulation.
  • extends SkinnableContainer uses flex component lifecycle model
  • uses regular MXML and AS flex components
  • supports complex shaped flex components (convex and concave) conversion to b2d shapes.
  • allows multiple worlds side by side

[iframe src="http://www.codeinvain.com/blog/wp-content/uploads/2010/07/Box2DDemos/HelloBox2DWorld.html" width="640" height="480"]

Getting Started

In order to play with Box2dFlex you will need flash builder 4 and Box2DFlex source which is hosted on GitHub.

and in four simple steps you should

  1. download the source code
  2. inport the Box2DFlex and Demos  projects into flash builder 4
  3. compile
  4. Play with the eamples in Box2Demos project

Building Your Own b2d World

  1. download the framework
  2. create a new project
  3. add refrence to <Box2DFlex dir>/Box2dFlexLib/bin/Box2DFlexLib.swc
  4. in your MXML add a new SkinnablePhysicsContainer
  5. set the container’s yGravity property to 10 and autoStartPhysicsEngine to true (yGravity=”10 autoStartPhysicsEngine=”true”)
  6. if you want your world to contains walls use setBoundries=”true” attribute
  7. place a button inside SkinnablePhysicsContainer and set it’s properties (width / height / label)
  8. run the project

Timezone shift in bootcamp

Another short one , each time i open my bootcamp or VM (parallels or fusions) i get different timezone for windows and osx.
both are configured correctly connected to the internet and updated from ntp server.

But the windows machine is persistently offsets by two hours. After some hunting around and some trial and error I found that the best and quickest solution is adding a new registry key to HKLM\SYSTEM\CurrentControlSet\Control\TimeZoneInformation\ named RealTimeIsUniversal typed REG_DWORD and set it’svalue to 1

[gist id=464413]

you can also patch your registry by downloading bootcamp clock registry update and running it on your windows machine.

daniel's RSS Feed
Go to Top