Skip to content

Instantly share code, notes, and snippets.

View rdsedmundo's full-sized avatar

Edmundo Santos rdsedmundo

  • Belo Horizonte, Brazil
View GitHub Profile
@rdsedmundo
rdsedmundo / console.sql
Created February 14, 2024 08:24
Datagrip bug
DROP TABLE IF EXISTS datagrip_bug;
CREATE TABLE datagrip_bug
(
id UUID PRIMARY KEY,
name TEXT NOT NULL,
created_at TIMESTAMPTZ
);
INSERT INTO datagrip_bug (id, name)
@rdsedmundo
rdsedmundo / cloudtrail.sh
Last active April 26, 2022 17:56
cloudtrail
# https://aws.amazon.com/premiumsupport/knowledge-center/troubleshoot-iam-permission-errors/
( echo "Time,Identity ARN,Event ID,Service,Action,Error,Message";
aws cloudtrail lookup-events --start-time "2020-01-01T00:00:00Z" --end-time "2020-01-01T23:59:59Z" --query "Events[*].CloudTrailEvent" --output text \
| jq -r ". | select(.userIdentity.arn == \"your-arn\" and .eventType == \"AwsApiCall\" and .errorCode != null
and (.errorCode | ascii_downcase | (contains(\"accessdenied\") or contains(\"unauthorized\"))))
| [.eventTime, .userIdentity.arn, .eventID, .eventSource, .eventName, .errorCode, .errorMessage] | @csv"
) | column -t -s'",'
@rdsedmundo
rdsedmundo / servicesPerAwsRegion.js
Created May 11, 2021 09:05
Compare services available on each AWS region
// https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services/
(() => {
const servicesAvailableOnRegion = (region) => Array.from(document.querySelectorAll(`[data-region="${region}"] [data-plc-offer-id]`)).map(node => node.querySelector('a').innerText);
const regions = Array.from(document.querySelectorAll('[data-region]')).map(node => node.getAttribute('data-region'));
const spr = regions.reduce((acc, region) => ({...acc, [region]: servicesAvailableOnRegion(region)}), {});
console.log(spr['us-east-1'].filter(service => !spr['us-east-2'].includes(service)));
})();
@rdsedmundo
rdsedmundo / collapse_pr.js
Last active June 12, 2022 02:19
Collapse all files in Pull Request review
document.querySelectorAll('.file-info > button:first-child[aria-expanded="true"]').forEach(node => node.click());
@rdsedmundo
rdsedmundo / gist:65c6ef2e75dfb01cebed806891623fa9
Created January 20, 2021 13:59
Get IAM permissions from CloudTrail logs
const _ = require('lodash');
const devHistory = require('../event_history_dev.json');
const prodHistory = require('../event_history_prod.json');
(async () => {
const events = [...devHistory.Records, ...prodHistory.Records];
const policiesByService = {};
for (const event of events) {
brew unlink yarn
brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/aacaa70e8931b2b005cb8f70703b48604f4a8d2a/Formula/yarn.rb
brew switch yarn 1.19.1
ssh -L 9200:url.com:443 -i ~/bastion.pem ec2-user@ip
@rdsedmundo
rdsedmundo / deleteAllLambdaLayers.ts
Created July 7, 2020 20:59
Deletes all lambda layers and their versions
import { Lambda } from 'aws-sdk';
const lambda = new Lambda({ region: 'us-east-1' });
async function run() {
const { Layers: layers } = await lambda.listLayers().promise();
if (!layers) {
console.log('No layers to delete.');
brew unlink yarn
brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/aacaa70e8931b2b005cb8f70703b48604f4a8d2a/Formula/yarn.rb
brew switch yarn 1.19.1
@rdsedmundo
rdsedmundo / queriesInFlight.js
Created September 20, 2019 15:21
Returns what queries are currently in-flight on your Apollo Client instance, globally.
function queriesInFlight() {
// client is your ApolloClient instance
const { queryManager } = client;
return Object.keys(queryManager.queryStore.getStore()).filter(queryId =>
queryManager.checkInFlight(queryId),
);
}