Skip to content

Instantly share code, notes, and snippets.

@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
@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
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 / 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))
{
@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 / InvokeJavaScriptFunctionAfterEachUpdatePanelRequest
Created June 11, 2020 07:47
invoke javascript functions after each UpdatePanel request
$(function () {
var prm = Sys.WebForms.PageRequestManager.getInstance();
if (prm != null) {
prm.add_endRequest(function (sender, e) {
/*
if (sender._postBackSettings.panelsToUpdate != null) {
DisplayCurrentTime();
}
*/
// invoke whatever functions
@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 / CreatePrimaryKeyOnIdentityColumn.sql
Created September 15, 2020 07:31
Generate SQL scripts that create primary key for tables that have no primary key defined but have identity column
SELECT T.*, PK.COLUMN_NAME
INTO #Tables
FROM INFORMATION_SCHEMA.TABLES T
INNER JOIN (
SELECT TABLE_NAME, COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMNPROPERTY(OBJECT_ID(TABLE_NAME), COLUMN_NAME, 'IsIdentity') = 1
) PK ON PK.TABLE_NAME = T.TABLE_NAME
WHERE T.TABLE_TYPE = 'BASE TABLE'
AND T.TABLE_NAME NOT IN (
@RickyLin
RickyLin / CreatePrimaryKeyOnTableNameIdColumns.sql
Last active September 22, 2020 03:06
Create Primary Key on TableNameId Columns
SELECT T.TABLE_NAME, C.COLUMN_NAME, C.DATA_TYPE, C.IS_NULLABLE
INTO #Tables
FROM INFORMATION_SCHEMA.TABLES T
INNER JOIN (
SELECT TABLE_NAME, COLUMN_NAME, IS_NULLABLE, DATA_TYPE
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME = TABLE_NAME + 'Id'
) C ON C.TABLE_NAME = T.TABLE_NAME
WHERE T.TABLE_TYPE = 'BASE TABLE'
AND T.TABLE_NAME NOT IN (
@RickyLin
RickyLin / AspNetWebFormValidatorEnable.js
Created February 7, 2021 05:35
Enable/Disable asp.net web form validator control on client side.
var rfv = document.getElementById('validator_control_id');
ValidatorEnable(rfv, true);
ValidatorEnable(rfv, false);