AstonJ

AstonJ

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?

Whatever the reason, please share! :blush:

Most Liked

ragamuf

ragamuf

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.

dyowee

dyowee

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

ohm

ohm

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.

Where Next?

Popular General Dev topics Top

AstonJ
I just watched this: (tldr: remove bad choices so you don’t need to use willpower) It got me thinking about ways to incre...
New
AstonJ
Looking at @siddhant3030’s photo from the Do you blog? thread, do you cover your computer or phone camera as a security precaution? Wha...
New
AstonJ
Want to plug where you work? Here’s your chance! Perhaps you could also mention what kind of stuff you’re working on? :nerd_face:
New
AstonJ
Inspired by this tweet by @dasdom Even if you take out all the damage being done by humans, our planet has about 50B years before bein...
New
Margaret
Hello everyone! This thread is to tell you about what authors from The Pragmatic Bookshelf are writing on Medium.
1143 25883 760
New
DevotionGeo
For me it’s six to seven steps above complete dark, on MacBook Air M1.
New
DevotionGeo
Hi everyone! I bought this domain name when I was planning to create a website like ElixirSchool.com, but that didn’t ever happen. Now ...
New
jaeyson
Hi!, hope everyone’s ok. Sorry if this question is ambiguous (i’ll remove this if i break some rules here). This is more like a self-ques...
New
AstonJ
Chris Seaton, the creator of TruffleRuby has died. It appears from suicide :cry: He left this note on Twitter on the weekend: And one...
New
harwind
I’m working on a Spring Boot project and I have a controller where I want to map multiple request paths to a single method. Let’s say I h...
New

Other popular topics Top

Devtalk
Reading something? Working on something? Planning something? Changing jobs even!? If you’re up for sharing, please let us know what you’...
1033 17470 383
New
AstonJ
A thread that every forum needs! Simply post a link to a track on YouTube (or SoundCloud or Vimeo amongst others!) on a separate line an...
New
AstonJ
Or looking forward to? :nerd_face:
New
AstonJ
Do the test and post your score :nerd_face: :keyboard: If possible, please add info such as the keyboard you’re using, the layout (Qw...
New
PragmaticBookshelf
“Finding the Boundaries” Hero’s Journey with Noel Rappin @noelrappin Even when you’re ultimately right about what the future ho...
New
Exadra37
Oh just spent so much time on this to discover now that RancherOS is in end of life but Rancher is refusing to mark the Github repo as su...
New
mafinar
This is going to be a long an frequently posted thread. While talking to a friend of mine who has taken data structure and algorithm cou...
New
New
PragmaticBookshelf
Develop, deploy, and debug BEAM applications using BEAMOps: a new paradigm that focuses on scalability, fault tolerance, and owning each ...
New
AstonJ
Curious what kind of results others are getting, I think actually prefer the 7B model to the 32B model, not only is it faster but the qua...
New