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

justinjunodev
Figured this would be a cool topic and maybe provide some inspiration for those who are just starting to work from home. Feel free to sha...
New
AstonJ
What chair do you have while working… and why? Is there a ‘best’ type of chair or working position for developers?
New
axelson
Can anyone recommend a tmux session switcher? I’ve used https://github.com/siadat/session-finder in the past but it’s not very actively m...
New
siddhant3030
I’m thinking of buying a monitor that I can rotate to use as a vertical monitor? Also, I want to know if someone is using it for program...
New
AstonJ
Curious to know which languages and frameworks you’re all thinking about learning next :upside_down_face: Perhaps if there’s enough peop...
New
Exadra37
Kubernetes is everywhere. Transactional apps, video streaming services and machine learning workloads are finding a home on this ever-gro...
New
AstonJ
Slightly different to the What does your mobile phone home screen look like? thread, what is your lock screen image?
New
New
AstonJ
Do we have any digital nomads here? Anyone fancy it? If so, which countries would you consider? I’ve been toying with the idea for a wh...
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

Other popular topics Top

AstonJ
What chair do you have while working… and why? Is there a ‘best’ type of chair or working position for developers?
New
Exadra37
I am thinking in building or buy a desktop computer for programing, both professionally and on my free time, and my choice of OS is Linux...
New
siddhant3030
I’m thinking of buying a monitor that I can rotate to use as a vertical monitor? Also, I want to know if someone is using it for program...
New
Rainer
My first contact with Erlang was about 2 years ago when I used RabbitMQ, which is written in Erlang, for my job. This made me curious and...
New
AstonJ
poll poll Be sure to check out @Dusty’s article posted here: An Introduction to Alternative Keyboard Layouts It’s one of the best write-...
New
PragmaticBookshelf
Rust is an exciting new programming language combining the power of C with memory safety, fearless concurrency, and productivity boosters...
New
AstonJ
If you are experiencing Rails console using 100% CPU on your dev machine, then updating your development and test gems might fix the issu...
New
First poster: bot
The overengineered Solution to my Pigeon Problem. TL;DR: I built a wifi-equipped water gun to shoot the pigeons on my balcony, controlle...
New
New
AstonJ
This is cool! DEEPSEEK-V3 ON M4 MAC: BLAZING FAST INFERENCE ON APPLE SILICON We just witnessed something incredible: the largest open-s...
New