Skip to content

Instantly share code, notes, and snippets.

View MatteoGioioso's full-sized avatar
🍕
Pizza

Matteo Gioioso MatteoGioioso

🍕
Pizza
View GitHub Profile
@MatteoGioioso
MatteoGioioso / debuggo.Dockerfile
Last active September 8, 2021 03:16
Example Dockerfile for debugging golang application inside docker container
FROM public.ecr.aws/bitnami/golang:1.15 AS build-env
RUN go get github.com/go-delve/delve/cmd/dlv
# Copy the files here, be sure to include the go.mod file.
WORKDIR /app
RUN go build -gcflags="all=-N -l" -o /server
FROM debian:buster
@MatteoGioioso
MatteoGioioso / source-aws-sso-credentials.sh
Last active April 16, 2023 05:57
Export AWS SSO credentials
#!/bin/bash
echo "unsetting previous aws credentials..."
unset AWS_ACCESS_KEY_ID
unset AWS_SECRET_ACCESS_KEY
unset AWS_SESSION_TOKEN
aws sso login &&
aws sts get-caller-identity > /dev/null && # this refresh the cache
echo "sourcing aws credentials"
@MatteoGioioso
MatteoGioioso / source-aws-credentials.sh
Created August 26, 2021 04:51
Source aws credentials, this could be useful for using AWS in a container
#!/usr/bin/env sh
AWS_PROFILE="${AWS_PROFILE:-default}"
export AWS_ACCESS_KEY_ID=$(sed -nr "/^\[${AWS_PROFILE}\]/ { :l /^aws_access_key_id[ ]*=/ { s/.*=[ ]*//; p; q;}; n; b l;}" "$HOME"/.aws/credentials)
export AWS_SECRET_ACCESS_KEY=$(sed -nr "/^\[${AWS_PROFILE}\]/ { :l /^aws_secret_access_key[ ]*=/ { s/.*=[ ]*//; p; q;}; n; b l;}" "$HOME"/.aws/credentials)
docker volume rm $(docker volume ls -qf dangling=true);
docker volume ls -qf dangling=true | xargs -r docker volume rm;
docker rmi $(docker images --filter "dangling=true" -q --no-trunc);
docker rmi $(docker images | grep "none" | awk '/ / { print $3 }'); # docker rmi $(docker images | tr -s ' ' | cut -d ' ' -f 3)
docker rm $(docker ps -qa --no-trunc --filter "status=exited");
@MatteoGioioso
MatteoGioioso / ErrorBoundary.js
Created February 3, 2020 01:16
React error boundary component with Sentry integration
import React from "react";
import * as Sentry from "@sentry/browser";
Sentry.init({
dsn: process.env.REACT_APP_SENTRY_DNS
});
export default class ErrorBoundary extends React.Component {
state = {
hasError: false,
@MatteoGioioso
MatteoGioioso / accessControl.js
Created December 25, 2019 10:07
Access control component for Reactjs
import { connect } from "react-redux";
/**
* Insert here all the roles
*/
const roles = loggedUserId => ({
rootAccount: {
static: ["profile:create", "profile:read", "profile:update"],
dynamic: {
"profile:delete": ownerId => !Boolean(ownerId)
@MatteoGioioso
MatteoGioioso / fetchAmplifyAuthHttpclient.ts
Last active December 8, 2019 02:17
Small fetch typescript wrapper with Amplify authentication
import { Auth, AuthClass } from "aws-amplify";
export interface IOptions extends RequestInit {}
export interface IHttpClient {
request(url: string, options: IOptions): Promise<any>;
authenticatedRequest(url: string, options: IOptions): Promise<any>;
}
export class HttpClient implements IHttpClient {
#!/bin/bash
CONTAINER_NAME=stepfunctions
STATE_MACHINE_DEFINITION=/path/to/yourstatemachine.json
STATE_MACHINE_NAME="Name of your process"
ENV_FILE=path/to/your-stepfunctions-local-credentials.txt
INPUT="{ \"myInput\": \"hello world\"}"
function get_value_from_json(){
VALUE="$(jq .$1 temporary.json)"
@MatteoGioioso
MatteoGioioso / groupArrayByKey.js
Last active August 2, 2019 02:30
How to group an array by key in javascript in a functional style
/**
* groupArrayByKey
* @param array
* @param {function(object):number | string} keyExtractorCallback - function to calculate the key
* @returns {*}
*/
export const groupArrayByKey = (array, keyExtractorCallback) =>
array.reduce((accumulator, item) => {
const key = keyExtractorCallback(item);
accumulator[key] = (accumulator[key] || []).concat(item);
@MatteoGioioso
MatteoGioioso / prepare-commit-msg.sh
Created July 22, 2019 06:49
How to automatically prepend git commit with a branch number tag
#!/bin/bash
#Does not work if executed as sh
#Copy this commit script into prepare-commit-msg
BRANCH_NAME=$(git branch 2>/dev/null | grep -e ^* | tr -d ' *')
IFS='-' read -r -a array <<< "$BRANCH_NAME"
if [ -n "$BRANCH_NAME" ]; then
echo " (#$array) $(cat $1)" > $1
fi