Skip to content

Instantly share code, notes, and snippets.

View dmoisset's full-sized avatar

Daniel F Moisset dmoisset

View GitHub Profile
@dmoisset
dmoisset / module.js
Created August 7, 2021 10:22
Add extra skill to 5e system in FoundryVTT
import { DND5E } from "../../../systems/dnd5e/module/config.js";
// Update list of skills
DND5E.skills.eng = "Engineering";
Hooks.once("init", function () {
game.system.model.Actor.character.skills.eng = {value: 0, ability: "int"};
});
// This seems to work. are there any issues?
#type: ignore
from math import pi
# Original haskell code from: https://www.haskellforall.com/2021/01/the-visitor-pattern-is-essentially-same.html
# -- | This plays the same role as the old `Shape` type
# type Shape = forall shape
# . (Double -> Double -> Double -> shape)
# -> (Double -> Double -> Double -> Double -> shape)
# -> shape
from contextlib import contextmanager
@contextmanager
def breakable():
class Break(Exception): pass
def breaker(): raise Break
try:
yield breaker
except Break:
pass
# Original: https://github.com/python/cpython/blob/46abfc1416ff8e450999611ef8f231ff871ab133/Lib/logging/config.py#L438-L464
def convert(self, value):
"""
Convert values to an appropriate type. dicts, lists and tuples are
replaced by their converting alternatives. Strings are checked to
see if they have a conversion format and are converted if they do.
"""
match value:
case ConvertingDict() | ConvertingList() | ConvertingTuple:
# based on https://github.com/python/cpython/blob/9538bc9185e934bee2bd5ae2cda2b2e92a61906d/Lib/distutils/command/build_ext.py#L357-L385
match ext:
case Extension():
continue
case tuple((str(ext_name), {"sources": build_src})) if extension_name_re.match(ext_name):
log.warn("old-style (ext_name, build_info) tuple found in "
"ext_modules for extension '%s' "
"-- please convert to Extension instance", ext_name)
ext = Extension(ext_name, build_src)
case _:
@dmoisset
dmoisset / gist:785428692cfc3a969bce71dc826572b7
Created April 10, 2018 14:43
test failure mypy af7e834
====================================================== FAILURES =======================================================
______________________________________________ TestPEP561.test_typed_pkg ______________________________________________
[gw1] linux -- Python 3.6.2 /home/machinalis/.virtualenvs/mypy-dev/bin/python3
self = <mypy.test.testpep561.TestPEP561 testMethod=test_typed_pkg>
def test_typed_pkg(self) -> None:
"""Tests type checking based on installed packages.
This test CANNOT be split up, concurrency means that simultaneously
# Build functions that can be applied with **, mimicing the dollar operator in Haskell
class ApplyableFunc():
def __init__(self, func):
self.func = func
def __call__(self, *args, **kwargs):
return self.func(*args, **kwargs)
def __pow__(self, arg):
@dmoisset
dmoisset / lr.py
Created July 26, 2016 14:53 — forked from alep/lr.py
Logistic Regresion (with type annotations).
# An example implementation of Logistic Regression
# Originally by Alejandro Peralta
# Type annotation by Daniel Moisset
import numpy as np
import scipy as sp
from sklearn import cross_validation
from sklearn.utils.fixes import expit as logistic_sigmoid
from sklearn.utils.extmath import log_logistic
import json
import sys
# You need scapy installed to run this
from scapy.utils import PcapReader
import scapy.layers.inet
def main():
if len(sys.argv) != 2:
sys.stderr.write("Usage: %s <filename.pcap>\n\n" % sys.argv[0])
@dmoisset
dmoisset / timer.py
Created March 10, 2014 22:11
A small timer useful for testing
import contextlib
from datetime import datetime
class Timer(object):
def start(self):
self.start = datetime.now()
def stop(self):