Skip to content

Instantly share code, notes, and snippets.

View bosgood's full-sized avatar

Brad Osgood bosgood

View GitHub Profile
@bosgood
bosgood / hash.py
Last active June 23, 2017 20:31
Create password hash for use with Ansible:user
# Borrowed from
# https://stackoverflow.com/a/17992126/573791
# import the hash algorithm
from passlib.hash import sha512_crypt
# generate new salt, and hash a password
hash = sha512_crypt.encrypt("password")
hash
@bosgood
bosgood / command.sh
Created June 23, 2017 18:54
Find all instances using security groups
# Append another grep to find a specific security group
aws ec2 describe-instances --output text | grep sg-
@bosgood
bosgood / termination-check.sh
Last active June 9, 2017 15:27
AWS spot instance termination check
#!/bin/bash
# Borrowed from: AWS re:Invent 2015 | (CMP311) This One Weird API Request Will Save You Thousands
# https://www.youtube.com/watch?v=_6bgSDZeLAw
while true
do
if curl -s http://169.254.169.254/latest/meta-data/spot/termination-time | grep -q .*T.*Z; then
/env/bin/runterminationscripts.sh
else
@bosgood
bosgood / mark-instance-unhealthy.sh
Last active May 10, 2017 22:01
Mark ASG instance unhealthy
aws autoscaling set-instance-health --instance-id="$(curl http://169.254.169.254/latest/meta-data/instance-id)" --health-status="Unhealthy"
@bosgood
bosgood / graphql_nullable_string_field.go
Created March 29, 2017 02:42
graphql-go nullable string field
// In your database/models:
type User struct {
Name sql.NullString // Or any other maybe/option/nullable type
}
// In your graphql schema, use this helper to define a nullable string field:
func resolveNullableString(p graphql.ResolveParams) (interface{}, error) {
v := reflect.ValueOf(p.Source).Elem()
if !v.IsValid() {
return nil, fmt.Errorf("Invalid elem: %v", p.Source)
@bosgood
bosgood / iam-policy-data.tf
Created January 19, 2017 15:58
Terraform tricks
# Useful sometimes: Use a data item instead of a JSON literal to represent IAM policy
data "aws_iam_policy_document" "instance-assume-role-policy" {
statement {
actions = [ "sts:AssumeRole" ]
principals {
type = "Service"
identifiers = ["ec2.amazonaws.com"]
}
}
@bosgood
bosgood / awscli-ec2.sh
Last active January 17, 2017 22:15
awscli favorites
# List running instances
aws ec2 describe-instances --filters "Name=instance-state-name,Values=running" --output="table" --query="Reservations[*].Instances[*].{Dns:PublicDnsName,Type:InstanceType}"
@bosgood
bosgood / gist:1fce8bdc2f53a616eaa5bab635a73446
Created January 5, 2017 20:31 — forked from eduardocardoso/gist:82a629882ddb02ab3677
Script to delete exited containers and untagged/unused images from docker
#!/bin/bash
set -o errexit
echo "Removing exited docker containers..."
docker ps -a -f status=exited -q | xargs -r docker rm -v
echo "Removing dangling images..."
docker images --no-trunc -q -f dangling=true | xargs -r docker rmi
@bosgood
bosgood / document.md
Last active November 21, 2016 03:06
The Erotic Ontology of Cyberspace by Michael Heim
                  The Erotic Ontology of Cyberspace

                            Michael Heim

This is a chapter from Michael Heim's book The Metaphysics of Virtual Reality (New York: Oxford University Press, 1993: 82-108).

Cyberspace is more than a breakthrough in electronic media or in computer interface design. With its virtual environments and simulated worlds,

@bosgood
bosgood / mongo-shell.js
Created September 21, 2016 18:35
Create mongo unique index on collection with duplicates
var collectionName = "<your collection name here>";
var field = "<your unique column name here>";
// Part 1
var indexObj = {}; indexObj[field] = 1;
db[collectionName].count()
db[collectionName].createIndex(indexObj, { unique: true })
// If this doesn't fail, you're done!