Skip to content

Instantly share code, notes, and snippets.

View MaxHalford's full-sized avatar

Max Halford MaxHalford

View GitHub Profile
@MaxHalford
MaxHalford / annuairechambresdhotes.com.py
Last active August 10, 2023 12:36
Scraping chambres d'hôtes
import requests
from bs4 import BeautifulSoup
from PIL import Image
import pytesseract
from io import BytesIO
from dataclasses import dataclass
from tqdm import tqdm
@dataclass
class Ad:
@MaxHalford
MaxHalford / 11_bananas.ipynb
Last active January 25, 2023 00:54
Tree experiments
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@MaxHalford
MaxHalford / dataset.csv
Last active March 11, 2023 06:33
Are Airbnb guests less energy efficient than their host?
date kilowatt-hour n_hosts n_guests temperature
2022-01-01 2.171 0.0 0.0 7.875000000000028
2022-01-02 10.31 0.0 0.5 8.787500000000023
2022-01-03 16.107 0.0 1.0 8.35000000000003
2022-01-04 16.563 0.0 1.0 9.250000000000014
2022-01-05 17.098 0.0 1.0 5.700000000000024
2022-01-06 18.76 0.0 1.0 2.950000000000024
2022-01-07 20.853 0.0 1.0 3.2500000000000284
2022-01-08 19.548 0.0 1.0 8.887500000000031
2022-01-09 20.81 0.0 1.0 8.72500000000003
import pandas as pd
cards = pd.read_csv('archive/hearthstone_standard_cards.csv')
cards['multiClassIds'] = cards['multiClassIds'].map(eval)
cards = cards.explode('multiClassIds')
cards['multiClassIds'] = cards['multiClassIds'].fillna(cards['classId'])
classes = pd.read_csv('archive/metadata/classes.csv', index_col='id')
cards['class'] = cards['multiClassIds'].map(classes['name'])
@MaxHalford
MaxHalford / profiles.yml
Created November 29, 2022 23:12
Local DuckDB setup
project:
outputs:
prod:
type: duckdb
path: /tmp/project.duckdb
target: prod
<!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>
@MaxHalford
MaxHalford / merge.py
Created June 15, 2022 17:21
Group by merge
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 February 16, 2021 10:02
ABBYY synchronous query
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 January 27, 2021 18:29
Pure Python random laws
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 January 5, 2021 14:52
Tree implementation
"""Generic branch and leaf implementation."""
import operator
import textwrap
import typing
class Op:
"""An operator that is part of a split."""
__slots__ = "symbol", "func"