Skip to content

Instantly share code, notes, and snippets.

View stephanh42's full-sized avatar

Stephan Houben stephanh42

  • Heythuysen, The Netherlands
View GitHub Profile
"""Sine in degrees.
Copyright 2018 Stephan Houben
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFT
@stephanh42
stephanh42 / freeze.py
Created November 30, 2017 11:32
Convert object into a read-only (frozen) variant. Well, to the extent possible.
from functools import singledispatch
from types import MappingProxyType
@singledispatch
def freeze(obj):
"""Convert obj into a read-only (frozen) variant. Well, to the extent possible."""
""" Example: foo = freeze({"x": [1,2,{3,4}]})
"""
return obj # not much frost today
@stephanh42
stephanh42 / LICENSE
Last active November 22, 2017 08:04
Check a Python source code if it contains identifiers which are confusable.
MIT License
Copyright (c) 2017 Stephan Houben
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@stephanh42
stephanh42 / spaces.txt
Created November 17, 2017 15:58
Various outside-the-usual Unicode whitespace characters
U+001C || [FILE SEPARATOR]
U+001D || [GROUP SEPARATOR]
U+001E || [RECORD SEPARATOR]
U+001F || [UNIT SEPARATOR]
U+00A0 | | NO-BREAK SPACE
U+1680 | | OGHAM SPACE MARK
U+2000 | | EN QUAD
U+2001 | | EM QUAD
U+2002 | | EN SPACE
U+2003 | | EM SPACE
@stephanh42
stephanh42 / compose.py
Created October 26, 2017 11:42
Attempt at efficient funciton composition on Python
from functools import lru_cache
def identity(x):
return x
@lru_cache(None)
def _make_compose(n):
if n == 0:
return lambda: identity
elif n == 1:
"""
Support `fake` binary operator
so we can do
a @f@ b
in addition to (and with the same meaning as):
f(a, b)
"""
import collections.abc
@stephanh42
stephanh42 / unicode.vim
Last active June 1, 2017 10:10
Allow Unicode characters to be written in Vim using LaTeX-like abbrev's.
iab AE\ Æ
iab Alpha\ Α
iab Angle\ ⦜
iab Beta\ Β
iab Bumpeq\ ≎
iab Cap\ ⋒
iab Chi\ Χ
iab Colon\ ∷
iab Cup\ ⋓
iab DH\ Ð
@stephanh42
stephanh42 / class_extend.py
Created February 10, 2017 19:00
Python class extensions a la Objective-C "categories"
#class extensions a la Objective-C "categories"
#using metaclasses
excluded_methods = frozenset(["__module__", "__qualname__"])
def class_extend(cls):
class Meta(type):
def __new__(self, name, bases, attrs, **kwargs):
for name, value in attrs.items():
if name not in excluded_methods:
@stephanh42
stephanh42 / emoji.txt
Created June 5, 2016 20:08
Unicode Emoji symbols
U+1f601 😁
U+1f602 😂
U+1f603 😃
U+1f604 😄
U+1f605 😅
U+1f606 😆
U+1f607 😇
U+1f608 😈
U+1f609 😉
U+1f60a 😊
import os
from IPython.qt.console.rich_ipython_widget import RichIPythonWidget
from IPython.qt.manager import QtKernelManager
from IPython.qt.inprocess import QtInProcessKernelManager
from IPython.kernel.zmq.ipkernel import Kernel
from IPython.kernel.inprocess.ipkernel import InProcessKernel
from IPython.lib import guisupport