Skip to content

Instantly share code, notes, and snippets.

import math
def deg2rad(angle: float) -> float:
return (angle % 360) / 180 * math.pi
def rad2deg(angle: float) -> float:
return (angle * 180 / math.pi) % 360
class Point:
def __init__(self, x: float, y: float):
@Defelo
Defelo / lineqsysolver.py
Last active June 9, 2019 21:44
Linear Equation System Solver
from typing import List
def solve(matrix: List[List[float]]) -> List[float]:
# check size of matrix
n: int = len(matrix)
assert n >= 1
assert all(len(row) == n + 1 for row in matrix)
# Gaussian elimination
@Defelo
Defelo / totp.py
Last active November 30, 2021 13:22
import base64
import hashlib
import hmac
import secrets
import time
class TOTP:
def __init__(self, secret: str):
self.secret = secret
@Defelo
Defelo / arch-arm-rpi3-b-plus.md
Last active October 27, 2019 17:35 — forked from theramiyer/arch-arm-rpi3-b-plus.md
Install Arch Linux (ARM) on Raspberry Pi 3 Model B+

Install Arch Linux (ARM) on Raspberry Pi B+

Created 17 Aug 2018

This is a simple installation that I did on my Raspberry Pi. Of course, this is only one of the many reasons to do it.

Here are my requirements:

import math
#term = input(">> ").split()
stack = []
running = True
while running:
for t in input(">> ").split():
if t == "exit":
running = False
break
@Defelo
Defelo / docker-compose.yml
Last active February 3, 2020 15:34
Docker MySQL Server
version: '3.7'
services:
db:
container_name: mysql_server
image: mariadb
restart: always
environment:
MYSQL_USER: "user"
MYSQL_PASSWORD: "password"
MYSQL_DATABASE: "db"
@Defelo
Defelo / clipsync.sh
Created April 4, 2020 08:57
X11 Clipboard Sync
#!/bin/bash
[[ $# -lt 2 ]] && echo "usage: $0 <first display> <second display>" && exit 1
clipread() {
xclip -selection clip -r -o -display $1 2> /dev/null
}
clipwrite() {
xclip -selection clip -r -i -display $1
@Defelo
Defelo / heap.ipynb
Created December 23, 2020 14:20
Heap Implementation in Python
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Defelo
Defelo / custom_html_head_content.html
Created January 31, 2021 21:33
KaTeX Support for Bookstack
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.12.0/dist/katex.min.css" integrity="sha384-AfEj0r4/OFrOo5t7NnNe46zW/tFgW6x/bCJG8FqQCEo3+Aro6EYUG4+cU+KJWu/X" crossorigin="anonymous">
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.12.0/dist/katex.min.js" integrity="sha384-g7c+Jr9ZivxKLnZTDUhnkOnsh30B4H0rpLUpJ4jAIKs4fnJI+sEnkvrMWph2EDg4" crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.12.0/dist/contrib/auto-render.min.js" integrity="sha384-mll67QQFJfxn0IYznZYonOWZ644AWYC+Pt2cHqMaRhXVrursRwvLnLaebdGIlYNa" crossorigin="anonymous"></script>
<script>
function _katex_render(elem) {
renderMathInElement(
elem,
{
delimiters: [
[W:=10,H:=10,find:=lambda x:x if x==uf[x]else(uf.__setitem__(x,x:=find(uf[x]))or x),union:=lambda a,b:uf.__setitem__(find(a),find(b)),c2i:=lambda x,y:y*W+x,i2c:=lambda i:(i%W,i//W),uf:=[*range(W*H)],E:=[(c2i(x,y),c2i(x+1-z,y+z))for x in range(W-1)for y in range(H-1)for z in range(2)]+[(c2i(x,H-1),c2i(x+1,H-1))for x in range(W-1)]+[(c2i(W-1,y),c2i(W-1,y+1))for y in range(H-1)],__import__("random").shuffle(E),PE:=[],N:=[[[]for _ in'*'*W]for _ in'*'*H],[[union(a,b),c1:=i2c(a),c2:=i2c(b),N[c1[1]][c1[0]].append(c2),N[c2[1]][c2[0]].append(c1),PE.extend([((2*c1[0]+1,2*c1[1]),(2*c1[0]+2,2*c1[1])),((2*c1[0]+1,2*c1[1]+1),(2*c1[0]+2,2*c1[1]+1))]if c1[1]==c2[1]else[((2*c1[0],2*c1[1]+1),(2*c1[0],2*c1[1]+2)),((2*c1[0]+1,2*c1[1]+1),(2*c1[0]+1,2*c1[1]+2))])]for a,b in E if find(a)!=find(b)],[[[0 if(x-1,y)in N[y][x]else PE.append(((2*x,2*y),(2*x,2*y+1))),0 if(x+1,y)in N[y][x]else PE.append(((2*x+1,2*y),(2*x+1,2*y+1))),0 if(x,y-1)in N[y][x]else PE.append(((2*x,2*y),(2*x+1,2*y))),0 if(x,y+1)in N[y][x]else PE.append(((2*x,2*y+1)