Skip to content

Instantly share code, notes, and snippets.

View NitriKx's full-sized avatar

Benoît Sauvère NitriKx

View GitHub Profile
@NitriKx
NitriKx / generate-aws-credential-file-based-iam-role
Last active December 21, 2015 07:28
[Old CLI Tool] Create an aws-credential-file based on EC2 instance role.
#!/bin/bash
ROLE=`curl http://169.254.169.254/latest/meta-data/iam/security-credentials/`
JSON=`curl http://169.254.169.254/latest/meta-data/iam/security-credentials/${ROLE}`
AWS_ACCESS_KEY=`echo ${JSON} | sed 's/\\\\\//\//g' | sed 's/[{}]//g' | awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' | sed 's/\"\:\"/\|/g' | sed 's/[\,]/ /g' | sed 's/\"//g' | grep -w 'AccessKeyId' | cut -d":" -f2| sed -e 's/^ *//g' -e 's/ *$//g'`
AWS_SECRET_KEY=`echo ${JSON} | sed 's/\\\\\//\//g' | sed 's/[{}]//g' | awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' | sed 's/\"\:\"/\|/g' | sed 's/[\,]/ /g' | sed 's/\"//g' | grep -w 'SecretAccessKey' | cut -d":" -f2| sed -e 's/^ *//g' -e 's/ *$//g'`
echo "AWSAccessKeyId=${AWS_ACCESS_KEY}" > /tmp/aws_credentials
echo "AWSSecretKey=${AWS_SECRET_KEY}" >> /tmp/aws_credentials
@NitriKx
NitriKx / generate-aws-credential-file-based-iam-role-new-aws-cli-tool
Last active December 21, 2015 07:29
[New AWS CLI Tool] Create an aws-credential-file based on EC2 instance role.
#!/bin/bash
ROLE=`curl http://169.254.169.254/latest/meta-data/iam/security-credentials/`
JSON=`curl http://169.254.169.254/latest/meta-data/iam/security-credentials/${ROLE}`
# Get access keys
AWS_ACCESS_KEY=`echo ${JSON} | sed 's/\\\\\//\//g' | sed 's/[{}]//g' | awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' | sed 's/\"\:\"/\|/g' | sed 's/[\,]/ /g' | sed 's/\"//g' | grep -w 'AccessKeyId' | cut -d":" -f2| sed -e 's/^ *//g' -e 's/ *$//g'`
AWS_SECRET_KEY=`echo ${JSON} | sed 's/\\\\\//\//g' | sed 's/[{}]//g' | awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' | sed 's/\"\:\"/\|/g' | sed 's/[\,]/ /g' | sed 's/\"//g' | grep -w 'SecretAccessKey' | cut -d":" -f2| sed -e 's/^ *//g' -e 's/ *$//g'`
SECURITY_TOKEN=`echo ${JSON} | sed 's/\\\\\//\//g' | sed 's/[{}]//g' | awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' | sed 's/\"\:\"/\|/g' | sed 's/[\,]/ /g' | sed 's/\"//g' | grep -w 'Token' | cut -d":" -f2| sed -e 's/^ *//g' -e 's/ *$//g'`
# Get insta
@NitriKx
NitriKx / generate-aws-credential-file-based-iam-role-new-aws-cli-tool-security-token
Last active December 21, 2015 07:29
[New AWS CLI Tool] Create an aws-credential-file based on EC2 instance role using security token.
#!/bin/bash
ROLE=`curl http://169.254.169.254/latest/meta-data/iam/security-credentials/`
JSON=`curl http://169.254.169.254/latest/meta-data/iam/security-credentials/${ROLE}`
TOKEN=`echo ${JSON} | sed 's/\\\\\//\//g' | sed 's/[{}]//g' | awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' | sed 's/\"\:\"/\|/g' | sed 's/[\,]/ /g' | sed 's/\"//g' | grep -w 'Token' | cut -d":" -f2| sed -e 's/^ *//g' -e 's/ *$//g'`
# Get instance region and make it the default endpoint
EC2_AVAIL_ZONE=`curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone`
AWS_INSTANCE_REGION="`echo \"$EC2_AVAIL_ZONE\" | sed -e 's:\([0-9][0-9]*\)[a-z]*\$:\\1:'`"
@NitriKx
NitriKx / AppengineLogAppender
Created August 6, 2014 14:58
Logback logs converter into GAE log (which uses JUL)
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger;
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.spi.IThrowableProxy;
import ch.qos.logback.classic.spi.LoggingEvent;
import ch.qos.logback.classic.spi.StackTraceElementProxy;
import ch.qos.logback.core.AppenderBase;
@NitriKx
NitriKx / gist:273b5fa97ef3efd8d757
Created September 1, 2014 17:18
[BASH 4.0] - Compute AWS S3 Data Transfert Out parsing S3 Logging files
# The key of the map is the first folder name
PATTERN=".*/mybucket/([^/]+)/.*200 - ([0-9]+) .*"
unset costMap
# Requires Bash 4.0
declare -A costMap
for file in $(ls .); do
@NitriKx
NitriKx / IAWS-Projet-Jersey-Exception-Logger-SLF4J
Last active August 29, 2015 14:17
Classe permettant de logger les exception survenues dans Jersey à travers SLF4J
package iaws.tblabsauzzya.ugmont;
import org.glassfish.grizzly.utils.Exceptions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
@NitriKx
NitriKx / IAWS-Projet-Jersey-Exception-Logger-Stdout
Last active August 29, 2015 14:17
Classe permettant de logger les exception survenues dans Jersey dans la sortie standard
package iaws.tblabsauzzya.ugmont;
import org.glassfish.grizzly.utils.Exceptions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
@NitriKx
NitriKx / delete-detached-disks.sh
Created June 24, 2015 07:46
[Google Compute Engine] - Delete all the detached disks
gcloud compute disks delete $(gcloud compute disks list --format json | jq '.[] | select (has("users") | not) | .name' -r)
@NitriKx
NitriKx / gist:6fc97b7111aeecf0d7ec
Created January 21, 2016 15:35
[M2DL/TER] Coordonnées des zones/points de recyclage sur le site de Paul Sabatier
Verre
new LatLng(43.55891,1.47303);
new LatLng(43.55999,1.47194);
new LatLng(43.55995,1.47195);
new LatLng(43.56439,1.47053);
new LatLng(43.56355,1.47579);
new LatLng(43.55509,1.46816);
new LatLng(43.56295,1.46311);
new LatLng(43.56305,1.45939);
@NitriKx
NitriKx / instruction-remote-cloudmip.md
Last active May 12, 2016 17:18
Instructions pour utilisé l'API OpenStack de Cloudmip depuis l'extérieur de l'Université

OSX/Linux seulement (ça doit pouvoir se faire avec Putty sur Wind0ws mais je l'ai pas sous la main)

Editez votre fichier host pour rajouter la ligne suivante (ne pas oublier de faire sudo). Si votre fichier host contient déjà frontal commentez cette ligne.

frontal    127.0.0.1

Lancer la commande suivante dans le terminal en replaçant "ens24" par votre identifiant (et entrer le mot de passe)