Skip to content

Instantly share code, notes, and snippets.

View arouene's full-sized avatar

Aurélien Rouëné arouene

  • Lucca
  • Nantes (France)
View GitHub Profile
@arouene
arouene / subprocess_run.py
Created April 10, 2018 11:49
Python backports
# Backport subprocess.run for Python 3.3 and 3.4
import subprocess
if not 'run' in subprocess.__all__:
class CompletedProcess(object):
def __init__(self, stdout, stderr, returncode):
self._stdout = stdout
self._stderr = stderr
@arouene
arouene / add_ec2_to_route53.py
Created April 16, 2018 14:20
add ec2 instances with tag Name in Route53 Domain
import os
import boto3
HOSTED_ZONE_ID = "ABCDEF123456789"
DOMAIN_NAME = ".example.lan."
def lambda_handler():
# Setup Boto3 client
boto3.setup_default_session(region_name='us-east-1')
ec2 = boto3.client("ec2")
@arouene
arouene / curl-format.txt
Created April 16, 2018 14:38
Format file for timing benchmark with curl
time_namelookup : %{time_namelookup}\n
time_connect : %{time_connect}\n
time_appconnect : %{time_appconnect}\n
time_pretransfer : %{time_pretransfer}\n
time_redirect : %{time_redirect}\n
time_starttransfer : %{time_starttransfer}\n
------------------------------------------\n
time_total : %{time_total}\n

Keybase proof

I hereby claim:

  • I am shengis on github.
  • I am shengis (https://keybase.io/shengis) on keybase.
  • I have a public key ASDNQwDduUpozyIMWvxrI6nWaYHbY5qvtEG241BvnIrD6wo

To claim this, I am signing this object:

@arouene
arouene / check_user.c
Last active August 2, 2018 09:21
Test pam service authentication
/*
Needs pam-devel on Fedora to build
Build cmd: gcc -o check_user -lpam -lpam_misc check_user.c
Edited from the example took in Linux-PAM_ADG.txt
Originally contributed by Shane Watts
*/
#include <security/pam_appl.h>
#include <security/pam_misc.h>
@arouene
arouene / mutex_decorator.py
Created August 27, 2018 07:37
Python decorator for exclusive methods
def one_at_a_time(message):
''' Decorator for exclusive methods
Using like this:
@one_at_a_time("Deployment or build already running")
def deploy(self, msg, args)
'''
def mutex_decorator(func):
@wraps(func)
def wraper(self, *args, **kwargs):
if not mutex.locked():
@arouene
arouene / test_email.py
Created September 27, 2018 15:25
Test if an email exists by trying to send an email (but not doing it)
#!/bin/env python
# Test email address
# return code :
# 0 -> OK
# 1 -> Not Valid
# 2 -> Could not connect to mail server
from sys import argv, exit
import dns.resolver
@arouene
arouene / 256color.go
Created October 1, 2018 09:46
Use ANSI code to test color capabilites of a terminal
// Test terminals color capabilities
package main
import "fmt"
func main() {
const (
normal = "\033[0m"
color = "\033[%d;%dm"
@arouene
arouene / smtp.go
Last active May 22, 2021 23:31
Send emails using SMTP with TLS support in Go using standard libraries only
// Connecting to a SMTP server to send an email in Go
// - Support TLS and optional password
// - A CA file can be provided or it will use the CA bundle of your OS
//
// Usage:
// s := smtp.NewSMTP("localhost", "[email protected]", "[email protected]")
// s.SetPort(465)
// s.SetTLS(true)
// s.SetUser("login/user")
// s.SetPassword("password")
@arouene
arouene / mux.go
Created November 14, 2020 15:35
Golang http muxer with middleware support
package mux
import (
"fmt"
"net/http"
)
type Middleware struct {
mux *http.ServeMux
middlewares [](func(http.Handler) http.Handler)