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 / 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 / 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()
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 / 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
kubectl get pods | grep Evicted | awk '{print $1}' | xargs kubectl delete pod
@anderson-marques
anderson-marques / s3-put-event.ts
Created May 25, 2021 22:59
S3 Put Event - TypeScript
export type S3PutEventEntry = {
eventVersion: string;
eventsource: string;
awsRegion: string;
eventTime: string;
eventName: string;
userIdentity: Record<string, unknown>;
requestParameters: Record<string, unknown>;
responseElements: Record<string, unknown>;
s3: {
@anderson-marques
anderson-marques / template.yaml
Created May 25, 2021 23:10
SAM Template using S3 Event Source - Hypothetical CustomerEventsProcessor
AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
Description: >
SAM Template - Example of S3 Event processing
Process related events: CustomerCreated, CustomerDeleted, CustomerUpdated
Parameter:
DataLakeBucket:
Type: String
Default: com-mycompany-datalake-bucket
import { SendWelcomeMessageInteractor } from "../marketing/control/send-welcome-message";
import { CustomerEventNames, CreateCustomerEvent } from "../customer/entity/customer-event";
import { S3PutEvent, S3PutEventEntry } from "../s3/entity/put-event-entry";
import { DataLakeGateway } from "../datalake/boundary/datalake-gateway";
const dataLakeGateway = DataLakeGateway.newInstance();
const sendWelcomeMessageInteractor = SendWelcomeMessageInteractor.newInstance();
const extractEventIdAndEventName = (
s3PutEventEntry: S3PutEventEntry
@anderson-marques
anderson-marques / gist:0a56ad8ad4872f0eda45d9686964794d
Created October 19, 2021 12:00
Podman run with read-only volume from the host
podman run --rm -it --env-file credentials.env -v /mnt$(pwd)/my-folder:/${WORKDIR}//my-folder/:Z ${PROJECT_NAME}:base sh
@anderson-marques
anderson-marques / iptables-ddns.sh
Created February 9, 2022 11:14 — forked from eusonlito/iptables-ddns.sh
Update iptables firewall with dynamic DNS updates from cron job
#!/bin/bash
# Set as cronjob
# * * * * * /root/scripts/iptables-ddns.sh >> /root/logs/iptables-ddns.log 2>&1
log () {
echo "[$(date "+%F +%T")] [$1] $2" >> "$LOGS/changes.log"
}
HOSTS="mydynamichost.ddns.net"