Skip to content

Instantly share code, notes, and snippets.

View exhuma's full-sized avatar
🐢
Slowly advancing on hobby projects

Michel Albert exhuma

🐢
Slowly advancing on hobby projects
View GitHub Profile
@exhuma
exhuma / colortrace.py
Last active March 5, 2024 11:04
Fancy Colorful Python Traceback
'''
This module provides a function ``make_except_hook`` which returns a function
usable as replacement for ``sys.excepthook``.
All imports are done dynamically to make this function a self-contained,
copy/pasteable piece of code.
Requires the "blessings" module to work!
--- License - (MIT) ----------------------------------------------------------
@exhuma
exhuma / colorise.py
Last active March 16, 2018 08:38
Colorise parametric value using Python
from math import pi, cos
from functools import partial
def sinusoidal(v):
'''
Create a sinusoidal easing function.
*v* is assumed to range from 0 to 1. The function will return a new value
from 0 to 1.
@exhuma
exhuma / 01-README.rst
Last active March 18, 2018 19:01
Quick & Dirty Rocket.Chat client

Simple Rocket Chat Client

About

This is a really simple module offering a thin wrapper around the Rocket.Chat REST API. It only provides a simple means to deal with authentication and does not provide any functions for the REST endpoints.

@exhuma
exhuma / with_dedent.py
Created December 24, 2017 08:41
Using dedent to keep multi-line-strings on same indent-level as the rest
class TestFrontendHelpers(TestCase):
SQLALCHEMY_DATABASE_URI = 'postgresql://exhuma@/powonline_testing'
SQLALCHEMY_TRACK_MODIFICATIONS = False
TESTING = True
def __create_app(self):
config = ConfigParser()
config.read_string(dedent(
'''\
@exhuma
exhuma / README.rst
Created October 26, 2017 13:15
Problem with infinity timestamps in SQLAlchemy?

Problem with infinity timestamps in SQLAlchemy?

I've noticed missing entries in table relationships which are joined using timestamp columns using "infinity" timestamps.

The files below demonstrate this. The example is stipped down to the bare minimum while still reproducing the issue.

Looking at the table data, when joining using name and ts we should get two rows (as seen in the select.sql file below).

But, when running this in Python we run into an issue: The infinity timestamp gets converted to a datetime instance using datetime(1, 1, 1, 0, 0).

@exhuma
exhuma / README.rst
Created October 15, 2017 12:41
Example service which returns a custom media-type with a +json indicator

This service is used as an example to demonstrate the Chromium issue described at https://bugs.chromium.org/p/chromium/issues/detail?id=773654

It does not use any external dependencies. To run this, simply follow theses steps:

go build server.go
./server

This will run a HTTP server on port 8080. To test the issue, open the page with Chromium, open the developer tools network tab and reload the page. Upon loading

@exhuma
exhuma / colorize.py
Created February 22, 2017 10:44
Colorful werkzeug logging
import logging
import re
P_REQUEST_LOG = re.compile(r'^(.*?) - - \[(.*?)\] "(.*?)" (\d+) (\d+|-)$')
LOG = logging.getLogger('werkzeug')
def colorize_werkzeug():
@exhuma
exhuma / description.md
Created February 2, 2017 09:04
flask-exception-problem

I've tried upgrading from Flask 0.10.1 to 0.12 today and ran into a little issue:

I am maintaining a larger application which also provides a JSON API on top of a subset of it's functionalities via Flask. In order to make error handling consistent I defined a simple mixin class:

class RestExceptionMixin(object):
    """
    Mixin for exceptions which can be used in a REST API.
    """
    status_code = 400

Keybase proof

I hereby claim:

  • I am exhuma on github.
  • I am exhuma (https://keybase.io/exhuma) on keybase.
  • I have a public key whose fingerprint is 033C FABB FBCE 2387 C88D E243 8C72 CFB3 4D7E BB44

To claim this, I am signing this object:

@exhuma
exhuma / timed_exec.py
Created September 26, 2016 06:01
Example of running functions at given time intervals.
from time import sleep
import logging
LOG = logging.getLogger(__name__)
def every_5_seconds():
LOG.info('Running every 5')