Skip to content

Instantly share code, notes, and snippets.

@fitzgeraldsteele
fitzgeraldsteele / net-promoter-score.py
Created November 7, 2013 21:13
A little python function to calculate the net promoter score from a list of ratings. Also wanted to practice doctests.
#!/usr/bin/env python
import sys
def netpromoterscore(scores):
"""
Calculates the netpromoter score of a list
The Net Promoter Score is obtained by asking customers a single question on a 0 to 10 rating scale:
'How likely is it that you would recommend our company to a friend or colleague?'
Based on their responses, customers are categorized into one of three groups:
Promoters (9-10 rating), Passives (7-8 rating), and Detractors (0-6 rating).
@fitzgeraldsteele
fitzgeraldsteele / vmss-flex-spot-create.py
Created February 6, 2024 06:41
Create VMSS Flex with Spot Instances sample
# Import the needed credential and management objects from the libraries.
from azure.identity import AzureCliCredential
from azure.mgmt.resource import ResourceManagementClient
from azure.mgmt.network import NetworkManagementClient
from azure.mgmt.compute import ComputeManagementClient
from azure.mgmt.compute.models import OrchestrationMode
import os
print(f"Provisioning a virtual machine scale set...some operations might take a minute or two.")
@fitzgeraldsteele
fitzgeraldsteele / simpleVMSSApplicationHealth.yaml
Last active July 21, 2023 20:02
Simple cloud init for application health
#cloud-config
package_upgrade: true
packages:
- nginx
write_files:
- path: /var/www/html/index.html
content: |
<!DOCTYPE html>
version: '3.4'
services:
yarpreverseproxy:
image: vmssapplicationhealth.azurecr.io/yarpreverseproxy:ds1
container_name: yarpreverseproxy
ports:
- 80:7176
links:
@fitzgeraldsteele
fitzgeraldsteele / azure-metadata-cloud-init.yml
Last active June 30, 2021 17:31
cloud-init for Azure Metadata service
#cloud-config
package_upgrade: true
packages:
- nginx
- nodejs
- npm
write_files:
- owner: www-data:www-data
path: /etc/nginx/sites-available/default
content: |
#cloud-config
package_upgrade: true
packages:
- nginx
- nodejs
- npm
write_files:
- owner: www-data:www-data
path: /etc/nginx/sites-available/default
content: |
@fitzgeraldsteele
fitzgeraldsteele / getUnhealthyInstances.ps1
Created March 16, 2021 18:22
Find all unhealth instances in a VMSS
$allInstances = Get-AzVmssVM -InstanceView -ResourceGroupName $rg -VMScaleSetName $vmssName
$unhealthyInstances = $allInstances | where {$_.InstanceView.VmHealth.Status.Code -eq "HealthState/unhealthy"}
Write-Output "Total instances: $($allInstances.Count)"
Write-Output "Unhealthy instances: $($unhealthyInstances.Count)"
@fitzgeraldsteele
fitzgeraldsteele / vmss-availability.ps1
Created June 9, 2020 19:06
Azure Virtual Machine Scale Sets: Check Availability constructs
Connect-AzAccount
$mysub = "my-subscription-name"
$rg = "my-resourcegroup-name"
$vmssname = "my-vmss-name"
Set-AzContext -Subscription $mysub
$vmssmodel = Get-AzVmss -ResourceGroupName $rg -VMScaleSetName $vmssname
Write-Output($vmssmodel.Id)
Write-Output("FD Count: " + $vmssmodel.PlatformFaultDomainCount)
@fitzgeraldsteele
fitzgeraldsteele / app.js
Last active November 12, 2019 18:00
Simple node app to return data from Azure Metadata service
var express = require('express')
var app = express()
var os = require('os');
app.get('/', function (req, res) {
const request = require('request');
const options = {
url: 'http://169.254.169.254/metadata/instance?api-version=2019-03-11',
headers: {
'Metadata': 'true'
[Unit]
Description=Azure Metadata app
[Service]
ExecStart=/usr/bin/node /var/www/azuremetadata/app.js
#Restart=always
StandardOut=syslog
StandardError=Syslog
User=nobody
# Note Debian/Ubuntu uses 'nogroup', RHEL/Fedora uses 'nobody'