Skip to content

Instantly share code, notes, and snippets.

View cbattlegear's full-sized avatar

Cameron Battagler cbattlegear

View GitHub Profile
@cbattlegear
cbattlegear / plex_auto_update.php
Created March 18, 2019 03:16
Plex Auto update Scripts, run with both in same directory. Run plex_auto_update.php as root to update.
<?php
# Install Curl Support with sudo apt-get install php-curl
# Install XML Support with: sudo apt-get install php-xml
#Config
#Plex host in url format (protocol://host:port)
$plex_host = "http://localhost:32400";
$plex_token = "YourPlexTokenHere";
#Get updates XML file from plex
@cbattlegear
cbattlegear / DWPause.ps1
Created January 11, 2019 16:09
This is an azure automation workflow to pause all DWs on your subscription daily
workflow PauseDWInstances
{
$connectionName = "AzureRunAsConnection"
try {
# Get the connection "AzureRunAsConnection "
$servicePrincipalConnection=Get-AutomationConnection -Name $connectionName
"Logging in to Azure..."
Add-AzureRmAccount `
-ServicePrincipal `
@cbattlegear
cbattlegear / SyncPeloton.csx
Created September 25, 2018 16:49
Synchronize Peloton data to Azure SQL Database
#r "Newtonsoft.Json"
#r "System.Configuration"
#r "System.Data"
using System;
using System.Net;
using RestSharp;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Data;
#r "Newtonsoft.Json"
#r "System.Configuration"
#r "System.Data"
using System.Net;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using Newtonsoft.Json;
#r "Newtonsoft.Json"
#r "System.Configuration"
#r "System.Data"
using System.Net;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using Newtonsoft.Json;
import time
import board
import digitalio
from urllib import request, parse
print("press the button!")
sneezeurl = "AzureFunctionsURL"
led = digitalio.DigitalInOut(board.D18)
@cbattlegear
cbattlegear / sql-azure-export-script-example.ps1
Created September 28, 2017 21:32
Basic powershell script that copies and exports database to azure storage that can be scheduled on an Azure VM
# You will need to install the newest version of SSMS https://docs.microsoft.com/en-us/sql/ssms/download-sql-server-management-studio-ssms
# (easiest way to get the dependencies) and install AzCopy http://aka.ms/downloadazcopy
# create a file one database name per line called database_list.txt for all dbs on the server you want to export
#SQL Azure connection info
$sql_servername = '' # Without .database.windows.net
$sql_username = ''
$sql_password = ''
#Storage Account connection info
@cbattlegear
cbattlegear / CreateDatabaseFromGeoRestore.cs
Last active September 6, 2017 15:37
Basic REST API Example for Creating database from Geo-Restore
using System;
using System.Text;
using System.Net;
using Microsoft.IdentityModel.Clients.ActiveDirectory;
using Newtonsoft.Json.Linq;
/* Basic REST API Example for Creating database from Geo-Restore
* Grab Microsoft.IdentityModel.Clients.ActiveDirectory and Newtonsoft.Json from Nuget
*
* Create Service principal credentials as per https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-service-principal-portal#create-an-azure-active-directory-application
@cbattlegear
cbattlegear / bandwidth.py
Last active August 31, 2017 16:07
Quick Bandwidth Format function
def format_bandwidth(i):
loop = 0
current_num = i
last_num = 0
label = ["Bps", "KBps", "MBps", "GBps"]
while(True):
last_num = current_num
current_num = current_num/1024.0
if(current_num < 1):
return '{0:0.2f} {1}'.format(last_num, label[loop])
@cbattlegear
cbattlegear / plexinfo.php
Last active August 7, 2017 19:29
PHP Script to gather Plex streams and transcodes and to output them to influxdb
<?php
function write_to_influx($influx_host, $influx_port, $influx_db, $influx_query) {
#Convert to binary stream as per https://stackoverflow.com/a/34119930/404006
$stream = fopen('php://memory','r+');
fwrite($stream, $influx_query);
$data_length = ftell($stream);
rewind($stream);
$curl = curl_init();
curl_setopt_array( $curl,