Skip to content

Instantly share code, notes, and snippets.

View schwartzmx's full-sized avatar
👓

Phil Schwartz schwartzmx

👓
View GitHub Profile
@schwartzmx
schwartzmx / windows_ec2_provision.yml
Last active February 10, 2023 00:51
Ansible Windows EC2 Provisioning Playbook
- name: Launch {{env}}-{{service}} Instance(s)
hosts: localhost
gather_facts: false
connection: local
vars_files:
- group_vars/env/{{ environment }}.yml
- group_vars/service/{{ service }}.yml
- group_vars/admin.yml
# Launch instances with the following parameters. Register the output.
@schwartzmx
schwartzmx / fizz_buzz.sql
Created February 12, 2016 04:58
T-SQL FizzBuzz
-- Printed, while loop
declare @str varchar(30), @i int = 0, @max int = 100;
while @i <= 100
begin
if @i % 3 = 0
set @str += 'Fizz'
if @i % 5 = 0
set @str += 'Buzz'
if len(@str) !> 0
@schwartzmx
schwartzmx / prc_Magic8Ball.sql
Last active February 12, 2016 05:14
T-SQL Magic8Ball
create procedure [prc_Magic8Ball]
(
@question varchar(100)
)
-- Author: Phil
-- Example: exec prc_Magic8Ball 'Will I make it into the office on time today?';
as
begin
set nocount on;
declare @phrase as table (name varchar(50));
# Quick abstraction test
$d = (Get-Date)
$frequency = "Weekly"
$query = "exec prc_ReportXYZ {0}, {1};"
switch ($frequency) {
"Weekly" {
$beginDate = $d.AddDays(-$d.DayOfWeek).ToString('MM/dd/yy')
$endDate = (Get-Date $beginDate).AddDays(7).ToString('MM/dd/yy')
}
"Monthly" {
@schwartzmx
schwartzmx / SQLServerKB-RSSFeed.ps1
Created June 23, 2016 01:58
A simple PowerShell script to read the RSS feed for SQL Server KB support updates
<#
Author: Phil Schwartz
Description: A simple script to read the RSS feed for SQL Server KB support updates
- Allows stepping through the feed and opening in browser, if specified
#>
[xml]$xmldoc= Invoke-WebRequest 'https://support.microsoft.com/en-us/rss?rssid=1044'
$feed = $xmldoc.rss.channel
$lid = 0
@schwartzmx
schwartzmx / olympic_medals_scraper.py
Last active January 19, 2017 15:05
Simple script to scrape the default grid Olympic medals table on NBC's site and dump the result as JSON
from bs4 import BeautifulSoup
import requests as r
from json import dumps
class Country:
def __init__(self, country, place, gold, silver, bronze, total_medals):
self.country = country
self.place = place
self.gold = gold
self.silver = silver
@schwartzmx
schwartzmx / SQLServer_SettingsTransfer.ps1
Last active August 12, 2016 22:09
SQL Server jobs, linked servers, etc.. transfer from a source server to targets using SMO
<#
Note: Before running, make sure you have any relevant Credentials copied over and maintenance plans, or referenced objects could cause failures in the script.
Author: Phil
#>
$Source = "" # ex. "Source-SQL"
$SQLUser = "" # user
$SQLPassword = "" # password
$Targets = "" # ex. "Target-SQL"
[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO') | out-null
@schwartzmx
schwartzmx / SQLServer_SSIS-Transfer.ps1
Last active August 12, 2016 19:16
Transfer SSIS Folders and Projects from a source server to a destination server.
<#
Transfer SSIS Folders and Projects from a source server to a destination server.
Mostly taken from http://widba.blogspot.com/2013/02/moving-SSIS-projects-in-sql-server-2012.html with some added functionality for copying ALL SSIS packages and folders to the destination
Note this does have to use SSPI Integrated Security for copying from the Source to Dest
Author: Phil Schwartz
#>
@schwartzmx
schwartzmx / SQL_CheckWFClusterLogs.ps1
Last active September 19, 2016 16:42
Intended only to be run as a scheduled job on a SQL Server. This should be scheduled every $LogTimeSpanMinutes as a SQL Agent job. This grabs the events logs and emails on Error level logs being found and shoots an email with the contents of the errors.
$LogTimeSpanMinutes = 10
$AfterDate = (Get-Date).AddMinutes(-$LogTimeSpanMinutes)
$SQLMailProfile = "DoNotReplyNotification"
$recipients = "email@gmail.com"
$subject = "Failover Cluster ERRORS"
$body = "<!DOCTYPE html><html><head></head><br><body> {0} </body></html>"
$LocalServer = hostname
Function DBA-SendMail {
param(
@schwartzmx
schwartzmx / keybase.md
Created September 15, 2016 16:04
keybase.md

Keybase proof

I hereby claim:

  • I am schwartzmx on github.
  • I am schwartzmx (https://keybase.io/schwartzmx) on keybase.
  • I have a public key whose fingerprint is 5FD3 7845 FB08 46F6 6D0F CC00 3B5C B261 00D2 E70F

To claim this, I am signing this object: