Skip to content

Instantly share code, notes, and snippets.

Avatar

Max Halford MaxHalford

View GitHub Profile
View distance.html
<!DOCTYPE html>
<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
<div id="app">
<div class="grid-container">
<button class="grid-item" v-for="key in keys" @click="click(key[0], key[1])">
{{ key[2] }}
</button>
</div>
View merge.py
import itertools
def merge_components(cs):
while True:
for (i, a), (j, b) in itertools.combinations(enumerate(cs), 2):
if a[0] == b[0]:
a[1].extend(b[1])
del cs[j]
break
else:
@MaxHalford
MaxHalford / abbyy.py
Created Feb 16, 2021
ABBYY synchronous query
View abbyy.py
import urllib.parse
import requests
import time
import xml.dom.minidom
def get_abbyy_transcription(doc, app, password):
proxies = {}
url_params = {
@MaxHalford
MaxHalford / poisson.py
Created Jan 27, 2021
Pure Python random laws
View poisson.py
import math
import random
def poisson(l, rng=random):
"""From https://www.johndcook.com/blog/2010/06/14/generating-poisson-random-values/"""
L = math.exp(-l)
k = 0
p = 1
@MaxHalford
MaxHalford / tree.py
Created Jan 5, 2021
Tree implementation
View tree.py
"""Generic branch and leaf implementation."""
import operator
import textwrap
import typing
class Op:
"""An operator that is part of a split."""
__slots__ = "symbol", "func"
@MaxHalford
MaxHalford / rules.py
Created Dec 6, 2020
Rule-based system
View rules.py
import abc
class Rule(abc.ABC):
def __init__(self, var_name):
self.var_name = var_name
@abc.abstractmethod
def __repr__(self):
"""String representation of the Python expression."""
View iter_batches.py
import pandas as pd
def iter_batches(X_y, batch_size):
x_batch = [None] * batch_size
y_batch = [None] * batch_size
j = 0
for i, (x, y) in enumerate(X_y, start=1):
@MaxHalford
MaxHalford / med_filter.pyx
Created Aug 23, 2020
Median filter in Cython
View med_filter.pyx
import numpy as np
cimport cython
cimport numpy as np
ctypedef np.uint_t uint
ctypedef np.uint8_t uint8
@cython.boundscheck(False)
@MaxHalford
MaxHalford / inspect.py
Created Jul 17, 2020
sklearn partial_fit support
View inspect.py
import importlib
import inspect
def worthy(obj):
return inspect.isclass(obj) and hasattr(obj, 'partial_fit')
for _, submodule in inspect.getmembers(importlib.import_module('sklearn'), inspect.ismodule):
for _, obj in inspect.getmembers(submodule, worthy):
print(submodule.__name__, obj.__name__)
@MaxHalford
MaxHalford / linear-models.ipynb
Created Jun 9, 2020
creme mini-batch performance
View linear-models.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.