Skip to content

Instantly share code, notes, and snippets.

View philippegirard's full-sized avatar
🛠️
Building IoT platform

Philippe Girard philippegirard

🛠️
Building IoT platform
View GitHub Profile
### Keybase proof
I hereby claim:
* I am philippegirard on github.
* I am philippegirard (https://keybase.io/philippegirard) on keybase.
* I have a public key ASDRpmjw9gY3zLi2-i8rQG_rcL4zHQwUZ6i6cq0kkD2pUAo
To claim this, I am signing this object:
@philippegirard
philippegirard / fastapi-graphql.py
Last active March 28, 2020 20:22
FastAPI : async GraphQL (Graphene)
import graphene
from fastapi import FastAPI
from starlette.graphql import GraphQLApp
from graphql.execution.executors.asyncio import AsyncioExecutor
class Query(graphene.ObjectType):
hello = graphene.String(
name=graphene.String(default_value="stranger")
)
@philippegirard
philippegirard / logging.conf
Last active March 9, 2023 08:27
FastAPI logging
[loggers]
keys=root,uicheckapp
[handlers]
keys=consoleHandler,detailedConsoleHandler
[formatters]
keys=normalFormatter,detailedFormatter
[logger_root]
@philippegirard
philippegirard / main.py
Last active April 18, 2020 20:10
fastapi logging main.py
import logging
from fastapi import FastAPI
from uicheckapp.services import EchoService
# setup loggers
logging.config.fileConfig('logging.conf', disable_existing_loggers=False)
# get root logger
logger = logging.getLogger(__name__) # the __name__ resolve to "main" since we are at the root of the project.
# This will get the root logger since no logger in the configuration has this name.
@philippegirard
philippegirard / services.py
Created April 18, 2020 20:14
fastapi logging services
import logging
logger = logging.getLogger(__name__) # the __name__ resolve to "uicheckapp.services"
# This will load the uicheckapp logger
class EchoService:
def echo(self, msg):
logger.info("echoing something from the uicheckapp logger")
print(msg)
@philippegirard
philippegirard / main.py
Created April 18, 2020 20:17
fastapi logging middleware
@app.middleware("http")
async def log_requests(request: Request, call_next):
idem = ''.join(random.choices(string.ascii_uppercase + string.digits, k=6))
logger.info(f"rid={idem} start request path={request.url.path}")
start_time = time.time()
response = await call_next(request)
process_time = (time.time() - start_time) * 1000
@philippegirard
philippegirard / main.py
Created April 18, 2020 20:18
fastapi logging middleware
import logging
from fastapi import FastAPI
from uicheckapp.services import EchoService
logging.config.fileConfig('logging.conf', disable_existing_loggers=False)
logger = logging.getLogger(__name__)
app = FastAPI()
@philippegirard
philippegirard / main.py
Created April 19, 2020 00:55
fastAPI sentry middleware
import sentry_sdk
from fastapi import FastAPI
sentry_sdk.init(
dsn="your_dns",
)
app = FastAPI()
@philippegirard
philippegirard / test_helper.rb
Created July 23, 2020 21:51
Omniauth integration testing
ENV['RAILS_ENV'] ||= 'test'
require_relative '../config/environment'
require 'rails/test_help'
OmniAuth.config.test_mode = true
class ActiveSupport::TestCase
# ...some code here
def login_shop(shop)
@philippegirard
philippegirard / product_controller_test.rb
Last active July 23, 2020 22:40
Any Controller test
require 'test_helper'
class ProductsControllerTest < ActionDispatch::IntegrationTest
# This methods gets called before each test.
def setup
@shop = shops(:regular_shop)
login_shop(@shop)
end
test "post should work" do