Skip to content

Instantly share code, notes, and snippets.

View jimfdavies's full-sized avatar

Jim Davies jimfdavies

View GitHub Profile
@jimfdavies
jimfdavies / SafariTabCycler.Applescript
Last active July 3, 2018 13:15
Safari Tab Cycler Applescript for dashboards, etc on Macs. Needs open Safari window(s) and presents startup options.
tell application "Safari"
set reloadQuestion to display dialog "Reload each tab?" buttons {"Yes", "No"} default button 2
set reloadAnswer to button returned of reloadQuestion
if reloadAnswer is equal to "Yes" then
set reloadTab to true
else
set reloadTab to false
end if
(choose from list {1, 5, 10, 30, 60} ¬
with prompt "Select delay time in seconds?" default items 30)
@jimfdavies
jimfdavies / bumpme
Last active December 15, 2016 14:41
Thu Dec 15 14:41:41 UTC 2016
@jimfdavies
jimfdavies / helpers.sh
Last active November 16, 2021 02:47
AWS CLI helpers
# Security groups that contain 0.0.0.0/0 rules
aws ec2 describe-security-groups --filters Name=ip-permission.cidr,Values=0.0.0.0/0 --output=text | grep SECURITYGROUPS
# Security groups for ElasticSearch
aws ec2 describe-security-groups --filters Name=ip-permission.from-port,Values=9200 --output=text | grep SECURITYGROUPS
# Search last 10,000/1MB of CloudTrail logs for 'AccessDenied' (removed AWS account number from stream name)
aws logs get-log-events --log-group-name CloudTrail/DefaultLogGroup --log-stream-name 000000000000_CloudTrail_eu-west-1 | grep AccessDenied
# Get number of AWS API calls in time period (assumes a Cloudwatch Logs 'catch-all' filter and metric has been created against CloudTrail logs)
@jimfdavies
jimfdavies / test_echo
Last active August 29, 2015 14:07
Testing
echo "hello world"
ls -la
@jimfdavies
jimfdavies / showAllRightscaleAccount.rb
Last active December 22, 2015 00:49
Authenticates and lists your Rightscale deployments. Pretty much copied from Rightscale examples at http://support.rightscale.com/12-Guides/RightScale_API_1.5/Examples/
# Pretty much copied from Rightscale examples at
# http://support.rightscale.com/12-Guides/RightScale_API_1.5/Examples/
# Update and revision test
require 'rubygems'
require 'pp' # Require pretty print Ruby gem
require 'right_api_client' # RightScale API client gem
user = 'x@x.com' # Set user email address for using the Dashboard
acct = '1234' # Set the account ID
@jimfdavies
jimfdavies / pingsweep.ps1
Created February 21, 2013 09:57
Quick script to ping a subnet and report if each IP address is used or 'empty'. Can be extended to redirect to a file if desired.
$subnet24 = "10.10.1"
1..254 |
foreach-object {
$ip = $subnet24 + "." + $_
if (test-connection $ip -count 1 -quiet) { Write-Host "USED:$ip" } else { Write-Host "EMPT:$ip" }
}
#USED:10.10.2.1
#EMPT:10.10.2.2
@jimfdavies
jimfdavies / test-vsphere.rb
Last active September 28, 2018 14:06
Quick example for Fog VSphere provider. Lists VMs in a given folder in a given DC.
#!/usr/bin/env ruby
require 'rubygems'
require 'pp'
require 'fog'
require 'highline/import'
def get_password(prompt="Enter password:")
ask(prompt) {|q| q.echo = false}
end
@jimfdavies
jimfdavies / Get-OSTypeFromTemplate.ps1
Created February 11, 2013 14:39
Get-OSTypeFromTemplate returns the VSphere API 'ostype' from a defined template. This can be used to build out an OS Customisation Specification when deploying a new VM from template. Easily extensible for other OSes or more specific flavors. If the template does not give up its secrets, the script stops and waits for you to type it in.
Function Get-OSTypeFromTemplate {
param($templatename)
$templateview=get-view -id (get-template -Name $templatename).id
switch -wildcard ($templateview.Guest.GuestFullName)
{
"*Windows*" { $ostype = "Windows" }
"*Linux*" { $ostype = "Linux" }
default { $ostype = Read-Host "Unable to determine OS from template $templatename. Enter the word Linux or Windows here" }
}
@jimfdavies
jimfdavies / Get-GatewayFromIPAddress.ps1
Created February 11, 2013 14:29
Get-GatewayFromIPAddress returns your IP gateway from your IP address. This assumes that your default gateway is on the same /24 subnet and its node address is .1 (configurable). Useful for automatic deployment scripts.
Function Get-GatewayFromIPAddress {
param($ipaddress)
$routerip = ".1"
$gateway = (($ipaddress.Split("."))[0..2] -join ".") + $routerip
return $gateway
}
$ipaddress = "10.1.2.100"
$gateway = Get-GatewayFromIPAddress -ipaddress $ipaddress
@jimfdavies
jimfdavies / Get-DomainFromFQDN.ps1
Last active September 28, 2018 14:06
Get-DomainFromFQDN return the domain portion of a Fully-Qualified Hostname. This is currently limited to 4 sub-domains but the array selection could easily be extended to use the length of the array if appropriate. Useful for automatic deployment scripts.
Function Get-DomainFromFQDN {
param($fqdn)
$vmdomain = ($fqdn.split("."))[1..4]
$vmdomain = $vmdomain -join "."
return $vmdomain
}
$fqdn = "myhost.my.domain.local"
$domain = Get-DomainFromFQDN -fqdn $fqdn