# Code you love - share yours!

Thought this would be a nice way to start the year - have you seen or written a function (or method) or piece of code that you are particularly fond of? Perhaps you admired its simplicity (or complexity!) or maybe your surprised yourself or surpassed your own expectations of what is possible?

3 Likes

Hey Ashton, when GenStage was first released I wanted to make something practical with it in Elixir and ended up writing my own job manager. Then later I found a use case for this code which was sitting on the shelf. Felt pretty sweet.

2 Likes

This sounds great. This will help a lot of junior developers like myself.

2 Likes

When i started freecodecamp but using Elixir. The language helped me understand recursions and told me to forget hoisting and other quirks with JS (except closures).

1 Like

Iâ€™ve always admired the fast inverse square root function from Quake III Arena:

``````float q_rsqrt(float number)
{
long i;
float x2, y;
const float threehalfs = 1.5F;

x2 = number * 0.5F;
y  = number;
i  = * ( long * ) &y;                       // evil floating point bit level hacking
i  = 0x5f3759df - ( i >> 1 );               // what the fuck?
y  = * ( float * ) &i;
y  = y * ( threehalfs - ( x2 * y * y ) );   // 1st iteration
// y  = y * ( threehalfs - ( x2 * y * y ) );   // 2nd iteration, this can be removed

return y;
}
``````

This functions is called millions of times in that game, because you need to do inverse square roots to do graphics.

Thereâ€™s a good write up on itâ€™s history and meaning on Wikipedia.

2 Likes

Hey @AstonJ, thanks again for this thread. It motivated me to dust off an article I had sitting as a draft and finally publish it. Roll your own Queue Processor in Elixir with GenStage

2 Likes

I was very proud when I translated Joe Armstrongâ€™s tetris from Erlang to Elixir

2 Likes

Such low level stuff I donâ€™t understand

2 Likes

wow! bookmarked!

2 Likes

Make it a LiveView or ECSx app and put it on the web Koko!

I already wrote the pluginâ€¦ it is available here

But it is old code, itâ€™s when I started Elixir

2 Likes