Skip to content

Instantly share code, notes, and snippets.

View Incoming_Message_logger.cs
using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.Serialization.Json;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
using System.Text;
using System.Threading;
@vendettamit
vendettamit / UpdateBulk.cs
Created Dec 4, 2019
Update All fields of a document in MongoDB using BuildWrite
View UpdateBulk.cs
public async Task<long> UpdateBulk<T>(IMongoCollection<T> _collection, IEnumerable<T> items, FilterDefinition<T> filter, params string[] propertiesToSkip)
{
if (!items.Any())
{
return 0;
}
var updates = new List<WriteModel<T>>();
var filterBuilder = Builders<T>.Filter;
var updater = Builders<T>.Update;
@vendettamit
vendettamit / StringOrBindaryDataTruncated_Linqpad.cs
Created Dec 3, 2019
Utility method to detect long string and targeted column that's causing exception "String or binary data would be truncated"
View StringOrBindaryDataTruncated_Linqpad.cs
public static void FindLongStrings(object testObject)
{
foreach (FieldInfo propInfo in testObject.GetType().GetFields())
{
foreach (ColumnAttribute attribute in propInfo.GetCustomAttributes(typeof(ColumnAttribute), true))
{
if (attribute.DbType.ToLower().Contains("varchar"))
{
string dbType = attribute.DbType.ToLower();
int numberStartIndex = dbType.IndexOf("varchar(") + 8;
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
@vendettamit
vendettamit / tablemanipulator.js
Created Jul 29, 2013
Remove rowspan/colspan and split the cells with duplicate values
View tablemanipulator.js
var tempTable = $('#tbl').clone(true);
var tableBody = $(tempTable).children();
$(tableBody).children().each(function(index , item){
var currentRow = item;
$(currentRow).children().each(function(index1, item1){
if($(item1).attr("rowspan"))
{
// copy the cell
var item2 = $(item1).clone(true);
// Remove rowspan
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 / DynamicLinqCSharp.cs
Created Feb 19, 2016
A dynamic linq class library source code. Download the original content from here - http://www.scottgu.com/blogposts/dynquery/dynamiclinqcsharp.zip
View DynamicLinqCSharp.cs
//Copyright (C) Microsoft Corporation. All rights reserved.
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Reflection.Emit;
using System.Threading;
View InMemoryNunitTestRunner
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml;
using System.Xml.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
You can’t perform that action at this time.