Skip to content

Instantly share code, notes, and snippets.

@awsiv
awsiv / aws-az-map.sh
Last active October 9, 2020 12:14
Map AWS availability zones
#!/bin/bash
if [ $# != 1 ]; then
echo "Usage: AWS_PROFILE=<aws-profile> ./$0 <region>"
exit 1
fi
aws ec2 describe-availability-zones --region "$1" | jq -r '.AvailabilityZones[] | .ZoneId + "=" + .ZoneName'
@awsiv
awsiv / findEmptyTargetGroups.sh
Created August 27, 2020 16:13
Find AWS Target Groups without any registered instances
#!/bin/bash
for i in $(aws elbv2 describe-load-balancers --query 'LoadBalancers[*].LoadBalancerArn'| jq -r '.[]'); do
tgCount=$(aws elbv2 describe-target-groups --load-balancer-arn "$i" --query 'TargetGroups[*].TargetGroupArn' | jq -r '.[]'|wc -l)
if [ "$tgCount" -eq 0 ]; then
echo "No TG registered on LB: $i"
else
for t in $(aws elbv2 describe-target-groups --load-balancer-arn "$i" --query 'TargetGroups[*].TargetGroupArn' | jq -r '.[]'); do
instanceCount=$(aws elbv2 describe-target-health --target-group-arn "$t" --query 'TargetHealthDescriptions[*].[Target.Id,TargetHealth.State]' | jq -r '.[]' | wc -l)
if [ "$instanceCount" -eq 0 ]; then
@awsiv
awsiv / queries.sql
Last active February 12, 2020 16:04
SQL queries
--- select indexes
SELECT tablename, indexname, indexdef FROM pg_indexes WHERE schemaname = 'public' ORDER BY tablename, indexname;
--- list functions
\df public.*
--- list lastvalue
SELECT MAX(id) FROM <table name>;
@awsiv
awsiv / remove_old_data.c
Created March 15, 2012 01:00
Remove data older than a certain time period from an array
//gcc -static -std=c99 -Wall remove_old_data.c -I./src -L. -lbson -lmongoc -o remove_old_data
/* remove_old_data.c */
#include "bson.h"
#include "mongo.h"
int main() {
bson_buffer bb;
bson cond;
@awsiv
awsiv / compressed.c
Created March 14, 2012 17:33
Compression by timestamp
//scons
//gcc -static -std=c99 -Wall compressed_data.c -I./src -L. -lbson -lmongoc -o compressed_data
/* compressed_promiselog.c */
#include "bson.h"
#include "mongo.h"
int main() {
bson b, key, setOp;
bson_buffer bb;