Skip to content

Instantly share code, notes, and snippets.

View benoit-cty's full-sized avatar

Benoit Courty benoit-cty

View GitHub Profile
@benoit-cty
benoit-cty / fastapi_cancel_test.py
Last active September 8, 2023 12:40
Demonstrates how to cancel a task when the client disconnects in FastAPI.
"""
Demonstrates how to cancel a task when the client disconnects in FastAPI.
This reduce cpu consumption and memory usage for long tasks if clients stop waiting for answers.
Code from Scott Driggers posted at https://gist.github.com/msdrigg/02c7716d6e2a0cb4e5ef08d14f180119
Initial discussion at here https://github.com/tiangolo/fastapi/discussions/8805
Note: using these methods will likely discard request body (because they call receive and discard the result)
So it is not suitable for websocket or streaming requests.
@benoit-cty
benoit-cty / robot.nqc
Created April 22, 2021 10:02
Robot Lego RCX 2.0
int speed, __speed;
task music()
{
while (true)
{
PlayTone(262,40); Wait(50);
PlayTone(294,40); Wait(50);
PlayTone(330,40); Wait(50);
PlayTone(294,40); Wait(50);
@benoit-cty
benoit-cty / slack_backup.py
Last active August 25, 2023 16:32
Script to archive Slack messages from a channel list.
'''
Script to archive Slack messages from a channel list.
You have to create a Slack Bot and invite him to private channels.
View https://github.com/docmarionum1/slack-archive-bot for how to configure your account.
Then provide the bot token to this script with the list of channels.
'''
TOKEN='xoxb-xxxxx-xxxxxx-xxxxxxxxxxx'
channels = {
@benoit-cty
benoit-cty / download.py
Created October 8, 2020 08:51
Download WorkBank Data
import requests
import os
'''
https://climateknowledgeportal.worldbank.org/download-data
'''
PATH = '/temp/'
nature_of_data = ['projection', 'historical']
past_time_series = ["1901-1930", "1931-1960", "1961-1990", "1901-2016", "1991-2016"]
@benoit-cty
benoit-cty / asound.conf
Last active September 20, 2019 20:14
Project Alice confs
# UPDATED : seems to work but I have still some problems I think
# use samplerate to resample as speexdsp resample is bad
defaults.pcm.rate_converter "samplerate"
pcm.!default {
type asym
playback.pcm "playback"
capture.pcm "ac108"
}