View miller_rabin.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Part of https://lipsum.dev/2021-06-1-miller-rabin-openssl/ | |
# /!\ 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): |
View AoC24.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// RotatingCube React component, used in https://lipsum.dev/2020-09-1-rotations/ | |
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); |
View polynomial.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# See https://lipsum.dev/2020-05-1-pourquoi-les-polynomes/ | |
from numbers import Number | |
class Polynomial: | |
def __init__(self, *coefficients): | |
self.degree = -1 | |
self.coefficients = tuple(coefficients) | |
for i, coef in enumerate(self.coefficients): | |
if coef != 0: |
View money_amount_words.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
Args: | |
amount: decimal.Decimal, the amount of money | |
units: str, the currency units |