Skip to content

Instantly share code, notes, and snippets.

View Vodkacannon's full-sized avatar
😐

Vodkacannon

😐
View GitHub Profile
@Vodkacannon
Vodkacannon / temperature.py
Last active May 1, 2025 15:32
Calculate various temperature conversions in Python.
fahrenheit = "°F"
celcius = "°C"
kelvin = "K"
def c_to_f(celcius: float) -> float:
"""Celcius to fahrenheit."""
return celcius * 9.0 / 5.0 + 32.0
def f_to_c(fahrenheit: float) -> float:
@Vodkacannon
Vodkacannon / farming.py
Created September 27, 2023 22:00
A Simple farming Patch Simulator
import random
import time
random.seed(int(time.time()))
class FarmingPatch:
def __init__(self, area_sqr_meter: float):
self.area_sqr_meter = area_sqr_meter
self.weeds_per_sqr_meter = random.randint(0, 3)
self.total_weeds = self.weeds_per_sqr_meter * self.area_sqr_meter
@Vodkacannon
Vodkacannon / vec3.py
Last active August 8, 2023 11:46
Three dimensional vector mathematics with Python 3.
import math
class Vec3:
def __init__(self, x: float, y: float, z: float):
self.x = x
self.y = y
self.z = z
def zero(self):
//Used for maximum efficiency, especially over a network.
#pragma once
#include <string>
#include <bitset>
namespace bit_packer {
void set_bit(uint8_t& bits, const bool value, const uint8_t index) {
bits |= (value << index);
@Vodkacannon
Vodkacannon / c_string.h
Last active November 24, 2022 16:33
C Strings
//This code may contain bugs.
#include <malloc.h>
#include <ctype.h>
const size_t sizeof_char = sizeof(char);
const char empty_char = '\0';
struct string {
//How many elements:
@Vodkacannon
Vodkacannon / bool.h
Last active November 24, 2022 04:01
C Booleans
enum Bool {
False = 0,
True = 1
};
const char* true = "true";
const char* false = "false";
char* get_bool_str(enum Bool my_bool) {
return (my_bool == True) ? true : false;
@Vodkacannon
Vodkacannon / binary_tree.h
Created November 20, 2022 04:56
Binary Tree
struct binary_node {
int value;
struct node* left;
struct node* right;
};
struct binary_node_char {
char value;
struct node* left;
struct node* right;
@Vodkacannon
Vodkacannon / file_extension.c
Created November 4, 2022 01:01
File Extension Checking
//true and false.
#include <stdbool.h>
//isalnum().
#include <ctype.h>
int is_file_extension(const char* string) {
if (string[0] != '.') {
return false;
}
// this computes 1 / sqrt(number) using iterations of precision
//Attributed to Doom (the video game).
float Q_rsqrt( float number, int iterations )
{
long i;
float x2, y;
const float threehalfs = 1.5F;
x2 = number * 0.5F;
y = number;
@Vodkacannon
Vodkacannon / dirac_delta.py
Created October 30, 2022 01:49
Dirac Delta
import math
def dirac_delta(x: float, variance: float=0.001) -> float:
return (1.0 / (abs(variance) * math.sqrt(math.pi))) * math.exp(-(x / b)**2)