Skip to content

Instantly share code, notes, and snippets.

title: Home
views:
- theme: Backend-selected
path: default_view
title: Basics
icon: mdi:home
badges: []
cards:
- type: entities
title: Main House Lights
@simonjgreen
simonjgreen / clock.ino
Created March 20, 2023 09:02
M5Stick C Plus World Clock with M5 Digiclocks
#include <M5StickCPlus.h>
#include <M5UNIT_DIGI_CLOCK.h>
#include <Wire.h>
#include <WiFi.h>
#include "time.h"
#include <NTPClient.h>
// Wireless details
const char* ssid = "SSID";
const char* password = "PSK";
/**
* Retrieves all the rows in the active spreadsheet that contain data and logs the
* values for each row.
* For more information on using the Spreadsheet API, see
* https://developers.google.com/apps-script/service_spreadsheet
*/
function readRows() {
var sheet = SpreadsheetApp.getActiveSheet();
var rows = sheet.getDataRange();
var numRows = rows.getNumRows();
@simonjgreen
simonjgreen / HostValues.ps1
Created May 22, 2017 10:41
Get the commercial value of all hosts
function getValue{
# Define the dict of our products
$productsByMem = @{}
$productsByMem.Add(0.5,40)
$productsByMem.Add(1,60)
$productsByMem.Add(2,90)
$productsByMem.Add(3,130)
$productsByMem.Add(4,160)
$productsByMem.Add(6,210)
$productsByMem.Add(8,260)
@simonjgreen
simonjgreen / Get-CPURatio.ps1
Created May 2, 2017 10:24
Gets CPURatios for VMHosts. Use as a filter on Get-VMHost.
filter Get-CPURatio {
$vcpus=0
$ratio=$null
$hostthreads=$_.extensiondata.hardware.cpuinfo.numcputhreads
$_ | Get-VM | ForEach {$vcpus+=$_.numcpu}
if ($vcpus -ne "0") {$ratio= "$("{0:N2}" -f ($vcpus/$hostthreads))" + ":1"}
$temp = New-Object psobject
$temp | Add-Member -MemberType Noteproperty "Hostname" -value $_.name
$temp | Add-Member -MemberType Noteproperty "PhysicalThreads" -Value $Hostthreads
@simonjgreen
simonjgreen / Set-IOPSLimit.ps1
Last active May 9, 2019 16:43
Set's IOPS, as a filter, in PowerCLI
filter Set-IOPSLimit {
$_ | % {
$DiskLimitIOPerSecond = 300
# $DiskLimitIOPerSecond = -1 # Unlimited
$vm = Get-VM -Name $_.Name
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$vm.ExtensionData.Config.Hardware.Device |
where {$_ -is [VMware.Vim.VirtualDisk]} | %{
$dev = New-Object VMware.Vim.VirtualDeviceConfigSpec
@simonjgreen
simonjgreen / Get-SnapshotReport.ps1
Last active February 25, 2017 22:06
PowerCLI function to get a report on all snapshots with detail
function Get-SnapshotReport {
Get-VM | Sort-Object | Get-Snapshot | Where-Object {$_.Created -lt (Get-Date).AddDays(-28)} | Format-Table VM, Created, @{Name="Size GB"; Expression={$_.SizeGB}; FormatString="N1"}, ParentSnapshot, Name, Description, PowerState -AutoSize
}
@simonjgreen
simonjgreen / Get-IOPSLimit.ps1
Created February 19, 2017 09:19
PowerCLI filter for retrieving VMDKs and their associated IOPS Limits
filter Get-IOPSLimit {
$_ | % {
$VmHdds = Get-HardDisk -VM $_.Name | select Name, ExtensionData, Filename, CapacityKB
foreach ($VmHdd in $VmHdds) {
$row = "" | select VmName, HddName, ScsiID, Datastore, CapacityGB, CurrentIOLimit
$row.VmName = $_.Name
$row.HddName = $VmHdd.Name
$row.ScsiID = $([string]$VmHdd.extensiondata.controllerkey).substring(3,1) +":"+ $([string]$VmHdd.extensiondata.unitnumber)
$row.Datastore = $($VmHdd.Filename.TrimStart("[")).split("]")[0]
$row.CapacityGB = $VmHdd.capacitykb / 1024 / 1024
@simonjgreen
simonjgreen / Get-FolderPath.ps1
Created February 18, 2017 17:28
Look up folder path for object in PowerCLI
filter Get-FolderPath {
$_ | Get-View | % {
$row = "" | select Name, Path
$row.Name = $_.Name
$current = Get-View $_.Parent
# $path = $_.Name # Uncomment out this line if you do want the VM Name to appear at the end of the path
$path = ""
do {
$parent = $current
@simonjgreen
simonjgreen / get-stats.ps1
Last active February 18, 2017 22:20
Get avg and max VM usage stats
Get-VM -Tag LoadBalancer | Where {$_.PowerState -eq "PoweredOn"} | Select Name, VMHost, NumCPU, MemoryGB, `
@{N="CPU MHz (Avg)" ; E={[Math]::Round((($_ | Get-Stat -Stat cpu.usagemhz.average -Start (Get-Date).AddDays(-30) -IntervalMins 5 | Measure-Object Value -Average).Average),2)}}, `
@{N="CPU Mhz (Max)" ; E={[Math]::Round((($_ | Get-Stat -Stat cpu.usagemhz.average -Start (Get-Date).AddDays(-30) -IntervalMins 5 | Measure-Object Value -maximum).maximum),2)}}, `
@{N="Memory % (Avg)" ; E={[Math]::Round((($_ | Get-Stat -Stat mem.usage.average -Start (Get-Date).AddDays(-30) -IntervalMins 5 | Measure-Object Value -Average).Average),2)}} , `
@{N="Memory % (Max)" ; E={[Math]::Round((($_ | Get-Stat -Stat mem.usage.average -Start (Get-Date).AddDays(-30) -IntervalMins 5 | Measure-Object Value -maximum).maximum),2)}} , `
@{N="Network KBps (Max)" ; E={[Math]::Round((($_ | Get-Stat -Stat net.usage.average -Start (Get-Date).AddDays(-30) -IntervalMins 5 | Measure-Object Value -maximum).maximum),2)}} , `
@{N="Network KBps (A