Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View michelbl's full-sized avatar

Michel Blancard michelbl

View GitHub Profile
@michelbl
michelbl / datetime_surprises.py
Created December 12, 2023 10:11
A list of surprises, using datetimes with the python ecosystem
from datetime import UTC
from zoneinfo import ZoneInfo
TZ_PARIS = ZoneInfo("Europe/Paris")
TZ_UTC = UTC
# datetime equality is bugged
datetime(2023, 10, 29, 2, 30, fold=0, tzinfo=TZ_PARIS) == datetime(2023, 10, 29, 2, 30, fold=1, tzinfo=TZ_PARIS) # True
datetime(2023, 10, 29, 2, 30, fold=0, tzinfo=TZ_PARIS).timestamp() == datetime(2023, 10, 29, 2, 30, fold=1, tzinfo=TZ_PARIS).timestamp() # False
from google.cloud import speech
client = speech.SpeechClient()
audio = speech.RecognitionAudio(uri="gs://speech-data-895/source_2_flac.wav")
config = speech.RecognitionConfig(
language_code="fr-FR",
)
@michelbl
michelbl / tmux.conf
Created May 19, 2020 12:30
Configuration to use mouse and copy/paste with tmux
# Beforehand, to make it work with SSH you'll have to:
# * install xsel and xauth on target host
# * set X11Forwarding=yes in /etc/ssh/sshd_config
# * connect with option "-X"
# * on Mac, install XQuartz
#
# Test with "echo $DISPLAY", that variable should be set on the server
# tmux version 1.6

Keybase proof

I hereby claim:

  • I am michelbl on github.
  • I am michelbl (https://keybase.io/michelbl) on keybase.
  • I have a public key ASARCujZSGtNoYEHB-ddVUZtoUs3wkd1jbpLKlq8gQSdRgo

To claim this, I am signing this object:

@michelbl
michelbl / imap_backup.py
Last active February 3, 2019 10:54
Backup emails using IMAP
"""
Inspired from http://stackp.online.fr/?p=25s
Create a file named "mail_config.py" containing :
HOST = 'mail.gandi.net'
PORT = 993
USER = 'test@mydomain.net'
PASSWORD = '***'
#!/usr/bin/env python
'''
A Python class implementing KBHIT, the standard keyboard-interrupt poller.
Works transparently on Windows and Posix (Linux, Mac OS X). Doesn't work
with IDLE.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
@michelbl
michelbl / python_private_dep.md
Last active October 25, 2021 04:04
Python private dependencies cheatsheet

I need to give access to a private dependency. It can happen for continuous integration or deployment.

Here we use python and github, using the services CircleCI and Heroku. However, the principles applies everywhere.

What is a deploy key?

See https://developer.github.com/v3/guides/managing-deploy-keys/

There are 4 ways of granting access to a private dependency, but deploy keys are a good compromise in term of security and ease of use for projects that do not require too many dependencies (in that case, prefer a machine user). In any case, do not use username/password of a developer account or oauth token as they do not provide privilege limitation.

# See https://forums.meteor.com/t/acceptance-testing-on-circle-ci-2-0/37825/5
version: 2
jobs:
build:
working_directory: ~/app
docker:
- image: circleci/openjdk:8-jdk-browsers
environment:
# lang settings required for Meteor's Mongo
@michelbl
michelbl / danted.conf
Created March 6, 2018 15:47
Very simple, very insecure dante (proxy SOCKS server) conf
logoutput: /var/log/dante.log
errorlog: /var/log/dante.error.log
internal: 51.15.171.195 port = 7165
external: 51.15.171.195
socksmethod: none
clientmethod: none
user.privileged: root
@michelbl
michelbl / squid.conf
Created March 6, 2018 15:46
Very simple, very insecure squid conf
acl localnet src 0.0.0.0/0
http_access allow localhost
http_access allow localnet
http_port 9999
forwarded_for off
request_header_access Allow allow all