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

Devtalk
Reading something? Working on something? Planning something? Changing jobs even!? If you’re up for sharing, please let us know what you’...
1030 17300 381
New
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
Exadra37
Cloudflare as workers to run serverless code without using containers: So it seems that Isolates is based on: What we ended up settl...
New
jaywengrow
Hello! It’s Jay Wengrow, author of A Common-Sense Guide to Data Structures and Algorithms. My book now has a supplemental website, where ...
New
mjk
TL;DR: words that incorporate negation are acceptable, eg. independent, asymmetric, nondeterministic. An example in the book is to renam...
New
AstonJ
Great paper by Igor Kopestenski on Erlang and GRiSP: Erlang as an Enabling Technology for Resilient General-Purpose Applications on Edge ...
New
New
AstonJ
I’ve been watching Prag Dave’s Elixir course and I noticed he uses tree: Tree is a recursive directory listing program that produces a ...
New
DevotionGeo
Amazon CodeWhisperer is an alternative to GitHub Copilot, and it’s free!
New
Margaret
Hello DevTalk Community! Once again, The Pragmatic Programmers are looking for developers who’d like to help shape the future of our boo...
New

Other popular topics Top

ohm
Which, if any, games do you play? On what platform? I just bought (and completed) Minecraft Dungeons for my Nintendo Switch. Other than ...
New
dasdom
No chair. I have a standing desk. This post was split into a dedicated thread from our thread about chairs :slight_smile:
New
brentjanderson
Bought the Moonlander mechanical keyboard. Cherry Brown MX switches. Arms and wrists have been hurting enough that it’s time I did someth...
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
Inspired by this post from @Carter, which languages, frameworks or other tech or tools do you think is killing it right now? :upside_down...
New
AstonJ
This looks like a stunning keycap set :orange_heart: A LEGENDARY KEYBOARD LIVES ON When you bought an Apple Macintosh computer in the e...
New
Exadra37
I am asking for any distro that only has the bare-bones to be able to get a shell in the server and then just install the packages as we ...
New
New
husaindevelop
Inside our android webview app, we are trying to paste the copied content from another app eg (notes) using navigator.clipboard.readtext ...
New
AstonJ
If you’re getting errors like this: psql: error: connection to server on socket “/tmp/.s.PGSQL.5432” failed: No such file or directory ...
New