Skip to content

Instantly share code, notes, and snippets.

@vendettamit
vendettamit / tablemanipulator.js
Created July 29, 2013 12:32
Remove rowspan/colspan and split the cells with duplicate values
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
@vendettamit
vendettamit / ReferenceFinder.cs
Created October 7, 2015 21:06
This is a sample code that can be used to find references using Roslyn version Microsoft.CodeAnalysis 1.0.0
class ReferenceFinder
{
public void Find(string methodName)
{
string solutionPath = @"C:\Users\achoudhary\Documents\Visual Studio 2013\Projects\ConsoleForEverything\ConsoleForEverything.sln";
var msWorkspace = MSBuildWorkspace.Create();
List<ReferencedSymbol> referencesToMethod = new List<ReferencedSymbol>();
Console.WriteLine("Searching for method \"{0}\" reference in solution {1} ", methodName, Path.GetFileName(solutionPath));
@vendettamit
vendettamit / DynamicOrderByHelper.cs
Created January 20, 2016 19:28
Helper class to pass dynamic orderby parameter in LINQ.
///<summary>
/// Usage -
/// if (QueryHelper.PropertyExists<Club>(orderBy))
/// {
/// query = query.OrderByProperty(orderBy);
/// - OR -
/// query = query.OrderByPropertyDescending(orderBy);
/// }
///</summary>
public static class QueryHelper
@vendettamit
vendettamit / DynamicLinqCSharp.cs
Created February 19, 2016 16:27
A dynamic linq class library source code. Download the original content from here - http://www.scottgu.com/blogposts/dynquery/dynamiclinqcsharp.zip
//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;
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Security;
namespace Shared.ApplicationLoaderUtil
{
/// <summary>
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 / PartialDownloadController.cs
Last active August 24, 2020 14:22
WebApi controller to handle the single partial request for content
using System;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Reflection;
using System.Web;
using System.Web.Http;
@vendettamit
vendettamit / UpdateBulk.cs
Created December 4, 2019 22:14
Update All fields of a document in MongoDB using BuildWrite
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 December 3, 2019 19:08
Utility method to detect long string and targeted column that's causing exception "String or binary data would be truncated"
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;
//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);