Skip to content

Instantly share code, notes, and snippets.

View EtherZa's full-sized avatar

Richard Pringle EtherZa

  • Perth, Australia
View GitHub Profile
@EtherZa
EtherZa / generate.ps1
Created May 12, 2017 10:27
Generate WCF service from WSDL (URL hosted) and rewrite fields as properties
$url = "http://<url>?WSDL"
$name = "<Service Name>"
$namespace = "<Base Namespace>." + $name
$file = "$name.generated.cs"
echo "Generating service $name ($url)"
& "C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\SvcUtil.exe" /t:code $url /language:C# /n:"*,$namespace" /out:$file /noConfig /syncOnly | out-null
(Get-Content $file) | Foreach-Object {$_ -replace "(?<=public [\w\.]+(?:\[\])? \w+)(;)", " { get; set; }"} | Set-Content $file
/*
This script helps simulate deadlocks. Run the entire script in a SQL query window. It will continue running until stopped.
In the target script, insert a call to sp_simulatedeadlock where you want the deadlock to occur.
This stored procedure, also created below, causes the deadlock.
When you are done, stop the execution of this window and run the code in the cleanup section at the bottom.
*/
SET NOCOUNT ON
IF OBJECT_ID('DeadlockTest') IS NOT NULL
DROP TABLE DeadlockTest
@EtherZa
EtherZa / ShowConsole.cs
Created July 7, 2017 14:25
Output to console in Windows Forms application
namespace ShowConsole
{
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
public static class Program
{
[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
@EtherZa
EtherZa / SyncWeb.ps1
Created November 6, 2017 06:45
Synchronise IIS hosted website across multiple servers via web deploy. Console output for TeamCity support.
# Parameters are expected in the following order:
# 1. Path to ms deploy eg. "C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe"
# 2. Source server name eg. server1.domain.net
# 3. Path to setParameters.xml which contains 'IIS Web Application Name' override [Comma delimitted]
# 4. User name eg. domain\username
# 5. Password eg. ****** (Caveat: not escaped)
# 6. Destination server name(s) [Comma delimitted] eg. server2.domain.net,server3.domain.net
param (
[parameter(Mandatory=$true)] [string]$msdeploy,
@EtherZa
EtherZa / ReplaceTokens.ps1
Last active November 6, 2017 06:52
Replace tokens in config transformations. Used for prepping branched deployments.
# Submit with a single parameter of a comma delimted list of key=value pairs.
# Caveat: no escaping is performed, so the script will go awry if the value contains a ',' and the script is not modified
param (
[parameter(Mandatory=$true)] [string]$raw
)
$filter = '*.setParameters.xml'
$lookup = ConvertFrom-StringData ($raw.split(",") | out-string)
@EtherZa
EtherZa / ListboxScroll.xaml
Created January 22, 2019 00:40
[WPF] ListBox blocks mouse scrolling
<ListBox>
<ListBox.Template>
<ControlTemplate>
<!-- Empty template to allow ScrollViewer to capture mouse scroll -->
<ItemsPresenter />
</ControlTemplate>
</ListBox.Template>
</ListBox>
@EtherZa
EtherZa / RetargetFramework.cs
Last active July 5, 2021 09:14
Visual Commander script to retarget all loaded Visual Studio projects to a specified .net version (TargetFramework).
// Retarget all loaded projects to the .net version specified in "TargetFramework"
// Execute with Visual Commander (https://marketplace.visualstudio.com/items?itemName=SergeyVlasov.VisualCommander)
// **********************************************************
// NOTE: NuGet packages need to be reinstalled post execution
// **********************************************************
using EnvDTE;
using EnvDTE80;
using System.Collections.Generic;
@EtherZa
EtherZa / buildNumber.ps1
Last active June 18, 2019 06:01
Creates a build number from the current date, build counter and branch name where branch name starts with a story name/number prefix.
# Generated a build number in the format year.month.day.buildCounter-story
# where story is derived from the branch name
#
# Parameters are expected in the following order:
# 1. build counter
# 2. branch name in the format develop | XXXX-ddd
param (
[parameter(Mandatory=$true)] [int]$buildCounter,
[parameter(Mandatory=$true)] [string]$branch
@EtherZa
EtherZa / pre-commit
Created August 12, 2019 02:53
Format c# with dotnet-format with pre-commit hook
#!/bin/sh
#
# modified from sample: https://prettier.io/docs/en/precommit.html
#
# install dotnet-format: dotnet tool install -g dotnet-format
# copy to .git/hooks/pre-commit and make executable
#
FILES=$(git diff --cached --name-only --diff-filter=ACM "*.cs" | sed 's| |\\ |g')
@EtherZa
EtherZa / oracle_delete_all_objects.sql
Created October 11, 2019 03:52
Delete all objects in an Oracle schema
-- Maximum carnage. Delete everything in a schema
declare
V_SCHEMA varchar(100);
begin
V_SCHEMA := 'APSM';
-- drop queues
for R_QUEUE in (
select V_SCHEMA || '.' || NAME as QUEUE_NAME
from SYS.ALL_QUEUES