Skip to content

Instantly share code, notes, and snippets.

@DavidHulsman
DavidHulsman / gist:3860985
Created October 9, 2012 19:43
Inverse Square Root by Greg Walsh
float invSqrt(float x)
{
union {
float x;
int i;
} u;
float xhalf = 0.5f * x;
u.x = x;
u.i = 0x5f3759df - (u.i >> 1);
@DavidHulsman
DavidHulsman / first.py
Created February 28, 2019 18:50
Thought I'd give /u/Enjgine'd code a refactoring - https://redd.it/avnpue
import os
def cls():
os.system('cls' if os.name == 'nt' else clear)
# moved the first conversion into its own function for easier testing (either manual or automated)
def dist2cm(mode, distance):
# concert all to cm
@DavidHulsman
DavidHulsman / second.py
Created February 28, 2019 18:51
Thought I'd give /u/Enjgine'd code a second refactoring - https://redd.it/avnpue
import os
def cls():
os.system('cls' if os.name == 'nt' else clear)
# this is a function that returns a dictionary/key-value-pair 'list'
# the reason that this isn't a regular variable, as that they can be changed
# and Python doesn't have any constants, so you can use a function that returns
@DavidHulsman
DavidHulsman / coding-horror
Last active January 20, 2021 12:31
How not to .padLeft(3, '0') in C#
// I found this little nugget 6 times in a 5000+ lines god-class, with the deepest indent being 23 tabs deep.
if (var.Length < 3)
{
if (var.Length < 2)
{
if (var == "")
{
var = "000";
}
else