Skip to content

Instantly share code, notes, and snippets.

View lmazuel's full-sized avatar

Laurent Mazuel lmazuel

View GitHub Profile
@lmazuel
lmazuel / azure_httpxauth.py
Last active October 20, 2023 17:21
HTTPx wrapper for azure-identity
import typing
import httpx
import requests
from httpx import Auth, Request, Response
from azure.core.credentials import TokenCredential
from azure.core.pipeline.policies import BearerTokenCredentialPolicy
from azure.core.pipeline import PipelineRequest, PipelineContext
from azure.core.pipeline.transport import HttpRequest
@lmazuel
lmazuel / lro.tsp
Last active September 1, 2023 22:54
LRO fun in TypeSpec
import "@typespec/http";
import "@typespec/rest";
import "@typespec/versioning";
import "@azure-tools/typespec-azure-core";
using TypeSpec.Http;
using TypeSpec.Rest;
using TypeSpec.Versioning;
using Azure.Core;
using Azure.Core.Traits;
@lmazuel
lmazuel / next-pylint-runner.py
Last active June 28, 2023 21:01
Run next-pylint on all data-planes
from subprocess import check_output, CalledProcessError, DEVNULL
from pathlib import Path
from multiprocessing import Pool
from ci_tools.environment_exclusions import is_check_enabled
BASE_FOLDER = "/home/lmazuel/git/azure-sdk-for-python/"
TOX_INI = BASE_FOLDER+"eng/tox/tox.ini"
SDK_FOLDER = BASE_FOLDER+"sdk"
def run_next_pylint(folder: str):
@lmazuel
lmazuel / readme.md
Last active June 6, 2023 23:35
Visibility and input values

Overview

Given a visibility on a property on an attribute on a model, should this property be serialized to be sent to the server? This explains the algorithm to let SDK decide what to send or not, depending of create, update, etc.

It doesn't adress on purpose the question of SDK design (one model, more model, kwarg only, etc.), this is a page about serialization on the wire

Tagging property with visibility

@lmazuel
lmazuel / initial_headers.txt
Last active March 20, 2023 22:41
Train Anomaly Detector
Status code: 201
Headers:
'Content-Length': '594',
'Content-Type': 'application/json'
'Location': 'https://lmazuelanom.cognitiveservices.azure.com:443/anomalydetector/v1.1/multivariate/models/0c46cef0-c76e-11ed-83a5-8247640b151e'
'x-envoy-upstream-service-time': '247'
'apim-request-id': 'b5437cd9-f2f1-401b-b431-0993c096350c'
'Strict-Transport-Security': 'max-age=31536000; includeSubDomains; preload'
'x-content-type-options': 'nosniff'
'x-ms-region': 'East US'
@lmazuel
lmazuel / type_generic_inheritance.py
Created March 18, 2023 00:27
Typing with generic and inheritance
from typing import TypeVar, Optional, Generic, Protocol
class Additive(Protocol):
def __add__(self: 'MyReturnType', other: 'MyReturnType') -> 'MyReturnType': ...
MyReturnType = TypeVar("MyReturnType", bound=Additive)
class Foo(Generic[MyReturnType]):
def __init__(self, input: MyReturnType) -> None:
@lmazuel
lmazuel / mvad_polling.py
Last active March 17, 2023 03:15
MVAD Polling
class MVADPolling(LongRunningOperation):
"""Implements MVAD train polling."""
def __init__(self):
self._model_id = None
def can_poll(self, pipeline_response: "PipelineResponseType") -> bool:
# This method is used for algorithm chaining, in MVAD we don't need
# it since this is the only one we will register
return True
@lmazuel
lmazuel / setuptopyproj.py
Created January 27, 2023 23:37
Setup.py to pyproject.toml
# Just having fun, don't take this to seriously :p
import sys
import importlib
def new_module(mod_name):
spec = importlib.machinery.ModuleSpec(mod_name,None)
return importlib.util.module_from_spec(spec)
@lmazuel
lmazuel / cadl_fun.md
Last active December 14, 2022 03:12
CADL Model fun

Syntax 1

op (one: int32, two: int32): void;

Send JSON:

{"one": 12, "two": 47}
@lmazuel
lmazuel / update_labels.py
Created September 2, 2022 18:23
Push labels on Github
import sys
from github import Github, GithubException
REPOS = [
"Azure/azure-sdk-for-python",
"Azure/azure-sdk-for-net",
"Azure/azure-sdk-for-js",
"Azure/azure-sdk-for-java",