Skip to content

Instantly share code, notes, and snippets.


Thomas Chaumeny tchaumeny

View GitHub Profile
tchaumeny /
Created Jul 15, 2021
Implementation of Fermat and Miller-Rabin tests in Python, see
# Part of
# /!\ Warning /!\ — Not safe for real cryptographic usage
from collections import Counter
from random import randrange
import statistics
# Fermat
def fermat_test(n, max_witness=100):
from cmath import e, pi
from collections import Counter
import fileinput
def tokenize(s):
prev = None
for i, c in enumerate(s):
if prev is None:
if c in ('s', 'n'):
prev = c
View RotatingCube.js
// RotatingCube React component, used in
import * as BABYLON from 'babylonjs'
import * as GUI from 'babylonjs-gui'
import React, { useEffect, useRef, useState } from 'react'
const canvasWidth = 500;
const canvasHeight = 300;
function initScene(canvas, rotationCb) {
const engine = new BABYLON.Engine(canvas);
tchaumeny /
Last active May 24, 2020
Polynomial type in Python
# See
from numbers import Number
class Polynomial:
def __init__(self, *coefficients): = -1
self.coefficients = tuple(coefficients)
for i, coef in enumerate(self.coefficients):
if coef != 0:
tchaumeny /
Last active Feb 17, 2017
Converting amount of money (including cents) to words using num2words
from num2words import num2words
def money_amount_words(amount, units='euros', cents='centimes', lang='fr'):
Returns an iterator over the words describing the given amount
amount: decimal.Decimal, the amount of money
units: str, the currency units