Skip to content

Instantly share code, notes, and snippets.

Amit Choudhary vendettamit

Block or report user

Report or block vendettamit

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View EscapeBatchFileChars.js
//Escape special characters in a string to use in batch file
var arg = "^hU$xgjX4ku*Hc0p%#F^UH";
arg.replace(/([\(\)%!\^<>|;, ])/g,'^$1').replace(/&/g, '&&');
console.log(arg);
@vendettamit
vendettamit / GetProcResultInTable.sql
Last active Jun 13, 2019
Get any procedure result in temp table without using OPENROWSET or OPENQUERY
View GetProcResultInTable.sql
create table #d
(is_hidden bit NULL, column_ordinal int NULL, name sysname NULL, is_nullable bit NULL, system_type_id int NULL, system_type_name nvarchar(256) NULL,
max_length smallint NULL, precision tinyint NULL, scale tinyint NULL, collation_name sysname NULL, user_type_id int NULL, user_type_database sysname NULL,
user_type_schema sysname NULL,user_type_name sysname NULL,assembly_qualified_type_name nvarchar(4000),xml_collection_id int NULL,xml_collection_database sysname NULL,
xml_collection_schema sysname NULL,xml_collection_name sysname NULL,is_xml_document bit NULL,is_case_sensitive bit NULL,is_fixed_length_clr_type bit NULL,
source_server sysname NULL,source_database sysname NULL,source_schema sysname NULL,source_table sysname NULL,source_column sysname NULL,is_identity_column bit NULL,
is_part_of_unique_key bit NULL,is_updateable bit NULL,is_computed_column bit NULL,is_sparse_column_set bit NULL,ordinal_in_order_by_list smallint NULL,
order_by_list_length smallint NULL,order_by_is_desce
@vendettamit
vendettamit / SqlfunctionSplitIndexed.Sql
Created Jan 3, 2019
Split string with Index number
View SqlfunctionSplitIndexed.Sql
CREATE FUNCTION [dbo].[fnSplitIndexed](
@sInputList VARCHAR(8000) -- List of delimited items
, @sDelimiter VARCHAR(8000) = ',' -- delimiter that separates items
) RETURNS @List TABLE (idx integer, item VARCHAR(8000))
BEGIN
DECLARE @sItem VARCHAR(8000)
Declare @idx integer = 0
WHILE CHARINDEX(@sDelimiter,@sInputList,0) <> 0
View GenericUnitOfWork_Sample.cs
public interface IUnitOfWork<TContext> where TContext: DbContext, new()
{
void Commit();
}
public interface IDbFactory<TContext> : IDisposable where TContext: DbContext, new()
{
TContext Init();
}
@vendettamit
vendettamit / min_max.cs
Created Aug 15, 2017
Get minimum or maximum of two number without using conditional statement. Max(a,b) MIN(a,b) implementation in CSharp/C#
View min_max.cs
int max(int a, int b)
{
/* max(a,b) = 1/2(a + b + |a-b|) */
Func<int, int> modValue = x => (int)Math.Sqrt(Math.Pow(x, 2));
return (int)Math.Ceiling((double)(a + b)/2 + ((double)modValue(a - b))/2);
}
int min(int a, int b)
{
@vendettamit
vendettamit / OnEventCustomTask.ps1
Created Jan 13, 2017
Powershell script to run when an event occurs in Windows event log
View OnEventCustomTask.ps1
# To test this script you can use Powershell to write your own test error log entry in the following way:
# -------------------------------------
# New-EventLog –LogName Application –Source "Test"
# Write-EventLog –LogName Application –Source "Test" –EntryType Error –EventID 1 –Message "This is a test message."
# Name to filter the event uses wild card pattern matching
$a = "*LocalReport*Application*"
#Write-EventLog –LogName Application -Source "Test" –EntryType Error –EventID 1046 –Message "This is a test message for $($a)."
@vendettamit
vendettamit / CreateEventTask.ps1
Last active Jan 13, 2017
Create Event based task to run a custom powershell script on Windows Event
View CreateEventTask.ps1
# Create a task to run powershell script on event
$cred = Get-Credential
$password = $cred.GetNetworkCredential().Password
$taskName = "EventMonitoringService"
$action = New-ScheduledTaskAction -Execute 'Powershell.exe' -Argument '-NoProfile -WindowStyle Hidden "C:\CourtAlert\Scripts\TakeAction.ps1""'
#Remove existing tasks
$taskExists = Get-ScheduledTask | Where-Object {$_.TaskName -like $taskName }
@vendettamit
vendettamit / CheckStatusOfWinServices.ps1
Created Jan 13, 2017
Check windows service status and email if stopped using power shell script
View CheckStatusOfWinServices.ps1
$client = "Test"
$service=""
$EmailBody = ""
$EmailSubject = ""
$SMTPServer = "relay2"
$PCName = $env:COMPUTERNAME
$EmailFrom = "$client <Test@cshandler.com>"
$EmailTo = "achoudhary@courtalert.com"
@vendettamit
vendettamit / InvokeRemoteProcess.cs
Created May 12, 2016
WMI Snippet to invoke a process on remote machine with privileges.
View InvokeRemoteProcess.cs
ConnectionOptions connection = new ConnectionOptions() {
EnablePrivileges = true
};
connection.Username = "achoudhary";
connection.Password = "ggn@1212";
connection.Authority = "ntlmdomain:health";
ManagementScope scope = new ManagementScope(
"\\\\7vmdev038\\root\\CIMV2", connection);
scope.Connect();
@vendettamit
vendettamit / MS-TestResult-XSL2.0.xsl
Created May 6, 2016
xml stylesheet to transform MS Coded UI test results to html with xslt 2.0
View MS-TestResult-XSL2.0.xsl
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xp="http://www.xmlprime.com/"
xmlns:ext="urn:extensions">
<xsl:output method="html" />
<xsl:param name="applicationPath" select="'.'" />
<xsl:template match="/">
<script language="javascript">
function toggle (name, spn)
You can’t perform that action at this time.