Skip to content

Instantly share code, notes, and snippets.

View Moderrek's full-sized avatar
☀️
Light IDE attracts bugs 🐞

Tymon Woźniak Moderrek

☀️
Light IDE attracts bugs 🐞
View GitHub Profile
@Moderrek
Moderrek / file_to_header.py
Created December 2, 2024 21:53
Converts files to C++ header files.
def convert_file_to_header(input_file, output_header, variable_name):
with open(input_file, 'rb') as f:
data = f.read()
with open(output_header, 'w') as h:
h.write(f"#ifndef FILE_{variable_name.upper()}_H_INCLUDED\n")
h.write(f"#define FILE_{variable_name.upper()}_H_INCLUDED\n\n")
h.write(f"// Generated from {input_file}\n\n")
h.write(f"const unsigned char {variable_name}[] = {{\n")
@Moderrek
Moderrek / hegeui.h
Created November 4, 2024 21:33
My own terminal UI header library
#pragma once
#include <stdio.h>
#include <string>
#include <ostream>
#define HG_CLEAR printf("\033[2J")
#define HG_GOTO_START printf("\033[H")
#define HG_GOTO(row, col) printf("\033[%d;%dH", (row), (col))
#define HG_GOTO_LINE(line) printf("\033[%d;0H", (line))
@Moderrek
Moderrek / scoped_timer.hpp
Last active September 21, 2025 08:59
Scoped Timer used for speed measure.
#pragma once
/*
* Scoped Timer 1.1
* by Hegemon Studio
*
* used for profiling
* speed measure (in millis)
*
* easy header-only library
#include <iostream>
bool is_prime(unsigned long long n) {
if (n <= 1) return false;
if (n == 2) return true;
if (n % 2 == 0) return false;
for (int i = 3; i * i <= n; i += 2)
if (n % i == 0) return false;
return true;
}
@Moderrek
Moderrek / longest_word_7seg.py
Created January 1, 2024 21:05
Finds longest word possible to write on 7 segment display with txt dictionary.
import urllib.request
dictionaries: dict[str, str] = {
"pl": "https://raw.githubusercontent.com/sigo/polish-dictionary/master/dist/pl.txt",
"en": "https://raw.githubusercontent.com/dwyl/english-words/master/words.txt",
}
_7seg_possible_chars: str = "0123456789abcdefhijlnoprstuy"
@Moderrek
Moderrek / earth_mass.py
Created December 8, 2023 20:36
Earth mass
from scipy.constants import G
# F = G * (M1 * M2 / r2)
M1 = 1
F = 9.81
r = 6_371_000
# M2 = F * r2 / G / M1
M2 = F * pow(r, 2) / G / M1
@Moderrek
Moderrek / vec.hpp
Created December 5, 2023 21:27
Vector Array implementation in C++
#ifndef VEC_HPP_INCLUDED
/*
Author: Tymon Woźniak <https://github.com/Moderrek>
Vector Array implementation in C++ by Tymon Woźniak
*/
#define VEC_HPP_INCLUDED
#include <iostream>
#include <string>
@Moderrek
Moderrek / struct_printf.c
Created December 5, 2023 21:04
Struct printf macro and explain C compile time str concatenation.
/*
Tymon Woźniak <https://github.com/Moderrek>
C compile time concatenation
Struct printf
*/
#include <stdio.h>
// struct print format
#define Point_Fmt "(%d, %d)"
// unpack struct
@Moderrek
Moderrek / simplehttpserver.py
Created December 5, 2023 20:51
Easiest HTTP Python server with MIME types.
import socket
import os
import mimetypes
class TCPServer:
def __init__(self, host='127.0.0.1', port=8888):
self.host = host
self.port = port