Skip to content

Instantly share code, notes, and snippets.

@pcolazurdo
pcolazurdo / GOLANG-modules.md
Last active April 4, 2022 17:12
Interesting GOLANG resources

Userful Libraries/modules

  1. OpenAPI toolkit common string formats: github.com/go-openapi/strfmt
  2. Seamless printing to the terminal (stdout) and logging to a io.Writer (file) that’s as easy to use as fmt.Println: https://github.com/spf13/jwalterweatherman
  3. Go package for dealing with maps, slices, JSON and other data: https://github.com/stretchr/objx
  4. Efficient JSON beautifier and compactor for Go: https://github.com/tidwall/pretty
  5. bbolt is a fork of Ben Johnson's Bolt key/value store: https://pkg.go.dev/go.etcd.io/bbolt
  6. Formatters for units to human friendly sizes: github.com/dustin/go-humanize
  7. Package httpsnoop provides an easy way to capture http related metrics (i.e. response time, bytes written, and http status code) from your application's http.Handlers: https://github.com/felixge/httpsnoop
  8. Staticcheck - The advanced Go linter: https://github.com/dominikh/go-tools
@pcolazurdo
pcolazurdo / clean_up_unused_policies.sh
Created March 11, 2022 15:50
#CAUTION: This will help you to delete all AWS IAM Policies that aren't attached to any resource Role. Treat carefully
#!/bin/bash
TEMP_DIR=$(mktemp -d)
echo Output Directory: ${TEMP_DIR}
confirm() {
#
# syntax: confirm [<prompt>]
#
# Prompts the user to enter Yes or No and returns 0/1.
@pcolazurdo
pcolazurdo / observe.js
Created February 7, 2022 18:00
Browser: Observe events when an element is visible in the screen
var observer = new IntersectionObserver(function (entries) {
// isIntersecting is true when element and viewport are overlapping
// isIntersecting is false when element and viewport don't overlap
if (entries[0].isIntersecting === true)
console.log(entries[0].target.id);
}, { threshold: [0] });
// Observe all H2 headings and get their id printed into the console whenever they are in focus
document.querySelectorAll("h2").forEach(function (item) {
observer.observe(document.querySelector("#" + item.id));
@pcolazurdo
pcolazurdo / list_all_resources.sh
Created October 5, 2021 21:31
CloudControl for the win
# very basic but you can see the gist of it:
aws cloudformation list-types --type RESOURCE --visibility PUBLIC | \
jq '.TypeSummaries[].TypeName' | \
cut -d\" -f2 | \
while read a
do
aws cloudcontrol list-resources --type-name $a 2>/dev/null| \
jq '.ResourceDescriptions[].Identifier'
done
@pcolazurdo
pcolazurdo / main-instrumented.go
Last active August 24, 2021 16:04
AWS_SDK_BUGREPORT1
// This sample code triggers the problem if run against a large directory structure (+50K objects)
// I added some instrumention to check how many connections were being resued versus created new
// Please change the table name in line 283 and path in line 286
package main
import (
"context"
"crypto/md5"
"strings"
@pcolazurdo
pcolazurdo / README.md
Created July 2, 2021 12:44
AWS SHD parsing

Download the file from

wget https://status.aws.amazon.com/data.json

basic parsing

jq -r '(.archive[] | 
       (.date| tonumber | todate) as $D | 
       select($D | startswith("2021"))| 
 [.service_name, $D[0:10] ,.service,.summary]) | @csv ' \
@pcolazurdo
pcolazurdo / find_chome_dependency.sh
Created May 14, 2021 11:22
How to get list of libraries to fulfil dependency requirements
ldd /var/task/node_modules/puppeteer/.local-chromium/linux-869685/chrome-linux/chrome | grep not | \
cut -d= -f1 | while read a
do
yum provides $a | head -2 | tail -1 | cut -d\ -f1
done
@pcolazurdo
pcolazurdo / Dockerfile.18.04
Last active April 19, 2021 11:26
Building ingraind in AL2
FROM ubuntu:18.04
ARG openssl_arch=linux-x86_64
ENV RUSTUP_HOME=/usr/local/rustup \
CARGO_HOME=/usr/local/cargo \
PATH=/usr/local/cargo/bin:$PATH \
DEBIAN_FRONTEND=noninteractive
RUN apt-get update \
&& apt-get -y install curl wget lsb-release wget software-properties-common \
@pcolazurdo
pcolazurdo / cwagent-otel-collector.yaml
Last active March 28, 2021 22:12
OpenTelemetry Playground
# Config file to add a Prometheus receiver - not fully as I can't make it scrape another process yet
extensions:
health_check:
receivers:
prometheus:
config:
scrape_configs:
- job_name: "otel-collector"
scrape_interval: 5s