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 / pwatch.sh
Last active September 7, 2022 20:40
Interruptible process watcher
#!/bin/bash
declare -a JOBS
JOBS=("sleep 1" "sleep 2" "sleep 3")
cleanup() {
trap "" SIGTERM
kill 0
wait
@arouene
arouene / signal.go
Last active January 18, 2021 17:39
Signal interruption pattern for Go
func main() {
running := true
// Make a channel the signal handler will subscribe
sigc := make(chan os.Signal, 1)
// Notify will send a sigint or sigterm signal to the
// the previously created channel `sigc`
signal.Notify(sigc, syscall.SIGINT, syscall.SIGTERM)
go func() {
@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)
@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 / 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 / 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 / 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 / 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>

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 / 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