Skip to content

Instantly share code, notes, and snippets.

View bourdeau's full-sized avatar

Pierre-Henri bourdeau

  • La Rochelle
View GitHub Profile
import asyncio
from random import randint
import aiofiles
import request
import aiohttp
async def async_http_request():
"""
I'm using aiohttp lib to make the http request and it's
❯ terraform plan
module.staysail.random_password.polaris_secret_key: Refreshing state... [id=none]
module.staysail.random_password.database_password: Refreshing state... [id=none]
module.staysail.module.gce-lb-http.google_compute_global_address.default_ipv6[0]: Refreshing state... [id=projects/staysail/global/addresses/stay-sail-lb-preprod-ipv6-address]
module.staysail.module.gce-lb-http.google_compute_managed_ssl_certificate.default[0]: Refreshing state... [id=projects/staysail/global/sslCertificates/stay-sail-lb-preprod-cert]
module.staysail.module.gce-lb-http.google_compute_global_address.default[0]: Refreshing state... [id=projects/staysail/global/addresses/stay-sail-lb-preprod-address]
module.staysail.data.google_compute_default_service_account.default: Reading...
module.staysail.google_project_iam_member.trace_user: Refreshing state... [id=staysail/roles/cloudtrace.user/serviceAccount:polaris-preprod@staysail.iam.gserviceaccount.com]
"""
The Session.commit() operation unconditionally issues Session.flush() before emitting COMMIT on relevant database

There are only 2 scenarios I see when session.flush() could be call manually:
- `autoflush = False`: then flush might been needed if the object need to be query in the Session
- to get the AUTOINCREMENT ID which are EVIL (🔪🔪🔪🐱)

I wrote a few examples to illustrate this.
"""
import pandas as pd
import time
from contextlib import contextmanager
import dask.dataframe
import redis
import struct
import numpy as np
import pickle
---[ REQUEST ]---------------------------------------
GET /v1/projects/gleephpro-prod-368114/locations//repositories/gleephpro:getIamPolicy?alt=json HTTP/1.1
Host: artifactregistry.googleapis.com
User-Agent: Terraform/1.3.3 (+https://www.terraform.io) Terraform-Plugin-SDK/2.10.1 terraform-provider-google/dev
Content-Type: application/json
Accept-Encoding: gzip
-----------------------------------------------------: timestamp=2022-11-09T17:48:06.157+0100
2022-11-09T17:48:06.158+0100 [WARN] Provider "registry.terraform.io/hashicorp/google" produced an invalid plan for module.gleephpro.google_storage_bucket.medias, but we are tolerating it because it is using the legacy plugin SDK.
module.gleephpro.google_artifact_registry_repository_iam_binding.cross_accounts[0]: Creating...
╷
│ Error: Error retrieving IAM policy for artifactregistry repository "projects/prod/locations//repositories/docker": googleapi: Error 400: Request contains an invalid argument.
│ 
│   with module.gleephpro.google_artifact_registry_repository_iam_binding.cross_accounts[0],
│   on ../../modules/gleephpro/iam.tf line 15, in resource "google_artifact_registry_repository_iam_binding" "cross_accounts":
│   15: resource "google_artifact_registry_repository_iam_binding" "cross_accounts" {
│ 
╵
@bourdeau
bourdeau / sources.md
Last active June 11, 2019 13:49
Sources
@bourdeau
bourdeau / Python_Stuff.md
Last active April 21, 2023 05:58
Python Stuff

Inheritance & DI

Multiple inheritance can lead to multi level diamond diagram. In Python it is solved by C3 linearization.

Python doesn't need DI because it has super(). It doesn't work like parent() in other Typed programming languages such as Java or PHP.

In multiple inheritance super() doesn't call the parents but the ancestors:

class Adam(): pass
use function App\Service\Mailer\send

// Splat Operator (...) (Variadic functions)
public function __construct(callable $client, array $defaultHeaders = [], Adapter ...$adapters)

APPLICATION DESIGN

Inheritance & Composition 😱

Don't use inheritance as another way to copy/paste code.

class EmailRubbish
{
 public function sendEmail(string $email, string $subject): void