Skip to content

Instantly share code, notes, and snippets.

View MushroomMaula's full-sized avatar

Max Rausch-Dupont MushroomMaula

View GitHub Profile
def distribution(events: list, probabilities: list) -> int:
"""
Generates a random variable from the given distribution
:param events: List with integers specifying the the events
:param probabilities: List with the corresponding probabilites
"""
# Each event needs a probability
assert len(events) == len(probabilities)
assert sum(probabilities) == 1
@MushroomMaula
MushroomMaula / gram_schmidt.py
Last active July 12, 2021 21:08
Naive gram schmidt process using sympy
def gram_schmidt(basis: list, sp) -> list:
"""
Finds a orthonormal basis using the gram schmidt process
:param barsis: List of basis vectors
:param sp: Scalarproduct in this space
:returns: List containing the orthonormal basis vectors
"""
# Only makes sense when we have a basis
assert basis
@MushroomMaula
MushroomMaula / example.py
Created October 15, 2020 19:10
More in depth example of fastapi-login usage
from fastapi import FastAPI, Depends
from fastapi.security import OAuth2PasswordRequestForm
from fastapi_login import LoginManager
from fastapi_login.exceptions import InvalidCredentialsException
app = FastAPI()
manager = LoginManager(
# here we set the secret LoginManager uses to encrypt our Token
# normally you would use Environment Variables or some kind of config
# where you can store the secret
# https://github.com/uBlockOrigin/uAssets/pull/3517
twitch-videoad.js application/javascript
(function() {
if ( /(^|\.)twitch\.tv$/.test(document.location.hostname) === false ) { return; }
var realFetch = window.fetch;
window.fetch = function(input, init) {
if ( arguments.length >= 2 && typeof input === 'string' && input.includes('/access_token') ) {
var url = new URL(arguments[0]);
url.searchParams.forEach(function(value, key) {
url.searchParams.delete(key);
@MushroomMaula
MushroomMaula / chunk.py
Last active September 9, 2021 21:04
Useful python snippets
from typing import Sequence
def chunks(l: Collection, n):
"""
Yield successive n-sized chunks from l.
>>> list(chunks([1,2,3,4,5,6], 3))
[[1, 2, 3], [4, 5, 6]]
>>> list(chunks([1,2,3,4,5,6], 5))
class Calendar extends HTMLElement {
static daysInMonth(month, year) {
month += 1; // last day of previous month
return new Date(year, month, 0).getDate();
}
constructor() {
super();
this.draw = this.draw.bind(this);