Skip to content

Instantly share code, notes, and snippets.

View eruvanos's full-sized avatar

Maic Siemering eruvanos

View GitHub Profile
@eruvanos
eruvanos / arcade_imgui_demo
Created July 25, 2024 21:10
Arcade & IMGUI
"""Bridge between arcade and imgui using arcade.gl for rendering.
Works with arcade 3.0.0.dev32 and imgui 2.0.0.
Requires "imgui[pyglet]".
Documentation for imgui usage can be found here
https://pyimgui.readthedocs.io/en/latest/index.html
@eruvanos
eruvanos / test_flask.py
Created February 26, 2020 09:03
Run Flask app as fixture
from threading import Thread
import pytest
import requests
from flask import Flask
@pytest.fixture()
def app() -> Flask:
host = 'localhost'
@eruvanos
eruvanos / README.md
Last active September 8, 2020 09:45
LocalDynamoDB Setup

Setup for a local DynamoDB for testing

Requirements

boto3 # aws sdk
requests # to download dynamodb
mirakuru # monitors the subprocess and checks for an open port
@eruvanos
eruvanos / flask_json_dataclass.py
Created May 12, 2019 13:14
Enhance JSONEncoder supporting dataclasses
from flask import Flask
from flask.json import JSONEncoder
class EnhancedJSONEncoder(JSONEncoder):
def default(self, o):
if dataclasses.is_dataclass(o):
return dataclasses.asdict(o)
return super().default(o)
@eruvanos
eruvanos / timeit.py
Last active December 10, 2019 23:29
Time a python funtion
# Timer for functions
from functools import wraps
def timeit(f):
@wraps(f)
def wrap(*args, **kwargs):
start = time()
r = f(*args, **kwargs)
print(f.__name__, time() - start)
@eruvanos
eruvanos / read_newrelic_license_key.sh
Last active January 25, 2019 14:24
Read NewRelic License key from VCAP_SERVICES
#!/usr/bin/env bash
# put into .profile.d/
LICENSE_KEY=$(echo $VCAP_SERVICES | jq -r '.[] | select(.[].name | contains("newrelic"))| .[0].credentials.licenseKey')
if test -z "$LICENSE_KEY"
then
echo "INFO: No New Relic service bound to app"
else
echo "INFO: New Relic service found"
@eruvanos
eruvanos / auth.py
Created November 5, 2018 09:13
Flask BasicAuth Extension
import secrets
from typing import Union
from flask import Flask, Blueprint, Response, request
class BasicAuth:
def __init__(self, app: Union[Flask, Blueprint], username: str, password: str):
self.app = app
self.username = username
import math
from typing import List
import arcade
class Block:
def __init__(self, x: float, y: float, r: float):
self.x = x
self.y = y
@eruvanos
eruvanos / template.html
Created April 23, 2018 02:12
Postcard template
<html>
<head>
<meta charset="UTF-8">
<link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet" type="text/css">
<title>Lob.com Sample 4x6 Postcard Back</title>
<style>
*, *:before, *:after {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
@eruvanos
eruvanos / aws_utils.sh
Last active December 10, 2018 05:11
Useful aws utils for cli
#!/usr/bin/env bash
function load_service_credentials {
service_name=$1
# Read credentials for queue
SERVICE_KEY_JSON=$(cf service-key $service_name key | grep -v "Getting")
export AWS_ACCESS_KEY_ID=$(echo ${SERVICE_KEY_JSON} | jq '.access_key' -r)
export AWS_SECRET_ACCESS_KEY=$(echo ${SERVICE_KEY_JSON} | jq '.secret_access_key' -r)
export AWS_DEFAULT_REGION=$(echo ${SERVICE_KEY_JSON} | jq '.region' -r)
export AWS_URI=$(echo ${SERVICE_KEY_JSON} | jq '.uri' -r)