Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
MYDNS="8.8.8.8"
DATE=$(date '+%Y-%m-%d')
UBUNTU1_URL="http://cloud-images.ubuntu.com/xenial/current/xenial-server-cloudimg-amd64-disk1.img"
UBUNTU2_URL="http://cloud-images.ubuntu.com/bionic/current/bionic-server-cloudimg-amd64.img"
CIRROS_URL="http://download.cirros-cloud.net/0.4.0/cirros-0.4.0-x86_64-disk.img"
CENTOS_URL="http://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud.qcow2c"
VOLUME_SIZE=10
NEW_VOLUME_SIZE=15
VOLUME_NAME=$(cat /proc/sys/kernel/random/uuid)
@JamesOBenson
JamesOBenson / beautiful_idiomatic_python.md
Created February 1, 2019 22:16 — forked from 0x4D31/beautiful_idiomatic_python.md
Transforming Code into Beautiful, Idiomatic Python: notes from Raymond Hettinger's talk at pycon US 2013. The code examples and direct quotes are all from Raymond's talk. I've reproduced them here for my own edification and the hopes that others will find them as handy as I have!

Transforming Code into Beautiful, Idiomatic Python

Notes from Raymond Hettinger's talk at pycon US 2013 video, slides.

The code examples and direct quotes are all from Raymond's talk. I've reproduced them here for my own edification and the hopes that others will find them as handy as I have!

Looping over a range of numbers

for i in [0, 1, 2, 3, 4, 5]:
__author__ = 'Cody Giles'
__license__ = "Creative Commons Attribution-ShareAlike 3.0 Unported License"
__version__ = "1.0"
__maintainer__ = "Cody Giles"
__status__ = "Production"
import subprocess
import smtplib
from email.mime.text import MIMEText
import datetime
# Python's list comprehensions are awesome.
vals = [expression
for value in collection
if condition]
# This is equivalent to:
vals = []
for value in collection:
@JamesOBenson
JamesOBenson / greengrass_group_create.py
Created June 29, 2018 21:09 — forked from dzimine/greengrass_group_create.py
Create AWS Greengrass group and core.
import json
import yaml
import boto3
gg = boto3.client('greengrass')
iot = boto3.client('iot')
group = gg.create_group(Name="my_group")
keys_cert = iot.create_keys_and_certificate(setAsActive=True)
Input math equation and round to 3 decimals:
printf %.3f $(echo "$exp" | bc -l)
Comparing 3 numbers to find equals/differences:
read x
read y
read z
if [[ "$x" -eq "$y" ]] && [[ "$x" -eq "$z" ]] ; then echo EQUILATERAL
elif [[ "$x" -eq "$y" ]] || [[ "$x" -eq "$z" ]] || [[ "$y" -eq "$z" ]] ; then echo ISOSCELES
else echo SCALENE
@JamesOBenson
JamesOBenson / create_openstack_user.sh
Last active March 25, 2021 12:26
Create openstack project/user/networking & update security rules (python-openstackclient & openssl are the only requirement ); Verified all commands work properly & as intended.
#!/bin/bash
# This script creates all necessary components to start booting VM's in openstack. This includes
# - Project
# - User
# - Networking, subnets, router,
# Security group allows
# - 22 (SSH)
# - IMPI (Ping test)
# - 8443 & 8883 (Greengrass rules)
@JamesOBenson
JamesOBenson / backup.sh
Created December 1, 2017 21:38
This will look at openstack active instances, report a list and ask you if you want to download. After 10 seconds, it continues the download.
#!/bin/bash
source openrc
timeout=10
# pip install python-openstackclient
# pip install python-novaclient
# pip install python-glanceclient
# This script will create and download all available images in an openstack cluster under a specific username.
# This script has been tested against shellcheck and verified to the best of my abilities to work under any version of shell.
# To deploy in Openstack ubuntu server LTS instance:
sudo apt-add-repository ppa:ubuntu-lxc/stable -y
# Using the backports will be supported after the end of 2017, snap is still being developed. As of Nov 28, 2017, backports and regular install are the same.
sudo apt update && sudo apt install -y -t xenial-backports lxd lxd-client
#sudo apt update && sudo apt install -y lxd lxd-client
lxd init --auto
# MTU of 1450 is needed for openstack VM.
lxc network create lxdbr0 ipv4.address=auto ipv4.nat=true ipv6.address=none ipv6.nat=false bridge.mtu=1450
#!/bin/sh
# USE ON MASTER NODE as UBUNTU/root:
export MASTER1="r2-710-01"
export MASTER2="r2-710-03"
export MASTER3="r2-710-05"
export CLIENT_NODES="r2-710-07 r2-710-09 r2-710-11 r2-710-13"
export ALL_NODES="r2-710-01 r2-710-03 r2-710-05 r2-710-07 r2-710-09 r2-710-11 r2-710-13"