Skip to content

Instantly share code, notes, and snippets.

View seventhskye's full-sized avatar

Seventh Skye Limited seventhskye

View GitHub Profile
@seventhskye
seventhskye / mnist_softmax.py
Last active August 19, 2016 17:21
The beginners tutorial mnist-softmax script, from the TensorFlow website. https://www.tensorflow.org/versions/r0.10/tutorials/mnist/beginners/index.html#softmax-regressions
# https://www.tensorflow.org/versions/r0.10/tutorials/mnist/beginners/index.html#softmax-regressions
# download and read in the data automatically:
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)
import tensorflow as tf
# model for handwritten digit [0-9]
# y = softmax(Wx + b)
@seventhskye
seventhskye / master_and_slave
Created August 4, 2016 14:51
A script to detect all the instances in an autoscaling group and assign one as the master.
#!/usr/bin/env python
import sys
import boto3
def main(argv):
autoscaling = boto3.client('autoscaling')
auto_scaling_groups = autoscaling.describe_auto_scaling_groups()['AutoScalingGroups']
for asg in auto_scaling_groups:
break
@seventhskye
seventhskye / sse_policy.json
Created August 1, 2016 10:30
Policy to require Server side encrpytion on access to an s3 bucket.
{
"Version": "2012-10-17",
"Id": "Policy1469359009696",
"Statement": [
{
"Sid": "Stmt1469359007124",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:*",
"Resource": "arn:aws:s3:::<BUCKET_NAME>/*",
@seventhskye
seventhskye / create_image.sh
Created July 27, 2016 10:43
Creates an Amazon Machine Image.
#!/bin/bash
aws ec2 create-image --instance-id $(curl -s http://169.254.169.254/latest/meta-data/instance-id) --name image-$(date +'%s')
@seventhskye
seventhskye / lights_on.sh
Last active July 23, 2016 05:37
A script to collect InstanceIds from AWS by a tag: ScheduledUptime in this case. The list can then be used for other tasks such as shutting down instances.
#!/bin/bash
# The TAG_KEY and TAG_VALUE environment variables
# can be set before running the script otherwise the
# default are used.
IDS`aws ec2 describe-instances \
--filter "Name=tag:${TAG_KEY:-ScheduledUptime},Values=${TAG_VALUE:-True}" \
--query 'Reservations[*].Instances[*].[InstanceId]' \
--output text`
@seventhskye
seventhskye / lights_out.sh
Last active July 23, 2016 05:37
A script to turn all instances off.
#!/bin/bash
# The TAG_KEY and TAG_VALUE environment variables
# can be set before running the script otherwise the
# default are used.
IDS`aws ec2 describe-instances \
--filter "Name=tag:${TAG_KEY:-ScheduledUptime},Values=${TAG_VALUE:-True}" \
--query 'Reservations[*].Instances[*].[InstanceId]' \
--output text`
@seventhskye
seventhskye / aws_s3_backup
Created June 7, 2016 12:34
Script to upload or download a current working directory to an s3 bucket. Script assumes that the present working directory will be the name of the s3 directory
#!/bin/bash
if [ $# -eq 0 ]; then
echo "Usage: $@ upload|download"
if [ "$BUCKET_NAME" == "" ]; then
echo "variable \$BUCKET_NAME name must be set."
fi
else
DIR=`basename ${PWD}`
aws configure --profile cloud-backup
@seventhskye
seventhskye / clean_docker
Last active May 26, 2016 10:32
Removes all docker images and containers.
#!/bin/bash
# Stop all containers
docker kill $(docker ps -a -q)
# Delete all containers
docker rm $(docker ps -a -q)
# Delete all images
docker rmi $(docker images -q)
@seventhskye
seventhskye / Makedocker
Last active May 25, 2016 13:26
A Makefile for docker images.
DATE = $(shell date)
NAME = dcrbsltd/image
VERSION = 1
all: build
build:
docker build -t $(NAME):$(VERSION) --rm .
tag_latest:
@seventhskye
seventhskye / get_url.sh
Last active March 11, 2016 04:45
A bash while loop to get a URL from $PROTOCOL, $HOST and $DNS_DOMAIN environment variables.
#!/bin/bash
DNS_DOMAIN=${DNS_DOMAIN:-example.com}
HOST=${HOST:-www}
HOSTNAME=$HOST.$DNS_DOMAIN
PROTOCOL=${PROTOCOL:-https}
URL=$PROTOCOL://$HOSTNAME
echo " --> Testing for $URL"
# Number of requests
TIMEOUT=30
# Time to wait between requests