Skip to content

Instantly share code, notes, and snippets.

@RickyLin
RickyLin / fnGetCSharpTypeNameFromSQLTypeName.sql
Last active August 18, 2020 07:09
Convert SQL data type to C# data type
ALTER FUNCTION [dbo].[fnGetCSharpTypeNameFromSQLTypeName]
(
@SQLTypeName NVARCHAR(64)
, @IsNullable BIT
)
RETURNS NVARCHAR(64)
AS
-- TEST: SELECT dbo.fnGetCSharpTypeNameFromSQLTypeName('MONEY', 1)
BEGIN
DECLARE @Result NVARCHAR(64)
@RickyLin
RickyLin / DeleteLocalBranchesWhoseRemoteTrackingBranchesWereGone.ps1
Created August 15, 2019 02:16
Delete local branches whose remote tracking branches were gone.
git fetch origin -np
$BranchesToDelete = New-Object -TypeName System.Collections.Generic.List[string]
$BranchList = (git branch -vv)
foreach ($Branch in $BranchList) {
if ($Branch.ToString().Contains(": gone]")) {
$BranchesToDelete.Add($Branch.ToString().TrimStart().Split(' ')[0])
}
}
@RickyLin
RickyLin / StopAppPool.ps1
Created January 28, 2018 11:18
Powershell script to stop an IIS Application Pool
# usage: StopAppPool.ps1 -AppPoolName DefaultAppPool
# set-executionpolicy remotesigned
# Document of WebAdministration:
# https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2008-R2-and-2008/ee790599(v%3dtechnet.10)
# multiple parameters sample: param([string]$paramA,[string]$paramB)
param([string]$AppPoolName)
if ([string]::IsNullOrEmpty($AppPoolName))
{
@RickyLin
RickyLin / StartAppPool.ps1
Last active January 28, 2018 11:17
Powershell script to start an IIS Application Pool
# usage: StartAppPool.ps1 -AppPoolName DefaultAppPool
# set-executionpolicy remotesigned
# Document of WebAdministration:
# https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2008-R2-and-2008/ee790599(v%3dtechnet.10)
# multiple parameters sample: param([string]$paramA,[string]$paramB)
param([string]$AppPoolName)
if ([string]::IsNullOrEmpty($AppPoolName))
{
IF EXISTS ( SELECT 1 FROM sys.procedures WHERE name = 'spGenerateSqlStatement' )
DROP PROCEDURE spGenerateSqlStatement
GO
CREATE PROCEDURE spGenerateSqlStatement
@TableName VARCHAR(256)
AS
-- TEST: spGenerateSqlStatement 'Message'
DECLARE @SqlStmt VARCHAR(MAX)
DECLARE @Fields VARCHAR(MAX)
DECLARE @Params VARCHAR(MAX)
@RickyLin
RickyLin / SplitStringInSqlServer_XML_Approach
Last active August 29, 2015 14:19
Split string in Sql Server - XML approach
-- it comes from this great post: http://sqlperformance.com/2012/07/t-sql-queries/split-strings
-- this way turns out not to be very efficient
CREATE FUNCTION dbo.SplitStrings_XML
(
@List NVARCHAR(MAX),
@Delimiter NVARCHAR(255)
)
RETURNS TABLE
WITH SCHEMABINDING
AS
@RickyLin
RickyLin / StartAndStopIISAppPool
Created November 14, 2014 06:33
Start and Stop IIS App Pool by Cmd
REM stop the IIS App Pool
%windir%\system32\inetsrv\appcmd stop apppool /apppool.name:DefaultAppPool
REM start the IIS App Pool
%windir%\system32\inetsrv\appcmd start apppool /apppool.name:DefaultAppPool