Skip to content

Instantly share code, notes, and snippets.

@awsiv
awsiv / aws-az-map.sh
Last active Oct 9, 2020
Map AWS availability zones
View aws-az-map.sh
#!/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 Aug 27, 2020
Find AWS Target Groups without any registered instances
View findEmptyTargetGroups.sh
#!/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 Feb 12, 2020
SQL queries
View queries.sql
--- 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 Mar 15, 2012
Remove data older than a certain time period from an array
View remove_old_data.c
//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 Mar 14, 2012
Compression by timestamp
View compressed.c
//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;