Skip to content

Instantly share code, notes, and snippets.

View athoune's full-sized avatar

Mathieu Lecarme athoune

View GitHub Profile
@athoune
athoune / test_smtp.py
Created February 12, 2024 16:47
Test your SMTP settings
import smtplib
import base64
user = 'bob'
password = 'password'
# The server handle TLS connection, not the boring STARTTLS upgrade
server = smtplib.SMTP_SSL(host='smtp.example.com', timeout=5)
server.ehlo() # the server say its name and handled commands, you should see "AUTH PLAIN"
# The RFC for SMTP doesn't say wich text encoding must be used, smtplib use low ASCII, lets forge the command
@athoune
athoune / github_webhook.py
Last active October 15, 2022 13:51
aiohttp webhook for github
async def github_webhook(secret :str, request :web.Request) -> dict:
assert request.content_length < 1000000, "Request content too fat" # 1M
digest, signature = request.headers['X-HUB-SIGNATURE'].split("=", 1)
assert digest == "sha1", "Digest must be sha1" # use a whitelist
body = await request.content.read()
h = hmac.HMAC(bytes(secret, "UTF8"), msg=body, digestmod=digest)
assert h.hexdigest() == signature, "Bad signature"
return json.loads(body.decode('UTF8'))
@athoune
athoune / ping.py
Created October 10, 2016 12:16
async ping for python 3
#!/usr/bin/env python3
import asyncio
@asyncio.coroutine
def ping(loop, target, dump=False):
create = asyncio.create_subprocess_exec('ping', '-c', '10', target,
stdout=asyncio.subprocess.PIPE)
proc = yield from create
@athoune
athoune / server.py
Created September 28, 2020 19:52
Route to healthy server
#!/usr/bin/env python3
import signal
import os
from flask import Flask, abort
from werkzeug.serving import run_simple
state = True
@athoune
athoune / gist:01a739ed722257e613e1
Created November 10, 2014 20:14
Sending Luigi failure to Sentry
import os
import sys
import luigi
from raven import Client
client = Client()
# Define your Luigi tasks here
@luigi.Task.event_handler(luigi.Event.FAILURE)
@athoune
athoune / cgroup_swap.py
Last active June 2, 2020 15:13
display swap and rss in cgroup services
#!/usr/bin/env python3
from pathlib import Path
def containerd():
for p in Path("/sys/fs/cgroup/memory/system.slice/containerd.service/").iterdir():
if not p.is_dir():
continue
print(p.name)
with (p / "memory.stat").open("r") as f:
@athoune
athoune / who_connect.py
Last active May 29, 2020 08:46
nia nia nia ssh public key
#!/usr/bin/env python3
import pwd
import sys
import re
import subprocess
import tempfile
import os
import io
from collections import namedtuple
@athoune
athoune / mailq.py
Last active October 17, 2019 20:11
Parsing mailq format (from Postfix 2.x)
#!/usr/bin/env python3
import subprocess
import re
from pypred import Predicate
SPACE = re.compile(r"\s+")
def mailq():
@athoune
athoune / Dockerfile
Created September 5, 2016 16:12
Dockerfile for tmate-slave with Archlinux
FROM base/archlinux
RUN pacman-key --populate archlinux &&\
pacman-key --refresh-keys &&\
pacman-key -r arojas@us.es
RUN pacman -Sy
RUN yes | pacman -Sy libevent libssh libutempter msgpack-c openssl zlib automake cmake ruby autoconf gcc pkg-config make libunistring git
@athoune
athoune / metaping.py
Created June 28, 2016 15:29
Ping all the ping
#!/usr/bin/env python3
import os
import asyncio
import aiohttp
from aiohttp import web
@asyncio.coroutine
def do_ping(session, domain):