Skip to content

Instantly share code, notes, and snippets.

View aerostitch's full-sized avatar

aerostitch aerostitch

View GitHub Profile
#!/bin/bash
# packages { ['jq', 'awscli']: ensure => installed }
# cat ~/.aws/config
# [profile ebs_snapshot]
# aws_access_key_id = XXXXXXXXX
# region = us-east-1
# output = json
# aws_secret_access_key = XXXXXXXXXX
export AWS_DEFAULT_PROFILE=ebs_snapshot
@aerostitch
aerostitch / audio-split_flac_using_cue.sh
Created June 15, 2016 23:35
Split a flac file in several ones using a cue file.
# Split a flac file in several ones using a cue file.
# Prerequisites: sudo apt-get install cuetools shntool flac
shnsplit -f *.cue -t "%n-%t" -o "flac flac -s -8 -o %f -" *.flac
import argparse
import re
import subprocess
parser = argparse.ArgumentParser(description='Provides the RTT average and packet loss over N ping commands to a destinatino.')
parser.add_argument('hostname', metavar='HOSTNAME', help='IP or hostname to check the rtt and packet loss from')
parser.add_argument('-c', '--ping-count', metavar='COUNT', default=5, type=int, help='IP or hostname to check the rtt and packet loss from')
args = parser.parse_args()
packets_pattern = re.compile(r'\d+ packets transmitted, \d+ received, (\d+)% packet loss')
import re
import subprocess
import sys
import time
global descriptors
descriptors = []
debug = 1
packets_pattern = re.compile(r'\d+ packets transmitted, \d+ received, (\d+)% packet loss')
rta_pattern = re.compile(r'rtt min/avg/max/mdev = [0-9\.]+/([0-9]+)\.[0-9]+/[0-9\.]+/[0-9\.]+ ms')
import ctypes
import os
def mount(source, target, fs, options=''):
ret = ctypes.CDLL('libc.so.6', use_errno=True).mount(source, target, fs, 0, options)
if ret < 0:
errno = ctypes.get_errno()
raise RuntimeError("Error mounting {} ({}) on {} with options '{}': {}".
format(source, fs, target, options, os.strerror(errno)))
@aerostitch
aerostitch / graceful_shutdown_snippet.go
Created January 12, 2017 19:15
Graceful shutdown snippet
go func() {
signals := make(chan os.Signal, 1)
signal.Notify(signals, os.Kill, os.Interrupt)
<-signals
logger.Println("Initiating shutdown of consumer...")
close(closing)
}()
package main
import (
"crypto/tls"
"fmt"
"gopkg.in/ldap.v2"
"log"
)
// Of course, this is to give an idea of what should be in those variables, but this should end up in environment variables or flags and should not be stored inside the script!
@aerostitch
aerostitch / lsof_repartition_per_user_and_pid.sh
Last active April 11, 2017 23:01
Repartition of the open file descriptors per login name and process id
sudo lsof -n -F 'Lp'| awk 'BEGIN{pid=0; user=""};{if(match($0, /^p([0-9]*)$/, d)){pid=d[1]} if(match($0, /^L(.*)$/,d)){user=d[1]} if(match($0, /^f(.*)$/)){a[sprintf("%s\tpid: %d",user, pid)]++}} END {for (i in a) print a[i], "\tuser: ", i}' | sort -n
@aerostitch
aerostitch / fastly_generate_input_output.go
Last active May 4, 2017 00:03
Generates a json with the list of services and corresponding domains and origins/backends
package main
import (
"encoding/json"
"flag"
"io/ioutil"
"log"
"github.com/gobike/envflag"
"github.com/sethvargo/go-fastly"
@aerostitch
aerostitch / list_all_s3_buckets_websiste_policies.go
Last active May 5, 2017 21:54
Take all the buckets and list their website policy if any. Support multi-region and profile or static auth.
package main
import (
"context"
"encoding/json"
"flag"
"io/ioutil"
"log"
"time"