Skip to content

Instantly share code, notes, and snippets.

View stevensk's full-sized avatar

Kim Stevens stevensk

  • Sydney, Australia
View GitHub Profile
@stevensk
stevensk / web.config
Last active June 30, 2021 21:53
IIS URL Rewrite for Site Maintenance
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rewriteMaps>
<rewriteMap name="MaintenanceIpAddressWhitelist" defaultValue="">
<!-- add allowed IP addresses to grant access during maintenance period -->
<add key="192.168.0.1" value="1" />
<add key="127.0.0.1" value="1" />
</rewriteMap>
@stevensk
stevensk / dbup_kudu_deploy.cmd
Last active August 29, 2015 14:08
Kudu script section for running DbUp on Azure website continuous deployment
:: 2. DbUp Database Migrations
echo Handling Data Migrations.
%MSBUILD_PATH% HelloWorld.DbUp\HelloWorld.DbUp.csproj
IF !ERRORLEVEL! NEQ 0 goto error
echo Running DbUp.
:: call DbUp with the named connection string for the SQL Azure database i.e. "%SQLAZURECONNSTR_connection_string_name%"
call %DEPLOYMENT_SOURCE%\HelloWorld.DbUp\bin\debug\HelloWorld.DbUp.exe "%SQLAZURECONNSTR_HelloWorld_db%"
@stevensk
stevensk / azure_web_config_transforms
Last active September 23, 2017 18:16
Azure Web.config Transforms & Continuous Deployment
// Scenario
We've got two Azure web sites (Staging and Production), each with their respective database and we want to deploy to both websites from the same Git repository using continuous deployment. We need to take advantage of config transforms to accommodate the differences between the two environments, such as connection strings, for example.
Continuous deployment is fairly straight-forward, as we can simply specify different branches for each enivronment. For example, using GitFlow, we can use the "develop" branch to deploy to our Acceptance or Staging environment and our "master" branch to deploy to our Production environment. This allows us to use Pull Requests as an approval workflow for automated contiuous deployment.
// Setup
1) To enable config transforms for a web application project, simply add a transform for each environment required, in this case "Staging":
@stevensk
stevensk / pivot.sql
Created October 3, 2014 10:17
Basic example of using PIVOT to pivot table data.
-- 1. create the table
/****** Object: Table [dbo].[Population] Script Date: 3/10/2014 7:47:16 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
@stevensk
stevensk / unpivot_using_cross_join_and_union_all.sql
Last active August 29, 2015 14:07
Simple example of using CROSS JOIN with UNION ALL instead of UNPIVOT to unpivot data so as to include nulls in the results. This is especially useful when the data custodian wants to differentiate between data that was N/A and a zero value.
-- 1. Create a table of pivoted data (the kind of thing you might expect to be imported from CSV)
/****** Object: Table [dbo].[FruitBaskets] Script Date: 3/10/2014 10:48:23 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
/* Drop all non-system stored procs */
DECLARE @name VARCHAR(128)
DECLARE @SQL VARCHAR(254)
SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] = 'P' AND category = 0 ORDER BY [name])
WHILE @name is not null
BEGIN
SELECT @SQL = 'DROP PROCEDURE [dbo].[' + RTRIM(@name) +']'
EXEC (@SQL)