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