Skip to content

Instantly share code, notes, and snippets.

View Sam-Martin's full-sized avatar

Sam Martin Sam-Martin

View GitHub Profile
@Sam-Martin
Sam-Martin / Delete-LowQualityPlexDuplicates.ps1
Created April 15, 2018 15:36
Delete Lower Quality Plex Duplicates
$Server='192.168.1.9:32400'
$PlexToken = 'FGir5aQ5yfpRZZ4ZqxAg'
$libraries = Invoke-RestMethod -Uri "http://$server/library/sections/all?X-Plex-Token=$PlexToken"
$VideoLibraries = $libraries.MediaContainer.Directory | ?{$_.type -eq 'show'}
$Resolutions = @{
"sd" = 1
"420" = 10
"720" = 20
"1080" = 30
}
@Sam-Martin
Sam-Martin / userdata.sh
Created November 14, 2019 16:44
EC2 Userdata for proxy setup of SSM Agent on Amazon Linux 2
#!/usr/bin/env bash
mkdir -p /etc/systemd/system/amazon-ssm-agent.service.d
echo "[Service]" > /etc/systemd/system/amazon-ssm-agent.service.d/override.conf
echo 'Environment="https_proxy=http://proxy:3128"' >> /etc/systemd/system/amazon-ssm-agent.service.d/override.conf
echo 'Environment="http_proxy=http://proxy:3128"' >> /etc/systemd/system/amazon-ssm-agent.service.d/override.conf
echo 'Environment="no_proxy=169.254.169.254"' >> /etc/systemd/system/amazon-ssm-agent.service.d/override.conf
chmod 777 /etc/systemd/system/amazon-ssm-agent.service.d/override.conf
systemctl stop amazon-ssm-agent
systemctl daemon-reload
systemctl restart amazon-ssm-agent
@Sam-Martin
Sam-Martin / PowerShell Zabbix API Example.ps1
Created August 3, 2016 15:53
PowerShell Zabbix API Example
if(!$credential){
$credential = Get-Credential
}
$baseurl = 'http://zabbix.global.root'
$params = @{
body = @{
"jsonrpc"= "2.0"
"method"= "user.login"
"params"= @{
"user"= $credential.UserName
@Sam-Martin
Sam-Martin / Invoke-KMSEncrypt-Example.ps1
Last active June 16, 2020 17:53
PowerShell Example for using Invoke-KMSEncrypt and Invoke-KMSDecrypt
# Stolen from http://ctrlf5.net/?p=263 and http://www.dailycoding.com/posts/convert_image_to_base64_string_and_base64_string_to_image.aspx
function ConvertFrom-StringToMemoryStream{
param(
[parameter(Mandatory)]
[string]$InputString
)
$stream = New-Object System.IO.MemoryStream;
$writer = New-Object System.IO.StreamWriter($stream);
$writer.Write($InputString);
@Sam-Martin
Sam-Martin / Test Kitchen Add Vagrant Disks.md
Last active March 21, 2020 03:52
Test Kitchen VagrantFile.rb to add disks & test_helper.bash to format them

Use these two files to add disks to your VMs (here adding three disks) when Kitchen spins up Vagrant boxes.

  • test_helper.bash (add to your bats test with load test_helper)
  • vagrantfile.rb (add to your .kitchen.yml using)
---
driver:
  name: vagrant
  vagrantfiles: 
 - vagrantfile.rb
@Sam-Martin
Sam-Martin / Cmdline example
Created January 26, 2020 16:54
Get Media Language Recursively
find . -iregex ".*.\(mp4\|mkv\)" -exec ~/medialanguage.sh "{}" \; | jq '. | select(.Languages | index("English") | not)'
@Sam-Martin
Sam-Martin / get_all_lambda_invocation_stats.py
Created October 3, 2019 10:44
Sort lambda functions by invocations
import sys
import boto3
import datetime
cw = boto3.client('cloudwatch')
list_metrics_paginator = cw.get_paginator('list_metrics')
function_stats = []
@Sam-Martin
Sam-Martin / Clone DynamoDB.py
Created May 15, 2019 13:24
Download and Restore DynamoDB
aws dynamodb scan --table-name TABLE > export.json
import json
import boto3
dynamo = boto3.client('dynamodb')
TABLE_NAME = 'TABLE_NAME'
JSON_PATH = '/Users/USERNAME/git/GitHub/dynamodump/export.json'
with open(JSON_PATH, 'r') as file:
data = file.read()
parsed_file = json.loads(data)
for item_to_import in parsed_file['Items']:
@Sam-Martin
Sam-Martin / RightGIF Integration for HipChat using AWS Lambda.py
Created April 26, 2016 20:28
RightGIF Integration for HipChat using AWS Lambda
import urllib
import urllib2
import json
def lambda_handler(event, context):
url = 'https://rightgif.com/search/web'