Skip to content

Instantly share code, notes, and snippets.

View thomasms's full-sized avatar
🇧🇪

JustAnotherTom thomasms

🇧🇪
View GitHub Profile
@thomasms
thomasms / make_image.py
Created April 28, 2025 19:34
gepetie_image
#!/usr/bin/env python3
import os
import argparse
from openai import OpenAI
def main():
parser = argparse.ArgumentParser()
import enum
from typing import Any, Optional
class Priority(enum.Enum):
HIGH = 1
MEDIUM = 2
LOW = 3
#include <array>
#include <unordered_map>
#include <memory>
#include <iostream>
#include <string>
template<typename T>
using Ptr = std::shared_ptr<T>;
struct Node{
#include <iostream>
#include <array>
#include <functional>
#include <memory>
template<typename T>
using Ptr = std::unique_ptr<T>;
template<typename T>
struct Node {
// - function makes a binary search tree from an array
// - traverse the tree from left to right
#include <iostream>
#include <vector>
template<typename T=int>
struct Node {
Node* left;
Node* right;
@thomasms
thomasms / slc_abroad_plan1.py
Last active May 4, 2024 11:51
Student Loan Abroad payment plan 1
import argparse
countries = {
'belgium': {'currency': 'EUR', 'rate': 0.869943, 'threshold': 24990, 'default': 390},
'france': {'currency': 'EUR', 'rate': 0.869943, 'threshold': 19995, 'default': 312},
}
def plan1(annual_salary_in_currency: float, country: str) -> float:
data = countries.get(country)
@thomasms
thomasms / activity_vs_time.py
Created March 16, 2023 19:30
An example to show Activity Vs Time (log-log) plot for both irraditation and cooling periods - for Andrea
#!/usr/bin/env python3
import os
import pypact as pp
import pypact.analysis as ppa
# your FISPACT-II output file
filename = os.path.join(
os.path.dirname(os.path.abspath(__file__)), "..", "..", "reference", "test127.out"
from __future__ import print_function
import json
from typing import Any, Optional, Union
def get_interest_per_month(interest_rate_per_year: float) -> float:
interest_rate_per_month = (1.0 + interest_rate_per_year) ** (1.0 / 12.0)
# we do not consider anything more than 1e-5 for rate
interest_rate_per_month = round(interest_rate_per_month, 5)
@thomasms
thomasms / messi_futbol.py
Created December 28, 2022 21:44
The Messi problem from the Guardian
"""
# https://www.theguardian.com/science/2022/dec/26/can-you-solve-it-argentinas-creative-genius
Replace the ten letters of the following sum with the ten digits 0,1,2, … 9,
such that the sum is correct.
Each letter represents a unique digit.
There are two solutions, so find the one with the largest MESSI.
MESSI
+ MESSI
@thomasms
thomasms / exception_tricks.py
Created February 27, 2022 21:04
Using exceptions in python to transport values without explicit dependencies
# define in some util somewhere
class MyException(Exception):
class A:
value = 4
# raise an exception with a custom value to be caught elsewhere
def myfunc(b):
a = MyException
a.value = b
raise a