Skip to content

Instantly share code, notes, and snippets.

View M0r13n's full-sized avatar
🦔

Leon Morten Richter M0r13n

🦔
View GitHub Profile
@M0r13n
M0r13n / main.py
Last active September 10, 2017 11:16
simple script for parsing syslog logs from my edgerouter firewall + adding some extra information like GeoIP or whois information to it
import requests
import sys
__log_path = "logile path"
__parsed_log_path = "new parsed logfile"
__parsed_log_path_only_ip = " "
__apiKey = "enter api key for dn-ip here "
__api_Url = "http://api.db-ip.com/v2/" # to be added : <apiKey>/<ipAddress>
ips = []
@M0r13n
M0r13n / Backtrack.py
Last active March 30, 2018 13:06
A simple backtracking algorithm for solving a Maze in Python
OBJECTS = {'WALL': '#',
'SPACE': ' ',
'VISITED': '.', }
def readfile(file):
try:
f = open(file, 'r')
except Exception as e:
print('Error opening file. Did you enter the correct file-path?')
@M0r13n
M0r13n / quicksort.py
Last active June 23, 2018 15:13
Quicksort implementation in Python
data = [1, 5, 2, 5, 3, 5, 5]
def quicksort(left, right):
if 0 > left:
raise ValueError("left border must be greater or equal zero")
if right >= len(data):
raise ValueError("right index cant be greater than length")
if left < right:
def salary():
link = ""
key = ""
headers = {
'Accept': 'application/json'
}
params = {
'api_token': key,
}
@M0r13n
M0r13n / README.md
Last active January 30, 2024 19:35
Logging with Loguru in Flask

This is a simple example of how to use loguru in your flask application

Just create a new InterceptHandler and add it to your app. Different settings should be configured in your config file, so that it is easy to change settings.

Logging is then as easy as:

from loguru import logger

logger.info("I am logging from loguru!")

@M0r13n
M0r13n / template.html
Last active April 11, 2019 17:11
Flask WTF-Form - Custom rendering a Form with select
<div class="row text-left">
<div class="col-md-4 col-md-offset-4">
<form action="" method="POST" role="form" class="form">
<!--Errors + CSRF-->
{{ form.hidden_tag() }} {{ wtf.form_errors(form, hiddens="only") }}
{% for field, errors in form.errors.items() %}
<div class="alert alert-error">
{{ form[field].label }}: {{ ', '.join(errors) }}
</div>
@M0r13n
M0r13n / _macros.html
Created April 11, 2019 17:23
WTF-Forms - Render Form Field Errors
{% macro render_errors(field) %}
{% for error in field.errors %}
<div class="alert alert-error text-danger">
{{ error }}
</div>
{% endfor %}
{% endmacro %}
@M0r13n
M0r13n / _confirm.html
Created April 19, 2019 12:13
Reusable Confirmation Dialog for Jinja2 using Bootstrap and Modals
{% macro confirm_deletion(endpoint='#') %}
<div id="confirm-deletion">
<button type="button" class="btn btn-danger" data-toggle="modal"
data-target="#MyFancyModal">Löschen
</button>
<div id="MyFancyModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
@M0r13n
M0r13n / hexbot.py
Created June 16, 2019 10:14
How to query the hexbot api
import requests # install if necessary -> pip install requests
URL = 'https://api.noopschallenge.com' + '/hexbot' # change the last part to query different machines
r = requests.get(URL)
result = r.json()
print(result['colors'][0]['value']) # prints the hex code, e.g. #7A5A28
# Additional parameters
@M0r13n
M0r13n / render.html
Last active October 6, 2023 06:32
A sample Wtforms field for creating a list of tags with custom separators, e.g. "," or " ".
<form action="" method="POST" role="form" class="form">
{{ form.hidden_tag() }}
<!--Other fields-->
{{ wtf.form_field(form.tags, placeholder='audio, hardware, chip') }}
<button class="btn btn-success" type="submit">submit</button>
</form>