Skip to content

Instantly share code, notes, and snippets.

View WilliamBerryiii's full-sized avatar

Bill Berry WilliamBerryiii

View GitHub Profile
@WilliamBerryiii
WilliamBerryiii / gist:ffe6975c1a092f39dd1a
Last active August 29, 2015 14:19
Get IronPython Version from path ipy in Powershell
function Get-IpyVersionFromPath
{
.{
$version = ''
$ipyPath = Get-Command ipy | Select-Object -ExpandProperty Definition
if( [string]::IsNullOrEmpty($ipyPath) ) { return "IPY not in path" }
$ipyFolder = split-path $ipyPath
$ipyDll = join-path $ipyFolder 'IronPython.dll'
[reflection.assembly]::LoadFrom($ipyDll)
@WilliamBerryiii
WilliamBerryiii / DiskSpaceCheck.ps1
Created August 10, 2015 20:36
Powershell to check for impacted drives on a machine.
$drivediskSpace = Get-PSDrive |
## Select the Name, Used amount in GB and Free space in GB
Select-Object Name, @{Name="Used";Expression={$_.Used / 1GB}}, @{Name="Free";Expression={$_.Free / 1GB}} |
## just pick mounted single letter drives to exclude registry
Where {$_.Name.Length -eq 1}
$impactedDrives = $drivediskSpace |
## Select drives where there is more than 0 bytes
## and either more than 80% used or 10GB of disk space remaining
Where { (($_.Free + $_.Used) -gt 0) -and (($_.Used/($_.Free + $_.Used) -gt .8) -or ($_.Free -lt 10)) } |
Select-Object Name, Used, Free
@WilliamBerryiii
WilliamBerryiii / Get-ScriptrockNodes
Created September 13, 2015 21:48
Powershell v3.0+ to get all nodes configured in Scriptrock
$target = "https://my.scriptrock.applicance.com/"
$apiKey = "api_key"
$secretKey = "secret_key"
$token = $apiKey + $secretKey
$authToken = 'Token token="' + $token + '"'
$headers = @{'Authorization'=$authToken;'Content-Type'='application/json'; 'Accept'='application/json'}
$page = 0
@WilliamBerryiii
WilliamBerryiii / Update-ScriptrockNodeConnectionManager
Created September 15, 2015 06:57
Filter a list of Scriptrock nodes and update their connection manager.
$nodes |
where { $_.operating_system_family_id -eq 1 } |
Foreach {
$resource = "/api/v1/nodes/$_.id"
$uri = $target + $resource
Invoke-RestMethod -Method put -Uri $uri -Headers $headers -Body '{"node": {"connection_manager_group_id": 6}}'
}
@WilliamBerryiii
WilliamBerryiii / Toggle-ScriptrockNodeMediumType
Created September 16, 2015 06:04
Powershell v3.0+ to toggle the medium type of a Scriptrock node
$target = "https://my.scriptrock.com"
$apiKey = "api_key"
$secretKey = "secret_key"
$nodeName = 'node_name'
$ErrorActionPreference = "Stop"
# A reuseable enum for meduim types
Add-Type -TypeDefinition @"
public enum MediumType
@WilliamBerryiii
WilliamBerryiii / Add-TimelineEventWithFavicon
Created September 18, 2015 06:15
Add an event to the Scriptrock Timeline that includes the company favicon for branding.
# A reuseable enum for meduim types
Add-Type -TypeDefinition @"
public enum EventStatus
{
ERROR = 0,
WARNING = 1,
OK = 2
}
"@
@WilliamBerryiii
WilliamBerryiii / SimpleCSharpRepository
Last active September 26, 2015 22:08
Example Basic C# Data Accessor/Repository
public class Repository
{
private ISqlExecutioner _sqlExecutioner;
private string _connectionString;
public Repository (ISqlExecutioner sqlExecutioner, string connectionString)
{
_sqlExecutioner = sqlExecutioner;
_connectionString = connectionString;
}
@WilliamBerryiii
WilliamBerryiii / TimedRepositoryMethod
Created September 26, 2015 22:25
Example of timing a repository method
public static DataSet GetSomeStuffFromTheDatabase(int thingId)
{
const string PROCEDURE_NAME = "GetMeSomeData";
var parameterLisst = new SqlParameterList();
parameterList.Add("@thing_id", SqlDbType.Int, thingId);
var sw = Stopwatch.StartNew();
var results = _sqlExecutioner.ExecuteQuery(_connectionString, PROCEDURE_NAME, parameterList);
sw.Stop();
_timeToExecuteGetSomeStuffFromTheDatabase = sw.Elapsed;
return results;
@WilliamBerryiii
WilliamBerryiii / SimpleCSharpRepositoryWithTimingMethod
Created September 27, 2015 05:54
An example repository with timing method wrapping the database calls.
public class Repository
{
private ISqlExecutioner _sqlExecutioner;
private string _connectionString;
private long _dbQueryRequestTime;
public long DbQueryRequestTime { get { return _dbQueryRequestTime; }}
public Repository (ISqlExecutioner sqlExecutioner, string connectionString)
{
@WilliamBerryiii
WilliamBerryiii / StoredProcedureReturnCodeTesting
Last active July 7, 2017 07:39
Simple example of testing a stored procedure return code parameter with Moq
const string RETURN_CODE_NAME = "@return_code";
const int SP_RETURN_VALUE = 0;
Dictionary<string, SqlParameter> parameterList = null;
_mockSqlExecutor = new Mock<ISqlExecutor>();
_mockSqlExecutor.Setup(mdm =>
mdm
.ExecuteNonQuery(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<Dictionary<string, SqlParameter>>()))
.Callback(
(string conn, string procName, Dictionary<string, SqlParameter> plist) =>