Skip to content

Instantly share code, notes, and snippets.

View anderson-marques's full-sized avatar
🤖
Hacking as usual...

Anderson Carvalho anderson-marques

🤖
Hacking as usual...
View GitHub Profile
@anderson-marques
anderson-marques / aws-s3-get-object-command-to-string.ts
Created April 27, 2021 16:18
AWS S3 SDK v3 - GetObjectCommandOutput - How to get the content from Readable
const input:GetObjectRequest = {
Bucket: this.eventsBucket,
Key: `${request.eventName}/${request.eventId}`
}
const command = new GetObjectCommand(input);
const output = await this.s3Client.send(command)
let outputBody: string = ''
for await (let chunk of output.Body as Readable) {
outputBody += chunk
import base64
encoded = base64.b64encode('data to be encoded')
print(encoded)
# prints 'ZGF0YSB0byBiZSBlbmNvZGVk'
data = base64.b64decode(encoded)
print(data)
# prints 'data to be encoded'
@anderson-marques
anderson-marques / gcp_create_access_token.js
Created April 19, 2021 13:59
Create GCP Access token for Service Accounts
const {google} = require('googleapis');
const main = async function() {
const auth = new google.auth.GoogleAuth({
keyFile: __dirname + '/service-account-key.json',
scopes: [ 'https://www.googleapis.com/auth/cloud-platform']
});
const accessToken = await auth.getAccessToken()
@anderson-marques
anderson-marques / http-benchmark.md
Created March 30, 2021 17:30 — forked from denji/http-benchmark.md
HTTP(S) Benchmark Tools / Toolkit for testing/debugging HTTP(S) and restAPI (RESTful)
@anderson-marques
anderson-marques / parse_dotenv.bash
Created March 18, 2021 11:50 — forked from judy2k/parse_dotenv.bash
Parse a .env (dotenv) file directly using BASH
# Pass the env-vars to MYCOMMAND
eval $(egrep -v '^#' .env | xargs) MYCOMMAND
# … or ...
# Export the vars in .env into your shell:
export $(egrep -v '^#' .env | xargs)
@anderson-marques
anderson-marques / k8s_force_namespace_deletion.sh
Created March 18, 2021 10:05
k8s_force_namespace_deletion.sh
NAMESPACE=apigee
kubectl proxy &
kubectl get namespace $NAMESPACE -o json |jq '.spec = {"finalizers":[]}' >temp.json
curl -k -H "Content-Type: application/json" -X PUT --data-binary @temp.json 127.0.0.1:8001/api/v1/namespaces/$NAMESPACE/finalize
@anderson-marques
anderson-marques / gcloud_service_account_print_access_token.py
Created March 12, 2021 20:13
gcloud_service_account_print_access_token
# Python script to programmatically generate the access token from a service-account key
# It does what the following commands does:
# - gcloud auth activate-service-account
# - gcloud auth print-access-token
import google.auth
import google.auth.transport.requests
from google.oauth2 import service_account
from os.path import expanduser
@anderson-marques
anderson-marques / oauth2_device_flow.py
Created March 11, 2021 17:42
oauth2_device_flow.py
"""
OAuth2 Device Flow adaptation from Implicit Flow - Useful for CLIs
"""
from http.server import SimpleHTTPRequestHandler, HTTPServer
import os
from os.path import expanduser
import json
callback_html = """
<body style="font-family: 'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif">
@anderson-marques
anderson-marques / tag_untagged_ecr_images.sh
Created February 22, 2021 17:07
TAG Untagged ECR Images
# This script tags a untagged ECR Images using its diggest
ECR_REPO=my-ecr-repo-name
IMAGE_DIGEST="sha256:ab6DSA4f1f940df430062009fdfb02d3ede74b48e39ada939047c2e7d0ee3ac50d8"
TAG=my-tag
# ---
MANIFEST=$(aws ecr batch-get-image --repository-name $ECR_REPO --image-ids imageDigest=$IMAGE_DIGEST --query 'images[].imageManifest' --output text)
aws ecr put-image --repository-name $ECR_REPO --image-tag $TAG --image-manifest "$MANIFEST"
@anderson-marques
anderson-marques / Makefile
Last active February 20, 2021 16:15
Dockerized .NET - Makefile
build-dev:
@docker build -f ./docker/dev/Dockerfile -t dockerized-dotnet:dev .
tag=1.0.0
build-prod:
@docker build -f ./docker/prod/Dockerfile -t dockerized-dotnet:${tag} .
@docker tag dockerized-dotnet:${tag} dockerized-dotnet:latest
console: build-dev
@docker run --rm -it dockerized-dotnet:dev sh