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
#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