Skip to content

Instantly share code, notes, and snippets.

View M0r13n's full-sized avatar
🦔

Leon Morten Richter M0r13n

🦔
View GitHub Profile
@M0r13n
M0r13n / dotdict.py
Created October 11, 2020 14:32
A simple Python dictionary whose keys can be queried using dot notation.
from typing import Any
class CaseInsensitiveDict(dict):
"""
A dict object where the case of keys does not matter.
Create a new instance:
>>> c = CaseInsensitiveDict({'a' : 123})
@M0r13n
M0r13n / cert.pem
Last active September 14, 2020 14:59
Requests foo
-----BEGIN CERTIFICATE-----
MIIKuTCCCaGgAwIBAgIMIKnT34vOStDMr3hOMA0GCSqGSIb3DQEBCwUAMIGNMQswCQYDVQQGEwJERTFFMEMGA1UECgw8VmVyZWluIHp1ciBGb2VyZGVydW5nIGVpbmVzIERldXRzY2hlbiBGb3JzY2h1bmdzbmV0emVzIGUuIFYuMRAwDgYDVQQLDAdERk4tUEtJMSUwIwYDVQQDDBxERk4tVmVyZWluIEdsb2JhbCBJc3N1aW5nIENBMB4XDTE5MDMxNDEzMjU0MFoXDTIxMDYxNTEzMjU0MFowgbkxCzAJBgNVBAYTAkRFMRswGQYDVQQIDBJTY2hsZXN3aWctSG9sc3RlaW4xDTALBgNVBAcMBEtpZWwxMTAvBgNVBAoMKENocmlzdGlhbi1BbGJyZWNodHMtVW5pdmVyc2l0YWV0IHp1IEtpZWwxITAfBgNVBAsMGEluc3RpdHV0IGZ1ZXIgSW5mb3JtYXRpazEoMCYGA1UEAwwfYnVrYXJlc3QuaW5mb3JtYXRpay51bmkta2llbC5kZTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAMnBSHNRepsZOgKDk2IhzJ5V2jgvZuMAS635ixOUhgxeHemo9xHHXq6aXre3Enr0DXDr1tJ61Bi2gVcbT3SO1G5GRguLtdRhf+Qpiipf7GOwJDZv+lWiqEhXo8cesoZt4EjwLkd7MIy+kHpcVUtBJ+mcx7QrYI4Qu/pEtPY1XgNG2EdKkcE+6+fEJI1t5m2jdDNcZuV6E/nkHBZk1KVJuyRVsnnTR2HZY2IFV/ndH0koJMW+o2PA/iowBogMS/o13A0zmquCWV8oUH/NV0fZtuahA60uR6CIFUy6ov+eg6jKLlg/O8mQmNYcRnk7UJZ1lneFZ2/9g86a0yQE7A72XbW6jPtxXb35tv9UC0IosXm+wgO5rVeoQBaw534fe6l/NvbfTMyA1TnLMapIuAhbXMCTamYF
@M0r13n
M0r13n / index.html
Created September 2, 2020 14:57
Recursive Multilevel, nested and numbered lists from JSON. This includes checkboxes that also check or un-check their child checkboxes on click.
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" type="text/css" href="./style.css">
<title>Test</title>
</head>
@M0r13n
M0r13n / README.md
Created July 11, 2020 09:15
Oneliner to delete Systemd service (systemctl) in bash.

Oneliner to delete a Systemd service

service=YOUR_SERVICE_NAME; systemctl stop $service && systemctl disable $service && rm /etc/systemd/system/$service &&  systemctl daemon-reload && systemctl reset-failed

Set service to your desired service that should be deleted. E.g. service=gunicorn.service

@M0r13n
M0r13n / ssh_via_keyfile.md
Created July 9, 2020 09:29
Quick way to enable SSH authentication via keyfile.

Quick way to setup SSH via keyfile

On the remote host:

ssh-keygen -t rsa -b 2048

The key location is /root/.ssh/id_rsa.

@M0r13n
M0r13n / README.md
Created June 17, 2020 11:22
Change Select2 Height and Width for Flask Admin

Usage

Simply modify the Admin base html file and customize the select2-results and select2-results class in your css.

@M0r13n
M0r13n / url.js
Created April 1, 2020 19:30
Does the url query string need a & or a ? as an separator?
function url_sep(url) {
return url.match(/\?/) ? "&" : "?";
}
@M0r13n
M0r13n / self_cleaning_dict.py
Created March 4, 2020 14:05
A simple self cleaning Python dictionary (dict) with timestamps.
import time
class SelfCleaningDict(dict):
def __init__(self, time_out=3600, prone_interval=None):
self.timeout = time_out
self.prone_interval = time_out // 10 or prone_interval
self.last_prone = None
if not self.timeout:
@M0r13n
M0r13n / demo.py
Created February 20, 2020 11:06
Python caches hashes of strings
data = "ABCDEFG1234" * 1000000000
x = lambda: hash(data)
import timeit
for i in range(10):
print(f"#{i} took {timeit.timeit(x, number=1)} secs")
@M0r13n
M0r13n / calc.c
Last active January 13, 2020 12:48
Evaluate a string in Prefix Notation (Polish Notation) and calculate the result. Interact with a user through a simple REPL.
/**
* A simple REPL for Polish Notation / Prefix Notation.
* Compile with:
* gcc -std=c99 -Wall calc.c -ledit -o calc
*
* Examples:
* -----------
* calc> * / + 2 2 2 + 1 2
* Result is: 6.000000
*