Skip to content

Instantly share code, notes, and snippets.

@lukeplausin
lukeplausin / bash_aws_jq_cheatsheet.sh
Last active July 15, 2024 09:10
AWS, JQ and bash command cheat sheet. How to query, cut and munge things in JSON generally.
# Count total EBS based storage in AWS
aws ec2 describe-volumes | jq "[.Volumes[].Size] | add"
# Count total EBS storage with a tag filter
aws ec2 describe-volumes --filters "Name=tag:Name,Values=CloudEndure Volume qjenc" | jq "[.Volumes[].Size] | add"
# Describe instances concisely
aws ec2 describe-instances | jq '[.Reservations | .[] | .Instances | .[] | {InstanceId: .InstanceId, State: .State, SubnetId: .SubnetId, VpcId: .VpcId, Name: (.Tags[]|select(.Key=="Name")|.Value)}]'
# Wait until $instance_id is running and then immediately stop it again
aws ec2 wait instance-running --instance-id $instance_id && aws ec2 stop-instances --instance-id $instance_id
# Get 10th instance in the account
@olih
olih / jq-cheetsheet.md
Last active July 16, 2024 23:02
jq Cheet Sheet

Processing JSON using jq

jq is useful to slice, filter, map and transform structured json data.

Installing jq

On Mac OS

brew install jq

@ndavison
ndavison / socket-https-client.py
Created November 19, 2014 10:03
Python socket HTTPS client connection example
#!/bin/env python
"""
A simple example of using Python sockets for a client HTTPS connection.
"""
import ssl
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('github.com', 443))
@sloria
sloria / bobp-python.md
Last active July 24, 2024 02:53
A "Best of the Best Practices" (BOBP) guide to developing in Python.

The Best of the Best Practices (BOBP) Guide for Python

A "Best of the Best Practices" (BOBP) guide to developing in Python.

In General

Values

  • "Build tools for others that you want to be built for you." - Kenneth Reitz
  • "Simplicity is alway better than functionality." - Pieter Hintjens
@antonj
antonj / aj-toggle-fold.el
Created March 17, 2011 10:17
Emacs command to toggle folding of all lines with indentation larger than that on the current line.
(defun aj-toggle-fold ()
"Toggle fold all lines larger than indentation on current line"
(interactive)
(let ((col 1))
(save-excursion
(back-to-indentation)
(setq col (+ 1 (current-column)))
(set-selective-display
(if selective-display nil (or col 1))))))
(global-set-key [(M C i)] 'aj-toggle-fold)