Skip to content

Instantly share code, notes, and snippets.

View mercdev's full-sized avatar

Latitude17 mercdev

View GitHub Profile
@mercdev
mercdev / Blynk_WeMos_D1_R2.ino
Created January 25, 2018 02:52
Using Blynk with WeMos D1 R2 and RTC
#define BLYNK_PRINT Serial
// Blynk app
#include <BlynkSimpleEsp8266.h>
#include <RTClib.h>
#include <WidgetRTC.h>
// Non Blynk specific, local files
#include <WiFiUdp.h>
#include "NTP.h"
@mercdev
mercdev / ssl-cert-request.ps1
Created August 24, 2017 17:43
Get-Certificate by DNS Subject Name and grant management permissions. Will attempt to create via CA if not found.
cls
$dnssubject = 'CN=servername.goes.here'
$WorkingCert = Get-ChildItem CERT:\LocalMachine\My |where {$_.Subject -match $dnssubject} | sort $_.NotAfter -Descending | select -first 1
if ($WorkingCert -eq $null)
{
Write-Host "Unable to locate certificate for $($dnssubject), attempting to create..."
[string[]] $dnsnames = @("alternate.name.one", "altername.name.two", "alternate.name.three")
@mercdev
mercdev / dynamic-appender.cs
Last active December 23, 2015 15:55
Creates a log4Net RollingFileAppender.
// Init: Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();
// hierarchy.Root.AddAppender(CreateWSMFileAppender("logger-name-here"));
// Usage: var wsmLog = LogManager.GetLogger("logger-name-here");
// if (wsmLog != null)
// {
// wsm.InfoFormat("Hi, you did it dynamically!");
// {
private static IAppender CreateFileAppender(string appenderName)
{
@mercdev
mercdev / queue-tfs-builds.ps1
Last active November 30, 2015 14:19
Queue all enabled builds in TFS via PowerShell
cls
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Client")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Build.Client")
$serverName = "http://server.fqdn:8080/tfs"
$teamProject = "project_name"
$tfs = [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer($serverName)
$buildserver = $tfs.GetService([Microsoft.TeamFoundation.Build.Client.IBuildServer])
$buildDefinitions = $buildServer.QueryBuildDefinitions($teamProject).Name
@mercdev
mercdev / remote-iis.ps1
Created September 11, 2015 20:48
Remote IIS info via PowerShell
$website = 'Default'
$server = 'SOME_SERVER_01'
$session = New-PSSession -ComputerName $server -Name "My_Session_Name"
$remoteOriginalFolder = Invoke-Command -Session $session -ScriptBlock { param($website)
Import-Module WebAdministration
$originalFolder = Get-WebFilePath IIS:\Sites\$website
return $originalFolder.FullName
} -ArgumentList $website
$remoteOriginalFolder
DECLARE @SQL VARCHAR(MAX)
DECLARE @SearchString VARCHAR(100)
SET @SQL = ''
SET @SearchString = 'some string here'
SELECT @SQL = @SQL + 'SELECT CONVERT(VARCHAR(MAX),COUNT(*)) + '' matches in column ''+'''
+ C.name + '''+'' on table '' + ''' + SC.name + '.' + T.name +
''' [Matches for '''+@SearchString+''':] FROM ' +
QUOTENAME(SC.name) + '.' + QUOTENAME(T.name) + ' WHERE ' + QUOTENAME(C.name) +
param([parameter(Mandatory=$true,HelpMessage="Server Environment")]$state,$env)
Import-Module WebAdministration;
switch ($env)
{
"### SERVERNAME ###"
{
if ($state -eq "STOP")
{
private void SetKeepAliveIOControl(Socket socket, uint interval, uint retryInterval, bool enabled)
{
int size = sizeof(UInt32);
uint on = enabled ? (uint)1 : (uint)0;
byte[] inArray = new byte[size * 3];
Array.Copy(BitConverter.GetBytes(on), 0, inArray, 0, size);
Array.Copy(BitConverter.GetBytes(interval), 0, inArray, size, size);
Array.Copy(BitConverter.GetBytes(retryInterval), 0, inArray, size * 2, size);
socket.IOControl(IOControlCode.KeepAliveValues, inArray, null);
}
@mercdev
mercdev / multi-deploy.ps1
Last active August 29, 2015 14:20
Multithreaded file copy (via Robocopy) to multiple destinations
cls
$source = "\\sourcefiles\path\here";
$auth = "\\authserver\c$\Fileroot";
$destDev = "\\devserver\C$\FileRoot";
$destTest = "\\testserver\C$\FileRoot";
$destStage = "\\stageserver\C$\FileRoot";
$destProd = "\\productionserver\C$\FileRoot";
#$scriptBlock = { Param($source,$destination) robocopy $source $destination /MAXAGE:21 /MT:32 /S /NC /NS /NDL /NJH /NJS /NFL }
$scriptBlock = { Param($source,$destination) robocopy $source $destination /MAXAGE:21 /MT:32 /S }
@mercdev
mercdev / audit.ps1
Created May 2, 2015 23:08
PowerShell Windows AD Inventory with Excel output
# Usage: Audit.ps1 'pathtolistofservers' #
# The file is optional and needs to be a plain text list of computers to be audited one on each line. #
#
param([string] $auditlist)
cls
$Error.Clear() # clear the stack
$targets = $null
if ($auditlist -eq "")