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 / mandelbrot.py
Last active February 2, 2020 10:22
Mandelbrot
# pylint: disable=no-member, no-name-in-module
"""
This program is inspired on exercise 4.4 from the book for 1CB "CNESC
Informatique" (2019-2020): The Mandelbrot set. The exercise demands the
following features:
* Display the Mandelbrot set on the complex plane. Initially between -2.2-1.2j
and 1.0+1.2j and later by coordinates selected by the user (see below).
* Points within the set should be drawn in black, points outside of the set
should be colored based on the number of iterations necessary to determine
@exhuma
exhuma / read_prices.py
Created October 2, 2019 06:52
Scrape Prices from a Web-Page
"""
This module shows an alternative implementation of the code shown in the SO question
https://stackoverflow.com/questions/58188342/looping-through-web-pages
Comments marked with a ♫ symbol are possible improvements to this code which were
left out to keep concepts out of the code which could make it more difficult to
understand for beginners.
"""
from os.path import exists
@exhuma
exhuma / accept.py
Created August 8, 2019 11:45
Parser for the "Accept" header in HTTP requests
"""
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 February 26, 2024 10:15 — forked from mrh1997/wincred.py
Retrieve Windows Credential via Python
"""
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 November 22, 2018 17:09
Class to visualise which blocks in a IP range are occupied by networks and hosts
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 September 17, 2018 12:46
Python ABC to register subclasses with a name for easy retrieval.
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 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(
'''\