Skip to content

Instantly share code, notes, and snippets.

View billmetangmo's full-sized avatar

Bill Metangmo billmetangmo

  • France
View GitHub Profile
import unittest
from typing import List, Dict
from tqdm import tqdm
def distribute_elements(stream: List[int], servers: List[str], weights: List[int]) -> Dict[str, List[int]]:
if len(servers) != len(weights):
raise ValueError("The number of servers and weights must be the same.")
total_weight = sum(weights)
normalized_weights = [weight / total_weight for weight in weights]
@billmetangmo
billmetangmo / cfn-patches.yml
Last active January 4, 2024 11:42
Code to add a new domain to aws copilot
- op: add
path: /Resources/HTTPSRulePriorityAction1
value:
Metadata:
'aws:copilot:description': 'Custom resource assigning priority for the first HTTPS listener rule'
DependsOn: HTTPSListenerRule
Type: Custom::RulePriorityFunction
Properties:
ServiceToken: !GetAtt RulePriorityFunction.Arn
RulePath: ["/"]
@billmetangmo
billmetangmo / gitab-pipelines-stages-histogram.py
Created October 6, 2023 11:17
Generate histogram from gitlab pipelines scrape with Bardeen
import pandas as pd
import datetime
import re
import matplotlib.pyplot as plt
# Load the CSV file
df = pd.read_csv("/mnt/data/06-10-2023_10-10.csv")
# Function to convert status text to timedelta
def convert_to_timedelta_updated_with_weeks(text):
@billmetangmo
billmetangmo / slack_archive.py
Created September 12, 2023 15:49
slack archive channels
import os
import pandas as pd
from slack_sdk import WebClient
from slack_sdk.errors import SlackApiError
import csv
from time import sleep
# Initialize Slack client with your token
client = WebClient(token="<SLACK_BOT_TOKEN>")
@billmetangmo
billmetangmo / categories.py
Last active August 5, 2023 11:58
Détermine si une question compta online peut-être répondu juste juridiquement
from openpyxl import load_workbook
import csv
from collections import defaultdict, Counter
# Load the workbook
file_path = "Forum Gestion Entreprise Compta online.xlsx"
workbook = load_workbook(file_path)
sheet = workbook['Sheet1']
# Get the content of the "Droit pourquoi?" column
@billmetangmo
billmetangmo / argilla.py
Created August 4, 2023 23:30
Label output LLM
import argilla as rg
from argilla.client.feedback.schemas.records import ResponseSchema, SuggestionSchema, ValueSchema
rg.init(
api_url="http://localhost:6900",
api_key="admin.apikey"
)
dataset = rg.FeedbackDataset(
guidelines="Add some guidelines for the annotation team here.",
@billmetangmo
billmetangmo / ocr_pdf_scanneds.md
Created July 31, 2023 15:11
ocr_pdf_scanneds

Comment détecter les tableaux sur les pages de pdf scannés ?

Détecter les tableaux dans des pages de PDF scannés est un problème qui implique plusieurs étapes, car vous travaillez avec des images numérisées plutôt qu'avec du texte numérique. Voici une approche générale:

  1. OCR (Reconnaissance optique de caractères) : La première étape consiste à utiliser une technologie OCR pour transformer les images numérisées en texte lisible par une machine. Il existe plusieurs outils qui peuvent faire cela, y compris Google's Vision API, Tesseract, Adobe's Acrobat, et d'autres. Notez que la qualité de la numérisation et la netteté de l'image peuvent affecter la précision de l'OCR.

  2. Détection des tableaux : Une fois que vous avez du texte lisible par une machine, vous pouvez commencer à détecter les tableaux. Il s'agit souvent d'une tâche difficile, car les tableaux peuvent avoir des formats très différents. Vous pourriez envisager d'utiliser des expressions régulières pour détecter des motifs qui res

@billmetangmo
billmetangmo / guess_encoding.py
Created July 21, 2023 20:51
Guess encoding (python)
import chardet
def guess_encoding(file):
with open(file, 'rb') as f:
result = chardet.detect(f.read())
return result['encoding']
encoding = guess_encoding(csv_file)
df = pd.read_csv(csv_file, encoding=encoding)
import urllib2
from bs4 import BeautifulSoup
url = "https://www.compta-online.com/oubli-de-facturation-facture-faite-posteriori-t72224#NULL"
response = urllib2.urlopen(url)
html = response.read()
soup = BeautifulSoup(html, 'html.parser')
# Find the input element with the name 'text'
@billmetangmo
billmetangmo / client.py
Created July 6, 2023 21:51
openrefine_external_call
import urllib.request
import json
# Define the URL of the Flask service
service_url = "https://5000-mongulucm-mtchounmouh-h28ndlzaxu8.ws-eu99.gitpod.io/extract_text"
# Define the URL to be scraped
scrape_url = "https://www.compta-online.com/oubli-de-facturation-facture-faite-posteriori-t72224#NULL"
# Combine these into the full request URL