Skip to content

Instantly share code, notes, and snippets.

🐢
Slowly advancing on hobby projects

Michel Albert exhuma

🐢
Slowly advancing on hobby projects
Block or report user

Report or block exhuma

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@exhuma
exhuma / accept.py
Created Aug 8, 2019
Parser for the "Accept" header in HTTP requests
View accept.py
"""
This module contains helpers to work with the "Accept" request header
"""
import re
from typing import Generator, Iterable, List, NamedTuple, Tuple
AcceptType = NamedTuple('AcceptType', [
('media_type', str),
('quality', float),
])
@exhuma
exhuma / wincred.py
Last active Aug 13, 2019 — forked from mrh1997/wincred.py
Retrieve Windows Credential via Python
View wincred.py
"""
Access windows credentials
Credentials must be stored in the Windows Credentials Manager in the Control
Panel. This helper will search for "generic credentials" under the section
"Windows Credentials"
Example usage::
result = get_generic_credential('foobar')
@exhuma
exhuma / ipoccupation.py
Created Nov 22, 2018
Class to visualise which blocks in a IP range are occupied by networks and hosts
View ipoccupation.py
class IPOccupation:
'''
Class to visualise which blocks in a IP range are occupied by networks and hosts
'''
CHARS = {
0: '\u22c5', # sdot
1: '\u2592', # Medium Shade
2: '\u2588' # Full Block
}
@exhuma
exhuma / namedregistry.py
Created Sep 17, 2018
Python ABC to register subclasses with a name for easy retrieval.
View namedregistry.py
class NamedRegistry(ABCMeta):
'''
A metaclass which automatically registers each subclass by name when it is
defined.
Each subclass must define the class-attribute ``NAME``
The classes can be retrieved using ``NamedRegistry.get_query``.
'''
@exhuma
exhuma / colortrace.py
Last active Apr 5, 2018
Fancy Colorful Python Traceback
View colortrace.py
'''
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 Mar 16, 2018
Colorise parametric value using Python
View colorise.py
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 Mar 18, 2018
Quick & Dirty Rocket.Chat client
View 01-README.rst

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 Dec 24, 2017
Using dedent to keep multi-line-strings on same indent-level as the rest
View with_dedent.py
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 Oct 26, 2017
Problem with infinity timestamps in SQLAlchemy?
View README.rst

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 Oct 15, 2017
Example service which returns a custom media-type with a +json indicator
View README.rst

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

You can’t perform that action at this time.